docs: add a TODO; also add IsSqlitePrimaryKeyError and change ForeignKey interface to '~int'
All checks were successful
CI / build-docker (push) Successful in 7s
CI / build-docker-bootstrap (push) Has been skipped
CI / release-test (push) Successful in 31s

This commit is contained in:
wispem-wantex 2026-01-10 17:19:14 -08:00
parent 2d29ce92ec
commit dc33bd84ff
2 changed files with 16 additions and 1 deletions

View File

@ -8,3 +8,6 @@ TODO: auto-timestamps
TODO: modified-timestamps TODO: modified-timestamps
- set updated_at and created_at in SaveXYZ - set updated_at and created_at in SaveXYZ
- soft delete option - soft delete option
TODO: generator-foreign-keys
- add auto-foreign-key checking blocks to SaveXyz

View File

@ -15,7 +15,7 @@ var (
) )
type ForeignKey interface { type ForeignKey interface {
~uint64 | ~string ~int
} }
type ForeignKeyError[T ForeignKey] struct { type ForeignKeyError[T ForeignKey] struct {
@ -65,6 +65,18 @@ func IsSqliteUniqError(err error) bool {
return errors.Is(sqliteErr.ExtendedCode, sqlite3.ErrConstraintUnique) return errors.Is(sqliteErr.ExtendedCode, sqlite3.ErrConstraintUnique)
} }
// IsSqlitePrimaryKeyError checks whether an error is a SQLite `primary key` constraint violation.
//
// TODO: it's kind of annoying that SQLite returns this instead of whether the violation was
// . uniqueness or null-ness.
func IsSqlitePrimaryKeyError(err error) bool {
var sqliteErr sqlite3.Error
if !errors.As(err, &sqliteErr) {
return false
}
return errors.Is(sqliteErr.ExtendedCode, sqlite3.ErrConstraintPrimaryKey)
}
// IsSqliteNotNullError checks whether an error is a SQLite not null constraint violation. // IsSqliteNotNullError checks whether an error is a SQLite not null constraint violation.
func IsSqliteNotNullError(err error) bool { func IsSqliteNotNullError(err error) bool {
var sqliteErr sqlite3.Error var sqliteErr sqlite3.Error