Confusion converting DateTime<Utc> value to BigInteger for SQLite #2555
Unanswered
zebrapurring
asked this question in
Q&A
Replies: 1 comment
-
|
So this field: pub timestamp: DateTime<Utc>will still be handled by SeaORM as a datetime value, not as an integer timestamp. The simple option is to store it as #[sea_orm(primary_key, column_type = "BigInteger")]
pub timestamp: i64,and convert at the boundary: let dt = DateTime::<Utc>::from_timestamp_millis(model.timestamp)
.expect("valid timestamp millis");
let millis = dt.timestamp_millis();If you want your public/API type to use struct MyDomainModel {
timestamp: DateTime<Utc>,
}and convert between the SeaORM model and the domain model. So imo:
That keeps the SQLite storage exactly as |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi all, I'm trying to add column
timestampfor my SQLite entity where I would like:chrono::DateTime<chrono::Utc>BIGINTEGERcontaining the date time value in milliseconds (UNIX time)So far I tried the following:
However when I insert an entity I see the generated timestamp value is a string in format
YYYY-mm-dd HH:MM:SS +00:00. How can I map theDateTime<Utc>value to milliseconds asi64(and viceversa) when interfacing with the database?Beta Was this translation helpful? Give feedback.
All reactions