-
-
Notifications
You must be signed in to change notification settings - Fork 16
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
Adds support for datetime string formats #42
Adds support for datetime string formats #42
Conversation
This correctly interprets dates generated the `date` and `datetime` sqlite functions, which includes the `CURRENT_DATE` and `CURRENT_TIMESTAMP` constants.
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## main #42 +/- ##
==========================================
+ Coverage 45.68% 48.03% +2.35%
==========================================
Files 7 7
Lines 510 535 +25
==========================================
+ Hits 233 257 +24
- Misses 277 278 +1
|
@@ -123,6 +123,12 @@ extension Date: SQLiteDataConvertible { | |||
value = v | |||
case .integer(let v): | |||
value = Double(v) | |||
case .text(let v): | |||
guard let d = dateTimeFormatter.date(from: v) ?? dateFormatter.date(from: v) else { |
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'm not a huge fan of the "try one and then the other" approach this requires, but I can't think of a good alternative either.
Looks like the CI failed on a ThreadSanitizer warning in INSERT INTO "people" ("first_name", "last_name", "id") VALUES (?1, ?2, ?3) ["Foo #600", "Bar", "EAD5F1B5-561F-475C-A3B8-9AC0BB270E6C"] I'm not sure how my changes would impact that - @gwynne do you have any insights? |
Nevermind, sorry - it looks like that issue is occurring in other PRs as well. |
Yeah, that's a known threading bug in SQLite itself, I've been going back and forth on whether to suppress it or patch SQLite to "fix" it |
Deliberately merging without a semver- label in order to release all three pending PRs together. |
Previously, dates were only interpreted from
Double
orInt
SQLite representations, which caused issues with decoding values ofCURRENT_DATE
andCURRENT_TIMESTAMP
, which output formatted strings. This PR adds support to interpret dates from strings, matching the formats output by thedate()
anddatetime()
SQLite functions, which includes theCURRENT_DATE
andCURRENT_TIMESTAMP
constants.