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

Allow sqlite DATETIME to be mapped with time::DateTime<Utc> #2288

Open
nstinus opened this issue Jan 10, 2023 · 4 comments
Open

Allow sqlite DATETIME to be mapped with time::DateTime<Utc> #2288

nstinus opened this issue Jan 10, 2023 · 4 comments
Labels
enhancement New feature or request

Comments

@nstinus
Copy link
Contributor

nstinus commented Jan 10, 2023

Context

I have a column with a DATETIME type and a default value of CURRENT_TIMESTAMP. As discussed on different issues already 1617 and 598, CURRENT_TIMESTAMP does not hold the timezone although it is how the date is taken.

As such, a time::PrimitiveDateTime can be built but not a time::DateTime.

Possible solution

Allow fields of type time::DateTime to be maped to DATETIME columns by assuming the UTC tz if everything else fails.

@nstinus
Copy link
Contributor Author

nstinus commented Feb 15, 2023

@abonander any thoughts? I am happy to amend this as required.

@tgecho
Copy link

tgecho commented Apr 30, 2023

Is there any appetite for the non-standard DATETIME UTC thing @mehcode mentioned here? #598 (comment)

I did a rough first implementation: tgecho@2ed96e2

I don't love this overall (I'd rather it was just the default, since I have no interest in storing anything but UTC timestamps), but it's at least better than manually annotating every single query that touches a timestamp. The annotation is especially annoying when trying to do a SELECT * FROM that should just go right into a matching struct.

@d4h0
Copy link

d4h0 commented May 13, 2023

I'd love support for DATETIME UTC, or defaulting to UTC.

What would be a disadvantage of defaulting to UTC? I'm assuming that UTC is by far the most used TZ for storing date/time data in SQLite, so why shouldn't this be the default?

This would be a breaking change, however it seems sqlx 7.0 will be released soon. So now would probably be a good time to switch to UTC by default.

@MrFoxPro
Copy link

@d4h0 could you please elaborate how does non-standard type DATETIME UTCsuppose to be used?
When I'm setting paid_until datetime utc not null default (datetime('now')) I'm getting

Error: create table "users": sqlite: unsupported type: "datetime utc"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants