diff --git a/go.mod b/go.mod index e9c7abaf..a9662159 100644 --- a/go.mod +++ b/go.mod @@ -32,7 +32,7 @@ require ( gorm.io/datatypes v1.2.6 gorm.io/driver/mysql v1.6.0 gorm.io/driver/sqlite v1.6.0 - gorm.io/gorm v1.30.3 + gorm.io/gorm v1.30.5 ) require ( diff --git a/go.sum b/go.sum index 86596b9b..68195685 100644 --- a/go.sum +++ b/go.sum @@ -234,5 +234,5 @@ gorm.io/driver/sqlite v1.6.0 h1:WHRRrIiulaPiPFmDcod6prc4l2VGVWHz80KspNsxSfQ= gorm.io/driver/sqlite v1.6.0/go.mod h1:AO9V1qIQddBESngQUKWL9yoH93HIeA1X6V633rBwyT8= gorm.io/driver/sqlserver v1.6.0 h1:VZOBQVsVhkHU/NzNhRJKoANt5pZGQAS1Bwc6m6dgfnc= gorm.io/driver/sqlserver v1.6.0/go.mod h1:WQzt4IJo/WHKnckU9jXBLMJIVNMVeTu25dnOzehntWw= -gorm.io/gorm v1.30.3 h1:QiG8upl0Sg9ba2Zatfjy0fy4It2iNBL2/eMdvEkdXNs= -gorm.io/gorm v1.30.3/go.mod h1:8Z33v652h4//uMA76KjeDH8mJXPm1QNCYrMeatR0DOE= +gorm.io/gorm v1.30.5 h1:dvEfYwxL+i+xgCNSGGBT1lDjCzfELK8fHZxL3Ee9X0s= +gorm.io/gorm v1.30.5/go.mod h1:8Z33v652h4//uMA76KjeDH8mJXPm1QNCYrMeatR0DOE= diff --git a/vendor/gorm.io/gorm/clause/set.go b/vendor/gorm.io/gorm/clause/set.go index 75eb6bdd..2ffadb38 100644 --- a/vendor/gorm.io/gorm/clause/set.go +++ b/vendor/gorm.io/gorm/clause/set.go @@ -9,6 +9,11 @@ type Assignment struct { Value interface{} } +// Assigner assignments provider interface +type Assigner interface { + Assignments() []Assignment +} + func (set Set) Name() string { return "SET" } @@ -37,6 +42,9 @@ func (set Set) MergeClause(clause *Clause) { clause.Expression = Set(copiedAssignments) } +// Assignments implements Assigner for Set. +func (set Set) Assignments() []Assignment { return []Assignment(set) } + func Assignments(values map[string]interface{}) Set { keys := make([]string, 0, len(values)) for key := range values { @@ -58,3 +66,6 @@ func AssignmentColumns(values []string) Set { } return assignments } + +// Assignments implements Assigner for a single Assignment. +func (a Assignment) Assignments() []Assignment { return []Assignment{a} } diff --git a/vendor/gorm.io/gorm/generics.go b/vendor/gorm.io/gorm/generics.go index f31bdc5e..8c79342b 100644 --- a/vendor/gorm.io/gorm/generics.go +++ b/vendor/gorm.io/gorm/generics.go @@ -35,10 +35,33 @@ type Interface[T any] interface { } type CreateInterface[T any] interface { - ChainInterface[T] + ExecInterface[T] + // chain methods available at start; return ChainInterface + Scopes(scopes ...func(db *Statement)) ChainInterface[T] + Where(query interface{}, args ...interface{}) ChainInterface[T] + Not(query interface{}, args ...interface{}) ChainInterface[T] + Or(query interface{}, args ...interface{}) ChainInterface[T] + Limit(offset int) ChainInterface[T] + Offset(offset int) ChainInterface[T] + Joins(query clause.JoinTarget, on func(db JoinBuilder, joinTable clause.Table, curTable clause.Table) error) ChainInterface[T] + Preload(association string, query func(db PreloadBuilder) error) ChainInterface[T] + Select(query string, args ...interface{}) ChainInterface[T] + Omit(columns ...string) ChainInterface[T] + MapColumns(m map[string]string) ChainInterface[T] + Distinct(args ...interface{}) ChainInterface[T] + Group(name string) ChainInterface[T] + Having(query interface{}, args ...interface{}) ChainInterface[T] + Order(value interface{}) ChainInterface[T] + Build(builder clause.Builder) + + Delete(ctx context.Context) (rowsAffected int, err error) + Update(ctx context.Context, name string, value any) (rowsAffected int, err error) + Updates(ctx context.Context, t T) (rowsAffected int, err error) + Table(name string, args ...interface{}) CreateInterface[T] Create(ctx context.Context, r *T) error CreateInBatches(ctx context.Context, r *[]T, batchSize int) error + Set(assignments ...clause.Assigner) SetCreateOrUpdateInterface[T] } type ChainInterface[T any] interface { @@ -58,15 +81,28 @@ type ChainInterface[T any] interface { Group(name string) ChainInterface[T] Having(query interface{}, args ...interface{}) ChainInterface[T] Order(value interface{}) ChainInterface[T] + Set(assignments ...clause.Assigner) SetUpdateOnlyInterface[T] Build(builder clause.Builder) + Table(name string, args ...interface{}) ChainInterface[T] Delete(ctx context.Context) (rowsAffected int, err error) Update(ctx context.Context, name string, value any) (rowsAffected int, err error) Updates(ctx context.Context, t T) (rowsAffected int, err error) Count(ctx context.Context, column string) (result int64, err error) } +// SetUpdateOnlyInterface is returned by Set after chaining; only Update is allowed +type SetUpdateOnlyInterface[T any] interface { + Update(ctx context.Context) (rowsAffected int, err error) +} + +// SetCreateOrUpdateInterface is returned by Set at start; Create or Update are allowed +type SetCreateOrUpdateInterface[T any] interface { + Create(ctx context.Context) error + Update(ctx context.Context) (rowsAffected int, err error) +} + type ExecInterface[T any] interface { Scan(ctx context.Context, r interface{}) error First(context.Context) (T, error) @@ -163,6 +199,10 @@ func (c createG[T]) Table(name string, args ...interface{}) CreateInterface[T] { })} } +func (c createG[T]) Set(assignments ...clause.Assigner) SetCreateOrUpdateInterface[T] { + return setCreateOrUpdateG[T]{c: c.chainG, assigns: toAssignments(assignments...)} +} + func (c createG[T]) Create(ctx context.Context, r *T) error { return c.g.apply(ctx).Create(r).Error } @@ -189,6 +229,12 @@ func (c chainG[T]) with(v op) chainG[T] { } } +func (c chainG[T]) Table(name string, args ...interface{}) ChainInterface[T] { + return c.with(func(db *DB) *DB { + return db.Table(name, args...) + }) +} + func (c chainG[T]) Scopes(scopes ...func(db *Statement)) ChainInterface[T] { return c.with(func(db *DB) *DB { for _, fc := range scopes { @@ -198,12 +244,6 @@ func (c chainG[T]) Scopes(scopes ...func(db *Statement)) ChainInterface[T] { }) } -func (c chainG[T]) Table(name string, args ...interface{}) ChainInterface[T] { - return c.with(func(db *DB) *DB { - return db.Table(name, args...) - }) -} - func (c chainG[T]) Where(query interface{}, args ...interface{}) ChainInterface[T] { return c.with(func(db *DB) *DB { return db.Where(query, args...) @@ -390,6 +430,10 @@ func (c chainG[T]) MapColumns(m map[string]string) ChainInterface[T] { }) } +func (c chainG[T]) Set(assignments ...clause.Assigner) SetUpdateOnlyInterface[T] { + return setCreateOrUpdateG[T]{c: c, assigns: toAssignments(assignments...)} +} + func (c chainG[T]) Distinct(args ...interface{}) ChainInterface[T] { return c.with(func(db *DB) *DB { return db.Distinct(args...) @@ -557,6 +601,36 @@ func (c chainG[T]) Build(builder clause.Builder) { } } +type setCreateOrUpdateG[T any] struct { + c chainG[T] + assigns []clause.Assignment +} + +// toAssignments converts various supported types into []clause.Assignment. +// Supported inputs implement clause.Assigner. +func toAssignments(items ...clause.Assigner) []clause.Assignment { + out := make([]clause.Assignment, 0, len(items)) + for _, it := range items { + out = append(out, it.Assignments()...) + } + return out +} + +func (s setCreateOrUpdateG[T]) Update(ctx context.Context) (rowsAffected int, err error) { + var r T + res := s.c.g.apply(ctx).Model(r).Clauses(clause.Set(s.assigns)).Updates(map[string]interface{}{}) + return int(res.RowsAffected), res.Error +} + +func (s setCreateOrUpdateG[T]) Create(ctx context.Context) error { + var r T + data := make(map[string]interface{}, len(s.assigns)) + for _, a := range s.assigns { + data[a.Column.Name] = a.Value + } + return s.c.g.apply(ctx).Model(r).Create(data).Error +} + type execG[T any] struct { g *g[T] } diff --git a/vendor/gorm.io/gorm/logger/slog.go b/vendor/gorm.io/gorm/logger/slog.go index 44f289e6..613234ca 100644 --- a/vendor/gorm.io/gorm/logger/slog.go +++ b/vendor/gorm.io/gorm/logger/slog.go @@ -1,3 +1,5 @@ +//go:build go1.21 + package logger import ( @@ -88,3 +90,11 @@ func (l *slogLogger) Trace(ctx context.Context, begin time.Time, fc func() (sql }) } } + +// ParamsFilter filter params +func (l *slogLogger) ParamsFilter(ctx context.Context, sql string, params ...interface{}) (string, []interface{}) { + if l.Parameterized { + return sql, nil + } + return sql, params +} diff --git a/vendor/modules.txt b/vendor/modules.txt index fd32af7b..7ed89ff1 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -385,7 +385,7 @@ gorm.io/driver/mysql # gorm.io/driver/sqlite v1.6.0 ## explicit; go 1.20 gorm.io/driver/sqlite -# gorm.io/gorm v1.30.3 +# gorm.io/gorm v1.30.5 ## explicit; go 1.18 gorm.io/gorm gorm.io/gorm/callbacks