-
-
Notifications
You must be signed in to change notification settings - Fork 535
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
SQlite INTEGER should map to i64 not i32 #1067
Comments
Ok, after some random testing I see that if the type is BIGINT but not (BIGINTEGER) on the sql statement then the generated type is i64. So, SQL -> Rust:
This is really surprising. Specially coming from sqlx that would handle INTEGER as i64. Also, why is BIGINT different from BIGINTEGER? |
Hey @data-retriever, welcome! Nice icon lolll Note that in SQLite it only has For CLI codegen, the mapping from SQLite datatype to Rust type is providing by SeaSchema at here |
@data-retriever About SQLite type affinity refer https://www.sqlite.org/datatype3.html#determination_of_column_affinity |
That's correct, SQLite did support up to i64. But I think for most use cases i32 is enough and considering i64 is much more costly than i32. So, I feel i32 is a good default. Demanding user can change the integer field to i64 easily. Input? @tyt2y3 |
Perhaps what's missing is some comment in the documentation. It's not clear at all that using BIGINT is the way to go. |
Short answer, yes, Circle back to the original question. According to https://www.sqlite.org/datatype3.html, |
Another inconsistency that I've run into is when
I'm using Sqlite for development of a project, and I've written a migration as such: manager
.create_table(
Table::create()
.table(Channel::Table)
...
.col(ColumnDef::new(Channel::DiscordId).big_integer().not_null())
...
.to_owned(),
)
.await?; In this case, running the migration against a Sqlite DB will change that pub struct Model {
...
pub discord_id: i32,
...
} As far as I know, there's no way for me to annotate somewhere that I want it to come out as an i64 (which makes sense, I don't know of anywhere that would make sense to go). Since I'm generating entities, it's not as easy as being the "demanding user" that will go through and switch things out all the time. For a sensible default, I feel it makes more sense to be an I'm going to try and PoC this, and see what behaviour comes up to make sure that assumption is correct. |
I threw together a repo that can be found here: https://github.com/AngelOnFira/sea-orm-sqlite-integer-issue Essentially, I generated entities from a Sqlite database with an INTEGER column that held a number larger than an tl;dr |
I agree 100%. The default behavior is very surprising for someone that was already working with sqlite databases before using seaorm. But also it seems there is another issue. It seems that on the DSL there is only |
Thank you everyone for bringing this up. I think we should map sea-query's This way, it will be picked up correctly by sea-schema thus completing the loop. But mapping |
This should fix SeaQL/sea-orm#1067 (comment)
From SQlite's documentation:
But
sea-orm-cli generate entity
generates a i32The text was updated successfully, but these errors were encountered: