Fix SQL timestamp scanning error on macOS (bd-161, GH-88)
Fixes timestamp scanning error reported in GH-88 where DATETIME columns were being returned as strings instead of time.Time on macOS 13.5. Root cause: modernc.org/sqlite driver doesn't recognize mattn-style DSN parameters (_journal_mode, _foreign_keys). When these incompatible parameters are present, the driver ignores _time_format=sqlite on some platforms, causing DATETIME values to remain as strings. Solution: Use modernc's native _pragma syntax for all database options: - Changed _journal_mode=WAL to _pragma=journal_mode(WAL) - Changed _foreign_keys=ON to _pragma=foreign_keys(ON) - Kept _pragma=busy_timeout(30000) and _time_format=sqlite This ensures all parameters are properly recognized and DATETIME columns are automatically parsed to time.Time across all platforms. Fixes #88 Amp-Thread-ID: https://ampcode.com/threads/T-44d1817a-3709-4f1d-a27a-78bb2fa4d3dc Co-authored-by: Amp <amp@ampcode.com>
This commit is contained in:
@@ -30,10 +30,12 @@ func New(path string) (*SQLiteStorage, error) {
|
||||
}
|
||||
|
||||
// Open database with WAL mode for better concurrency and busy timeout for parallel writes
|
||||
// Use modernc.org/sqlite's _pragma syntax for all options to ensure consistent behavior
|
||||
// _pragma=journal_mode(WAL) enables Write-Ahead Logging for better concurrency
|
||||
// _pragma=foreign_keys(ON) enforces foreign key constraints
|
||||
// _pragma=busy_timeout(30000) means wait up to 30 seconds for locks instead of failing immediately
|
||||
// Higher timeout helps with parallel issue creation from multiple processes
|
||||
// _time_format=sqlite uses SQLite's native time format for DATETIME columns
|
||||
db, err := sql.Open("sqlite", path+"?_journal_mode=WAL&_foreign_keys=ON&_pragma=busy_timeout(30000)&_time_format=sqlite")
|
||||
// _time_format=sqlite enables automatic parsing of DATETIME columns to time.Time
|
||||
db, err := sql.Open("sqlite", path+"?_pragma=journal_mode(WAL)&_pragma=foreign_keys(ON)&_pragma=busy_timeout(30000)&_time_format=sqlite")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to open database: %w", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user