-
-
Notifications
You must be signed in to change notification settings - Fork 532
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
Support the use of chrono::DateTime<Utc> in sea-orm #429
Conversation
Add documentation for this Temporarily use a fork to include new Sea-query code
@billy1624 @tyt2y3 Thoughts on this also welcome |
We need some testing against all three databases |
@billy1624 Can you clarify this or give an example. Currently, the example I can reference is at |
#[cfg(feature = "with-chrono")] | ||
pub type DateTimeUtc = chrono::DateTime<chrono::Utc>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The example would be inserting and updating ActiveModel
with DateTimeUtc
attribute.
e.g.
#[derive(Clone, Debug, PartialEq, DeriveEntityModel)]
#[sea_orm(table_name = "applog")]
pub struct Model {
#[sea_orm(primary_key)]
pub id: i32,
pub action: String,
pub json: Json,
pub created_at: DateTimeWithTimeZone,
pub deleted_at: DateTimeUtc,
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@billy1624 Some help on understanding the results of github action failures. They seem to build fine and store the values in the databases, but retrieval is an issue.
For example, asserting on mysql
2022-01-07T14:12:10.675164Z INFO sqlx::query: /* SQLx ping */; rows: 0, elapsed: 5.909ms
Error: Query("error returned from database: column \"launch_date\" is of type timestamp with time zone but expression is of type text")
thread 'main' panicked at 'assertion failed: `(left == right)`
left: `1`,
right: `0`: the test returned a termination value with a non-zero status code (1) which indicates a failure', /rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c/library/test/src/lib.rs:195:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem you encountered is rooted in SeaQL/sea-query#222 (comment)
@tyt2y3 @billy1624 Anyone who has an idea on how to fix the errors from the CI running mysql 5.7 ?
This is an issue with older versions of mysql, in this case version 5.7. Solving the problem on my end involved changing myql 5.7 configuration as specified in this article https://ixnfo.com/en/the-solution-of-error-error-1067-42000-at-line-211-invalid-default-value-for-blablabla.html So what I am asking, is this a configuration issue, if not how do I solve the issue from sea-orm ? I am out of ideas |
In case you need more details, re-running the tasks can provide this or check my fork https://github.com/charleschege/sea-orm/runs/4748288791?check_suite_focus=true |
#[derive(Clone, Debug, PartialEq, DeriveEntityModel)] | ||
#[sea_orm(table_name = "satellites")] | ||
pub struct Model { | ||
#[sea_orm(primary_key)] | ||
pub id: i32, | ||
pub satellite_name: String, | ||
pub launch_date: DateTimeUtc, | ||
pub deployment_date: DateTimeUtc, | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @charleschege, you could set one of the timestamp column to nullable. This will solve the problem, let say changing the type of deployment_date
attribute to Option<DateTimeUtc>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @billy1624
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I am a little bit confused about some results, does using the derive macro yield different results than the Table::create
statement?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For example, on run https://github.com/charleschege/sea-orm/runs/4770827851?check_suite_focus=true
using https://github.com/SeaQL/sea-orm/pull/429/files/1227ad8252815c72b19c4a6aa27e998d3f1e5330#diff-db71d1612ed300a9a9a38e99d0096890446cc04f150507455638b35110d81bf0 results in that error
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But using the manual method
sea_query::Table::create()
.table(Entity)
.col(
ColumnDef::new(Column::Id)
.integer()
.not_null()
.auto_increment()
.primary_key(),
)
.col(ColumnDef::new(Column::SatelliteName).string().not_null())
.col(
ColumnDef::new(Column::LaunchDate)
.timestamp_with_time_zone()
.not_null(),
)
.col(
ColumnDef::new(Column::DeploymentDate)
.timestamp_with_time_zone()
.not_null(),
)
.if_not_exists()
.to_owned();
Assertion doesn't fail, @billy1624 is there a way to ensure fields are not null using the derive macro ? The module docs in https://docs.rs/sea-orm/latest/sea_orm/ dont show how to do this if possible
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If launch_date
is nullable then the table create statement will be like...
.col(
ColumnDef::new(Column:: LaunchDate)
.timestamp_with_time_zone(),
)
What we are missing is a default expression like |
Support sea-orm derive macros for using Sea-Query
DateTimeUtc
.An update to sea-query dependency from depending on the fork will be made once sea-query PR supporting
DateTimeUtc
is approved