mirror of
https://github.com/mickael-kerjean/filestash.git
synced 2026-10-20 00:15:40 +00:00
32 lines
534 B
Go
32 lines
534 B
Go
//go:build cgo
|
|
|
|
package sqlite
|
|
|
|
import (
|
|
"errors"
|
|
|
|
"github.com/mattn/go-sqlite3"
|
|
)
|
|
|
|
func IsConstraint(err error) bool {
|
|
if err == nil {
|
|
return false
|
|
}
|
|
var sqliteErr sqlite3.Error
|
|
if !errors.As(err, &sqliteErr) {
|
|
return false
|
|
}
|
|
if sqliteErr.Code == sqlite3.ErrConstraint {
|
|
return true
|
|
}
|
|
switch sqliteErr.ExtendedCode {
|
|
case sqlite3.ErrConstraintPrimaryKey,
|
|
sqlite3.ErrConstraintUnique,
|
|
sqlite3.ErrConstraintForeignKey,
|
|
sqlite3.ErrConstraintCheck,
|
|
sqlite3.ErrConstraintNotNull:
|
|
return true
|
|
}
|
|
return false
|
|
}
|