Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to deal with the null insert/update? #7

Open
geohuz opened this issue Aug 20, 2021 · 3 comments
Open

How to deal with the null insert/update? #7

geohuz opened this issue Aug 20, 2021 · 3 comments
Labels
API Design help wanted Extra attention is needed

Comments

@geohuz
Copy link

geohuz commented Aug 20, 2021

For the following statement using db_postgres:

db.exec(sql"insert into data (name) values (?)", name)

the name can be null or some(value), is there any facility around this optional concept so we can deal with some(value) or none in both case without overhead of writing different sql string?

@juancarlospaco juancarlospaco added help wanted Extra attention is needed API Design labels Aug 23, 2021
@juancarlospaco
Copy link
Owner

I just use NOT NULL then forget about the possibility of it being null.

I know that null can give a tiny performance improvement, but it does not worth the risks,
like theres a lot of other things that can be improved for performance in your project than using nulls everywhere,
makes me remember of then string and seq was null on Nim, but is not null anymore and people use them just fine.

At the time of writing it, Nim's opinion was to not use nulls in database stuff anyway.

If theres interests for possibly null values and fields, then it can be added,
I dont know how the design would be, or how the implementation would be, but Pull Requests welcome.

@geohuz
Copy link
Author

geohuz commented Aug 28, 2021

Does that mean we should design a db field as "not null"? what if the target db is a third party realm and we can't touch?

@juancarlospaco
Copy link
Owner

I understand, but kinda the same happens with other ORM,
like if you have a DB built on manual raw SQL and plug a Django in it,
youll see Django using random names for stuff, not understanding prepared SQL, using too big data types, etc.

But this is something that can be improved in this project. 🙂:+1:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Design help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants