Chore: Make cgo optional (for sqlite) (#108756)
* make cgo optional for sqlite * update go.mod; check error code differently * reduce api surface even more * move test errors into sqlite package * add a comment
This commit is contained in:
@@ -1,12 +1,10 @@
|
||||
package migrator
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/mattn/go-sqlite3"
|
||||
|
||||
"github.com/grafana/grafana/pkg/util/sqlite"
|
||||
"github.com/grafana/grafana/pkg/util/xorm"
|
||||
)
|
||||
|
||||
@@ -139,27 +137,12 @@ func (db *SQLite3) TruncateDBTables(engine *xorm.Engine) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (db *SQLite3) isThisError(err error, errcode int) bool {
|
||||
var driverErr sqlite3.Error
|
||||
if errors.As(err, &driverErr) {
|
||||
if int(driverErr.ExtendedCode) == errcode {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
func (db *SQLite3) ErrorMessage(err error) string {
|
||||
var driverErr sqlite3.Error
|
||||
if errors.As(err, &driverErr) {
|
||||
return driverErr.Error()
|
||||
}
|
||||
return ""
|
||||
return sqlite.ErrorMessage(err)
|
||||
}
|
||||
|
||||
func (db *SQLite3) IsUniqueConstraintViolation(err error) bool {
|
||||
return db.isThisError(err, int(sqlite3.ErrConstraintUnique)) || db.isThisError(err, int(sqlite3.ErrConstraintPrimaryKey))
|
||||
return sqlite.IsUniqueConstraintViolation(err)
|
||||
}
|
||||
|
||||
func (db *SQLite3) IsDeadlock(err error) bool {
|
||||
|
||||
Reference in New Issue
Block a user