New
This commit is contained in:
30
internal/db/dialect/sqlite_adapter.go
Normal file
30
internal/db/dialect/sqlite_adapter.go
Normal file
@@ -0,0 +1,30 @@
|
||||
// Filename: internal/db/sqlite_adapter.go (全新文件 - 最终版)
|
||||
package dialect
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/clause"
|
||||
)
|
||||
|
||||
type sqliteAdapter struct{}
|
||||
|
||||
func NewSQLiteAdapter() DialectAdapter {
|
||||
return &sqliteAdapter{}
|
||||
}
|
||||
|
||||
func (a *sqliteAdapter) OnConflictUpdateAll(conflictColumns []string, updateColumns []string) clause.Expression {
|
||||
conflictCols := make([]clause.Column, len(conflictColumns))
|
||||
for i, col := range conflictColumns {
|
||||
conflictCols[i] = clause.Column{Name: col}
|
||||
}
|
||||
|
||||
assignments := make(map[string]interface{})
|
||||
for _, col := range updateColumns {
|
||||
assignments[col] = gorm.Expr(col + " + excluded." + col)
|
||||
}
|
||||
|
||||
return clause.OnConflict{
|
||||
Columns: conflictCols,
|
||||
DoUpdates: clause.Assignments(assignments),
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user