Skip to content
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

Handling MySQL & SQLite timestamp columns #345

Closed
wants to merge 1 commit into from
Closed

Conversation

billy1624
Copy link
Member

@billy1624 billy1624 commented Dec 1, 2021

PR Info

Notes to MySQL User

MySQL user should use sea_orm:: DateTimeWithTimeZone for timestamp columns until SQLx upstream merged the PR and released it. Only after that happened, MySQL user could use sea_orm::DateTime for timestamp columns.

@billy1624
Copy link
Member Author

Hey @lz1998, could you please try this PR?

sea-orm = { version = "0.4.0", git = "https://github.com/SeaQL/sea-orm.git", branch = "issues/344", ... }

@lz1998
Copy link
Contributor

lz1998 commented Dec 1, 2021

Hey @lz1998, could you please try this PR?

sea-orm = { version = "0.4.0", git = "https://github.com/SeaQL/sea-orm.git", branch = "issues/344", ... }

I have tried chrono::DateTime<chrono::Utc> and chrono::DateTime<chrono::FixedOffset>, but both failed.

@billy1624
Copy link
Member Author

Is your entity file similar to below? Defining the timestamp column with type DateTimeWithTimeZone.

use sea_orm::entity::prelude::*;

#[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,
}

#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {}

impl ActiveModelBehavior for ActiveModel {}

@billy1624 billy1624 self-assigned this Dec 1, 2021
src/executor/query.rs Outdated Show resolved Hide resolved
src/executor/query.rs Outdated Show resolved Hide resolved
@billy1624 billy1624 marked this pull request as ready for review December 7, 2021 15:22
@billy1624 billy1624 requested a review from tyt2y3 December 7, 2021 15:22
@tyt2y3
Copy link
Member

tyt2y3 commented Dec 9, 2021

I don't think MySQL can work with DateTimeWithTimeZone, there isn't a corresponding concept in MySQL.
The best bet is plain DateTime.

@billy1624
Copy link
Member Author

billy1624 commented Dec 9, 2021

I don't think MySQL can work with DateTimeWithTimeZone, there isn't a corresponding concept in MySQL. The best bet is plain DateTime.

We cannot decode timestamp column into chrono::NaiveDateTime (for MySQL).

Could we just introduce two more DateTime (timestamp)?

  • chrono::DateTime<chrono::Utc> named DateTimeUtc
  • chrono::DateTime<chrono::Local> named DateTimeLocal

(Continue our discussion on #344)

@tyt2y3
Copy link
Member

tyt2y3 commented Dec 9, 2021

So this PR is not needed now?

@billy1624
Copy link
Member Author

So this PR is not needed now?

You mean we have to wait for upstream release? So we have to defer this PR?

@billy1624
Copy link
Member Author

So this PR is not needed now?

I think we should split this PR in half. And release the hotfix part now. MySQL user should use sea_orm:: DateTimeWithTimeZone for timestamp columns until SQLx upstream merged the PR and released it.

Only after that happened, MySQL user could use sea_orm::DateTime for timestamp columns.

@tyt2y3
Copy link
Member

tyt2y3 commented Mar 6, 2022

Close as the SQLx PR is closed

@tyt2y3 tyt2y3 closed this Mar 6, 2022
@tyt2y3 tyt2y3 deleted the issues/344 branch July 7, 2023 14:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

How to define rust type of TIMESTAMP?
3 participants