Open RipleyTom opened 2 years ago
Hey @RipleyTom, thanks for the questions! From what I understand SQLite does not support unsigned integer. It will be treated as a normal integer column in SQLite. https://www.sqlite.org/datatype3.html#affinity_name_examples
I'm aware of this, every integer type in sqlite is really an INTEGER behind the hood(note that it's still a valid type in sqlite) but that still doesn't explained how a UNSIGNED SMALLINT(ie an INTEGER really) ended up as Vec\<u8> in codegen(at worst it should be an i32).
It end up being Vec<u8>
because UNSIGNED SMALLINT
isn't included in the list:
Hmm I'm even more confused now, why is there an UnsignedBigInt, Int2, Int8, etc types in there? Those are not sqlite types since there is only INTEGER.
Hmm I'm even more confused now, why is there an UnsignedBigInt, Int2, Int8, etc types in there? Those are not sqlite types since there is only INTEGER.
All these types are on the list because they are mentioned on the page https://www.sqlite.org/datatype3.html#affinity_name_examples.
I don't think there is a good way to parse arbitrary types, e.g. UNSIGNED SMALLINT
, in SQLite. I would suggest you to define it as INTEGER
datatype
Yeah but like the table says, those are examples: This table shows only a small subset of the datatype names that SQLite will accept.
.
The actual types are, anything with INT in it => INTEGER(which in sqlite type is a variable integer type from 0 to 8 bytes).
https://www.sqlite.org/datatype3.html#storage_classes_and_datatypes actually describes the only 5 actual types sqlite handles internally.
The way it is done atm seems very inconsistent to me.
Okay, I agree we can update the logic and search if INT
exists in the datatype string: it's INTEGER
column if we found INT
in it.
Summary: right now the database to type mapping is word-by-word. Ideally we should follow SQLite's rules in resolving types. This is a big task, because the implementation should have plenty of test cases verified against SQLite. Contribution is welcomed.
I'm currently in the process of migrating a program from sqlite to sea-orm and used sea-orm-codegen to generate the entities from the existing database.
It seems it converted an
UNSIGNED SMALLINT NOT NULL
to aVec<u8>
The database table used to be created like this:
resulting users.rs:
I'd expect
pub flags: u16