Skip to content

Commit 4893f83

Browse files
authored
fix(sqlite): migrate datetime format builders off time 0.3.48-depreca… (#4317)
* fix(sqlite): migrate datetime format builders off time 0.3.48-deprecated API * ci: re-trigger checks
1 parent 3da582a commit 4893f83

8 files changed

Lines changed: 19 additions & 136 deletions

File tree

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ ipnet = "2.3.0"
186186
ipnetwork = "0.21.1"
187187
mac_address = "1.1.5"
188188
rust_decimal = { version = "1.36.0", default-features = false, features = ["std"] }
189-
time = { version = "0.3.47", features = ["formatting", "parsing", "macros"] }
189+
time = { version = "0.3.48", features = ["formatting", "parsing", "macros"] }
190190
uuid = "1.12.1"
191191

192192
# Common utility crates

examples/postgres/axum-social-with-tests/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ rand = "0.10.1"
1717
regex = "1.6.0"
1818
serde = "1.0.219"
1919
serde_with = { version = "3.18.0", features = ["time_0_3"] }
20-
time = "0.3.47"
20+
time = "0.3.48"
2121
uuid = { version = "1.12.1", features = ["serde"] }
2222
validator = { version = "0.20.0", features = ["derive"] }
2323

examples/postgres/multi-database/accounts/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ uuid = { version = "1.12.1", features = ["serde"] }
1515
thiserror = "2.0.18"
1616
rand = "0.10.1"
1717

18-
time = { version = "0.3.47", features = ["serde"] }
18+
time = { version = "0.3.48", features = ["serde"] }
1919

2020
serde = { version = "1.0.219", features = ["derive"] }
2121

examples/postgres/multi-database/payments/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ sqlx = { workspace = true, features = ["postgres", "time", "uuid", "rust_decimal
99

1010
rust_decimal = "1.36.0"
1111

12-
time = "0.3.47"
12+
time = "0.3.48"
1313
uuid = "1.12.1"
1414

1515
[dependencies.accounts]

examples/postgres/multi-tenant/accounts/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ uuid = { version = "1.12.1", features = ["serde"] }
1414
thiserror = "2.0.18"
1515
rand = "0.10.1"
1616

17-
time = { version = "0.3.47", features = ["serde"] }
17+
time = { version = "0.3.48", features = ["serde"] }
1818

1919
serde = { version = "1.0.219", features = ["derive"] }
2020

examples/postgres/multi-tenant/payments/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ edition = "2021"
77

88
rust_decimal = "1.36.0"
99

10-
time = "0.3.47"
10+
time = "0.3.48"
1111
uuid = "1.12.1"
1212

1313
[dependencies.sqlx]

examples/postgres/preferred-crates/uses-time/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ authors.workspace = true
1010

1111
[dependencies]
1212
serde = "1.0.219"
13-
time = "0.3.47"
13+
time = "0.3.48"
1414
uuid = "1.12.1"
1515

1616
[dependencies.sqlx]

sqlx-sqlite/src/types/time.rs

Lines changed: 12 additions & 129 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,12 @@ fn decode_offset_datetime_from_text(value: &str) -> Option<OffsetDateTime> {
145145
return Some(dt);
146146
}
147147

148-
if let Ok(dt) = OffsetDateTime::parse(value, formats::OFFSET_DATE_TIME) {
148+
if let Ok(dt) = OffsetDateTime::parse(
149+
value,
150+
&fd!(
151+
"[year]-[month]-[day][optional [ ]][optional [T]][hour]:[minute][optional [:[second]]][optional [.[subsecond]]][optional [[offset_hour]]][optional [:[offset_minute]]]"
152+
),
153+
) {
149154
return Some(dt);
150155
}
151156

@@ -181,8 +186,12 @@ fn decode_datetime_from_text(value: &str) -> Option<PrimitiveDateTime> {
181186
}
182187

183188
let formats = [
184-
BorrowedFormatItem::Compound(formats::PRIMITIVE_DATE_TIME_SPACE_SEPARATED),
185-
BorrowedFormatItem::Compound(formats::PRIMITIVE_DATE_TIME_T_SEPARATED),
189+
BorrowedFormatItem::Compound(fd!(
190+
"[year]-[month]-[day] [hour]:[minute][optional [:[second]]][optional [.[subsecond]]][optional [Z]]"
191+
)),
192+
BorrowedFormatItem::Compound(fd!(
193+
"[year]-[month]-[day]T[hour]:[minute][optional [:[second]]][optional [.[subsecond]]][optional [Z]]"
194+
)),
186195
];
187196

188197
if let Ok(dt) = PrimitiveDateTime::parse(value, &BorrowedFormatItem::First(&formats)) {
@@ -191,129 +200,3 @@ fn decode_datetime_from_text(value: &str) -> Option<PrimitiveDateTime> {
191200

192201
None
193202
}
194-
195-
mod formats {
196-
use time::format_description::BorrowedFormatItem::{Component, Literal, Optional};
197-
use time::format_description::{modifier, BorrowedFormatItem, Component::*};
198-
199-
const YEAR: BorrowedFormatItem<'_> = Component(Year({
200-
let mut value = modifier::Year::default();
201-
value.padding = modifier::Padding::Zero;
202-
value.repr = modifier::YearRepr::Full;
203-
value.iso_week_based = false;
204-
value.sign_is_mandatory = false;
205-
value
206-
}));
207-
208-
const MONTH: BorrowedFormatItem<'_> = Component(Month({
209-
let mut value = modifier::Month::default();
210-
value.padding = modifier::Padding::Zero;
211-
value.repr = modifier::MonthRepr::Numerical;
212-
value.case_sensitive = true;
213-
value
214-
}));
215-
216-
const DAY: BorrowedFormatItem<'_> = Component(Day({
217-
let mut value = modifier::Day::default();
218-
value.padding = modifier::Padding::Zero;
219-
value
220-
}));
221-
222-
const HOUR: BorrowedFormatItem<'_> = Component(Hour({
223-
let mut value = modifier::Hour::default();
224-
value.padding = modifier::Padding::Zero;
225-
value.is_12_hour_clock = false;
226-
value
227-
}));
228-
229-
const MINUTE: BorrowedFormatItem<'_> = Component(Minute({
230-
let mut value = modifier::Minute::default();
231-
value.padding = modifier::Padding::Zero;
232-
value
233-
}));
234-
235-
const SECOND: BorrowedFormatItem<'_> = Component(Second({
236-
let mut value = modifier::Second::default();
237-
value.padding = modifier::Padding::Zero;
238-
value
239-
}));
240-
241-
const SUBSECOND: BorrowedFormatItem<'_> = Component(Subsecond({
242-
let mut value = modifier::Subsecond::default();
243-
value.digits = modifier::SubsecondDigits::OneOrMore;
244-
value
245-
}));
246-
247-
const OFFSET_HOUR: BorrowedFormatItem<'_> = Component(OffsetHour({
248-
let mut value = modifier::OffsetHour::default();
249-
value.sign_is_mandatory = true;
250-
value.padding = modifier::Padding::Zero;
251-
value
252-
}));
253-
254-
const OFFSET_MINUTE: BorrowedFormatItem<'_> = Component(OffsetMinute({
255-
let mut value = modifier::OffsetMinute::default();
256-
value.padding = modifier::Padding::Zero;
257-
value
258-
}));
259-
260-
pub(super) const OFFSET_DATE_TIME: &[BorrowedFormatItem<'_>] = {
261-
&[
262-
YEAR,
263-
Literal(b"-"),
264-
MONTH,
265-
Literal(b"-"),
266-
DAY,
267-
Optional(&Literal(b" ")),
268-
Optional(&Literal(b"T")),
269-
HOUR,
270-
Literal(b":"),
271-
MINUTE,
272-
Optional(&Literal(b":")),
273-
Optional(&SECOND),
274-
Optional(&Literal(b".")),
275-
Optional(&SUBSECOND),
276-
Optional(&OFFSET_HOUR),
277-
Optional(&Literal(b":")),
278-
Optional(&OFFSET_MINUTE),
279-
]
280-
};
281-
282-
pub(super) const PRIMITIVE_DATE_TIME_SPACE_SEPARATED: &[BorrowedFormatItem<'_>] = {
283-
&[
284-
YEAR,
285-
Literal(b"-"),
286-
MONTH,
287-
Literal(b"-"),
288-
DAY,
289-
Literal(b" "),
290-
HOUR,
291-
Literal(b":"),
292-
MINUTE,
293-
Optional(&Literal(b":")),
294-
Optional(&SECOND),
295-
Optional(&Literal(b".")),
296-
Optional(&SUBSECOND),
297-
Optional(&Literal(b"Z")),
298-
]
299-
};
300-
301-
pub(super) const PRIMITIVE_DATE_TIME_T_SEPARATED: &[BorrowedFormatItem<'_>] = {
302-
&[
303-
YEAR,
304-
Literal(b"-"),
305-
MONTH,
306-
Literal(b"-"),
307-
DAY,
308-
Literal(b"T"),
309-
HOUR,
310-
Literal(b":"),
311-
MINUTE,
312-
Optional(&Literal(b":")),
313-
Optional(&SECOND),
314-
Optional(&Literal(b".")),
315-
Optional(&SUBSECOND),
316-
Optional(&Literal(b"Z")),
317-
]
318-
};
319-
}

0 commit comments

Comments
 (0)