mirror of
https://github.com/launchbadge/sqlx
synced 2024-11-14 00:07:05 +00:00
[SQLite] encoding & decoding NaiveTime
with correct format (#1459)
* Fix SQLite encoding format * Update SQLite decoding format * Update sqlx-core/src/sqlite/types/chrono.rs * fixup: add `#[rustfmt::skip]` Co-authored-by: Austin Bonander <austin.bonander@gmail.com> Co-authored-by: Austin Bonander <austin@launchbadge.com>
This commit is contained in:
parent
51e45ce3ab
commit
8561891474
1 changed files with 4 additions and 2 deletions
|
@ -76,7 +76,7 @@ impl Encode<'_, Sqlite> for NaiveDate {
|
||||||
|
|
||||||
impl Encode<'_, Sqlite> for NaiveTime {
|
impl Encode<'_, Sqlite> for NaiveTime {
|
||||||
fn encode_by_ref(&self, buf: &mut Vec<SqliteArgumentValue<'_>>) -> IsNull {
|
fn encode_by_ref(&self, buf: &mut Vec<SqliteArgumentValue<'_>>) -> IsNull {
|
||||||
Encode::<Sqlite>::encode(self.format("%T%.f%").to_string(), buf)
|
Encode::<Sqlite>::encode(self.format("%T%.f").to_string(), buf)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -179,9 +179,11 @@ impl<'r> Decode<'r, Sqlite> for NaiveTime {
|
||||||
|
|
||||||
// Loop over common time patterns, inspired by Diesel
|
// Loop over common time patterns, inspired by Diesel
|
||||||
// https://github.com/diesel-rs/diesel/blob/93ab183bcb06c69c0aee4a7557b6798fd52dd0d8/diesel/src/sqlite/types/date_and_time/chrono.rs#L29-L47
|
// https://github.com/diesel-rs/diesel/blob/93ab183bcb06c69c0aee4a7557b6798fd52dd0d8/diesel/src/sqlite/types/date_and_time/chrono.rs#L29-L47
|
||||||
|
#[rustfmt::skip] // don't like how rustfmt mangles the comments
|
||||||
let sqlite_time_formats = &[
|
let sqlite_time_formats = &[
|
||||||
// Most likely format
|
// Most likely format
|
||||||
"%T.f", // Other formats in order of appearance in docs
|
"%T.f", "%T%.f",
|
||||||
|
// Other formats in order of appearance in docs
|
||||||
"%R", "%RZ", "%T%.fZ", "%R%:z", "%T%.f%:z",
|
"%R", "%RZ", "%T%.fZ", "%R%:z", "%T%.f%:z",
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue