ufoss-org / kotysa

The idiomatic way to write type-safe SQL in Kotlin
The Unlicense
117 stars 1 forks source link

autoIncrement with not nullable mapped column #136

Closed joseluisgs closed 7 months ago

joseluisgs commented 1 year ago

One of the best things about using Kotlin is being able to work with nulls safely.

I wanted to know, if I can work with autoIncrement directly in my model without the need to make id nullable.

Other frameworks use for example -1 or 0.

I think it's better to avoid comparison problems later or use !!.

Currently I solve it using a another bridge class, but I find it unnecessary if a non-null default value can be used.

Is there another possibility?

pull-vert commented 1 year ago

Hello @joseluisgs Thanks for submitting this proposal, I understand your point of view. For me a nullable id for an autoincrement column is the natural way to go : it's null unless you affect a value yourself or it's returned from a insertAndReturn call, this null value has a clear meaning that your entity was not inserted yet.

But nothing prevent me to allow autoIncrement for non nullable columns too, I would have to ignore the column value if it is <= 0 to let the database generate a value in this case. I add it to the roadmap !

pull-vert commented 7 months ago

Hi @joseluisgs This feature is included in the latest 3.2.2 version that was released yesterday

joseluisgs commented 7 months ago

@pull-vert Thank you very much! You are the best!