mirror of
https://github.com/hanzoai/tasks.git
synced 2026-10-04 02:04:03 +00:00
## What changed? Bumped `modernc.org/sqlite` to v1.51.0 and removed the custom `Driver`/`conn` wrapper in `sqlite/driver.go` that implemented `ResetSession()` and `IsValid()`. ## Why? The wrapper existed to stop `database/sql` from discarding the single in-memory connection on a context-cancelled transaction (which lost the whole database). v1.51.0 fixes this upstream — in-memory connections now stay usable after interruption ([cznic/sqlite c1d418e](https://gitlab.com/cznic/sqlite/-/commit/c1d418e0de38d2757c5d0faa6ab569fdf6acdf03)) — so the workaround is redundant. ## How did you test it? - [x] built - [x] covered by existing tests `TestSQLiteTransactionContextCancellation` (the in-memory cancellation regression test) and the rest of the SQLite persistence suite pass.
36 lines
764 B
Go
36 lines
764 B
Go
package sqlite
|
|
|
|
import (
|
|
"errors"
|
|
"regexp"
|
|
|
|
"modernc.org/sqlite"
|
|
sqlite3 "modernc.org/sqlite/lib"
|
|
)
|
|
|
|
const (
|
|
goSQLDriverName = "sqlite"
|
|
sqlConstraintCodes = sqlite3.SQLITE_CONSTRAINT | sqlite3.SQLITE_CONSTRAINT_PRIMARYKEY | sqlite3.SQLITE_CONSTRAINT_UNIQUE
|
|
sqlTableExistsPattern = "SQL logic error: table .* already exists \\(1\\)"
|
|
)
|
|
|
|
var sqlTableExistsRegex = regexp.MustCompile(sqlTableExistsPattern)
|
|
|
|
func (*db) IsDupEntryError(err error) bool {
|
|
var sqlErr *sqlite.Error
|
|
if errors.As(err, &sqlErr) {
|
|
return sqlErr.Code()&sqlConstraintCodes != 0
|
|
}
|
|
|
|
return false
|
|
}
|
|
|
|
func isTableExistsError(err error) bool {
|
|
var sqlErr *sqlite.Error
|
|
if errors.As(err, &sqlErr) {
|
|
return sqlTableExistsRegex.MatchString(sqlErr.Error())
|
|
}
|
|
|
|
return false
|
|
}
|