docs: add a TODO; also add IsSqlitePrimaryKeyError and change ForeignKey interface to '~int'
This commit is contained in:
@@ -15,7 +15,7 @@ var (
|
||||
)
|
||||
|
||||
type ForeignKey interface {
|
||||
~uint64 | ~string
|
||||
~int
|
||||
}
|
||||
|
||||
type ForeignKeyError[T ForeignKey] struct {
|
||||
@@ -65,6 +65,18 @@ func IsSqliteUniqError(err error) bool {
|
||||
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.
|
||||
func IsSqliteNotNullError(err error) bool {
|
||||
var sqliteErr sqlite3.Error
|
||||
|
||||
Reference in New Issue
Block a user