docs: add a TODO; also add IsSqlitePrimaryKeyError and change ForeignKey interface to '~int'
This commit is contained in:
parent
2d29ce92ec
commit
dc33bd84ff
@ -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
|
||||||
|
|||||||
@ -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
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user