-
-
Notifications
You must be signed in to change notification settings - Fork 500
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
Uuid/Datetime/etc. types (instead of String) for generated models with sqlite databases #924
Comments
Hey @Dash-L, thanks for filing this report! As discussed on Discord. Maybe we can add a special comment to indicate it's a uuid / date time column when creating the table.
|
Thoughts? @tyt2y3 @ikrivosheev |
Hello! I think this is similar to: SeaQL/sea-query#375 |
But as listed on the table |
I mean we can rename |
That's hacky lol |
That`s feature!)) |
This is larger than just sqlite. I'm running into this with Uuid and bool on mysql. |
Hey @wysenynja, thanks for the report! Currently, the ColumnType::Boolean => "bool".into(),
ColumnType::Uuid => "binary(16)".into(), I'm not sure why |
I think we can start with the following SQLite ColumnType::DateTime => "BlobDateTime"
ColumnType::Timestamp => "BlobTimestamp"
ColumnType::TimestampWithTimeZone => "BlobTimestampWithTimeZone"
ColumnType::Time => "BlobTime"
ColumnType::Date => "BlobDate"
ColumnType::Json => "BlobJson"
ColumnType::JsonBinary => "BlobJsonBinary"
ColumnType::Uuid => "BlobUuid" CC @ikrivosheev |
I believe SeaORM should probably use numeric values to represent timestamps with sqlite - that way, we can sort and filter with them as we can with timestamps in MySQL/PostgreSQL, like here: let mut message_pages = MessageEntity::find()
.filter(MessageColumn::Timestamp.between(start_of_day, end_of_day))
.order_by_asc(MessageColumn::Timestamp)
.paginate(db, MAX_MESSAGES_PER_PAGE); (unless sqlite has magic for handling sorting/filtering text timestamps?) |
Hey @Absolucy, I think SQLite did have some magic for comparing datetime like string. create table tbl (
id INTEGER PRIMARY KEY AUTOINCREMENT,
created TEXT
);
insert into tbl (created) values
('2022-09-12 12:37:00'),
('2022-09-10 12:37:12'),
('2022-09-09 12:32:01'),
('2022-09-08 12:37:02'),
('2022-09-09 12:32:00');
select * from tbl where created between '2022-09-09 12:00:00' and '2022-09-09 16:00:00' order by created asc; Output: Tested on https://sqliteonline.com/ |
Has anyone experience how other ORMs (maybe from other programming languages) deal with this issue? I would assume they derive the Entities from the Schema definition directly. Is the reason to derive it from the actual database tables in Sea-Orm so that you can quickly query existing databases? |
Update (not really since I never submitted the original but oh well)
This was originally a bug report, but now it is really a feature request, but I'm keeping the bug report template because I already wrote it out and I suspect others might come here thinking this is a bug.
After writing out this issue, I asked on the discord just in case, and found out that there has been some discussion of this in the past, not just for uuids but for datetime and other types as well, because sqlite doesn't support those types and they will be
TEXT
in the database anyway, but I still think it would be nice for type-safety to have the models be the correct types in rust anyway (though from my brief skimming of the discussion on discord, it seems like there are some drawbacks to this, at least in development of the ORM?). I'd like to continue the discussion of this here, or if it has already been started somewhere else if someone could point me to it that would be great.Original discussion on discord for anyone interested: https://discord.com/channels/873880840487206962/900758376164757555/997017818933497967
Also I'm not really sure what to title this issue, so the title right now is kind of confusing, sorry!
Original Issue:
Description
I want to use uuids for my ids in my models, so in the migration I have
but when I generate with
sea-orm-cli generate entity
, the generated model looks likewhich I suppose technically works because I can turn
Uuid
s intoString
s, but that's not particularly type-safe.Also I can just change the type of the
id
field manually, and it all seems to work, so my guess is this is not intended behavior/I am missing something, or if it is intended behavior it should probably be changed.Steps to Reproduce
.uuid()
in a migrationsea-orm-cli generate entity
String
, notUuid
Expected Behavior
The field is type
Uuid
Actual Behavior
The field is type
String
Reproduces How Often
Every time
Versions
OS: Void Linux
Database: sqlite3
Additional Information
The text was updated successfully, but these errors were encountered: