mirror of
https://github.com/glebarez/sqlite.git
synced 2025-10-05 07:36:58 +08:00

* feat: error translator support added * refactor: removed redundent error deserialization --------- Co-authored-by: Saeid Saeidee <s.saeidee@sensysgatso.com>
22 lines
375 B
Go
22 lines
375 B
Go
package sqlite
|
|
|
|
import (
|
|
"github.com/mattn/go-sqlite3"
|
|
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
var errCodes = map[string]sqlite3.ErrNoExtended{
|
|
"uniqueConstraint": 2067,
|
|
}
|
|
|
|
func (dialector Dialector) Translate(err error) error {
|
|
if sqliteErr, ok := err.(*sqlite3.Error); ok {
|
|
if sqliteErr.ExtendedCode == errCodes["uniqueConstraint"] {
|
|
return gorm.ErrDuplicatedKey
|
|
}
|
|
}
|
|
|
|
return err
|
|
}
|