v0.0.387 bf
All checks were successful
Build Docker and Deploy / Run goext test-suite (push) Successful in 3m24s
All checks were successful
Build Docker and Deploy / Run goext test-suite (push) Successful in 3m24s
This commit is contained in:
parent
3c439ba428
commit
7fedfbca81
2
go.mod
2
go.mod
@ -23,7 +23,7 @@ require (
|
||||
github.com/gin-contrib/sse v0.1.0 // indirect
|
||||
github.com/go-playground/locales v0.14.1 // indirect
|
||||
github.com/go-playground/universal-translator v0.18.1 // indirect
|
||||
github.com/go-playground/validator/v10 v10.17.0 // indirect
|
||||
github.com/go-playground/validator/v10 v10.18.0 // indirect
|
||||
github.com/goccy/go-json v0.10.2 // indirect
|
||||
github.com/golang/snappy v0.0.4 // indirect
|
||||
github.com/google/uuid v1.5.0 // indirect
|
||||
|
2
go.sum
2
go.sum
@ -33,6 +33,8 @@ github.com/go-playground/validator/v10 v10.16.0 h1:x+plE831WK4vaKHO/jpgUGsvLKIqR
|
||||
github.com/go-playground/validator/v10 v10.16.0/go.mod h1:9iXMNT7sEkjXb0I+enO7QXmzG6QCsPWY4zveKFVRSyU=
|
||||
github.com/go-playground/validator/v10 v10.17.0 h1:SmVVlfAOtlZncTxRuinDPomC2DkXJ4E5T9gDA0AIH74=
|
||||
github.com/go-playground/validator/v10 v10.17.0/go.mod h1:9iXMNT7sEkjXb0I+enO7QXmzG6QCsPWY4zveKFVRSyU=
|
||||
github.com/go-playground/validator/v10 v10.18.0 h1:BvolUXjp4zuvkZ5YN5t7ebzbhlUtPsPm2S9NAZ5nl9U=
|
||||
github.com/go-playground/validator/v10 v10.18.0/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM=
|
||||
github.com/go-sql-driver/mysql v1.6.0 h1:BCTh4TKNUYmOmMUcQ3IipzF5prigylS7XXjEkfCHuOE=
|
||||
github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
|
||||
github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU=
|
||||
|
@ -1,5 +1,5 @@
|
||||
package goext
|
||||
|
||||
const GoextVersion = "0.0.386"
|
||||
const GoextVersion = "0.0.387"
|
||||
|
||||
const GoextVersionTimestamp = "2024-02-09T15:58:21+0100"
|
||||
const GoextVersionTimestamp = "2024-02-12T18:17:49+0100"
|
||||
|
@ -44,7 +44,7 @@ func InsertAndQuerySingle[TData any](ctx context.Context, q Queryable, tableName
|
||||
|
||||
rval := reflect.ValueOf(v)
|
||||
|
||||
idRVal := rval.FieldByName(idColumn)
|
||||
idRVal := fieldByTag(rval, "db", idColumn)
|
||||
if !idRVal.IsValid() || idRVal.IsZero() {
|
||||
return *new(TData), fmt.Errorf("failed to find idColumn '%s' in %T", idColumn, v)
|
||||
}
|
||||
@ -67,6 +67,22 @@ func InsertAndQuerySingle[TData any](ctx context.Context, q Queryable, tableName
|
||||
return QuerySingle[TData](ctx, q, sqlstr, pp, mode, sec)
|
||||
}
|
||||
|
||||
func fieldByTag(rval reflect.Value, tagkey string, tagval string) reflect.Value {
|
||||
rtyp := rval.Type()
|
||||
for i := 0; i < rtyp.NumField(); i++ {
|
||||
rsfield := rtyp.Field(i)
|
||||
|
||||
if !rsfield.IsExported() {
|
||||
continue
|
||||
}
|
||||
|
||||
if rsfield.Tag.Get(tagkey) == tagval {
|
||||
return rval.Field(i)
|
||||
}
|
||||
}
|
||||
panic(fmt.Sprintf("tag %s = '%s' not found in %s", tagkey, tagval, rtyp.Name()))
|
||||
}
|
||||
|
||||
func InsertMultiple[TData any](ctx context.Context, q Queryable, tableName string, vArr []TData, maxBatch int) ([]sql.Result, error) {
|
||||
|
||||
if len(vArr) == 0 {
|
||||
@ -122,7 +138,7 @@ func UpdateAndQuerySingle[TData any](ctx context.Context, q Queryable, tableName
|
||||
|
||||
rval := reflect.ValueOf(v)
|
||||
|
||||
idRVal := rval.FieldByName(idColumn)
|
||||
idRVal := fieldByTag(rval, "db", idColumn)
|
||||
if !idRVal.IsValid() || idRVal.IsZero() {
|
||||
return *new(TData), fmt.Errorf("failed to find idColumn '%s' in %T", idColumn, v)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user