feat(auth): Add login, register, session_info and api creation
This commit is contained in:
25
app/utils/sql.go
Normal file
25
app/utils/sql.go
Normal file
@@ -0,0 +1,25 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"strings"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// IsDuplicateKeyError checks if an error is a duplicate key constraint violation
|
||||
func IsDuplicateKeyError(err error) bool {
|
||||
if err == nil {
|
||||
return false
|
||||
}
|
||||
|
||||
// Check for GORM duplicate key error
|
||||
if errors.Is(err, gorm.ErrDuplicatedKey) {
|
||||
return true
|
||||
}
|
||||
|
||||
// Check for PostgreSQL duplicate key error (SQLSTATE 23505)
|
||||
errMsg := strings.ToLower(err.Error())
|
||||
return strings.Contains(errMsg, "duplicate key value violates unique constraint") ||
|
||||
strings.Contains(errMsg, "sqlstate 23505")
|
||||
}
|
||||
Reference in New Issue
Block a user