v0.0.386 InsertAndQuerySingle
All checks were successful
Build Docker and Deploy / Run goext test-suite (push) Successful in 1m27s
All checks were successful
Build Docker and Deploy / Run goext test-suite (push) Successful in 1m27s
This commit is contained in:
parent
ad24f6db44
commit
3c439ba428
@ -1,5 +1,5 @@
|
||||
package goext
|
||||
|
||||
const GoextVersion = "0.0.385"
|
||||
const GoextVersion = "0.0.386"
|
||||
|
||||
const GoextVersionTimestamp = "2024-02-09T15:40:09+0100"
|
||||
const GoextVersionTimestamp = "2024-02-09T15:58:21+0100"
|
||||
|
@ -40,6 +40,33 @@ func InsertSingle[TData any](ctx context.Context, q Queryable, tableName string,
|
||||
return sqlr, nil
|
||||
}
|
||||
|
||||
func InsertAndQuerySingle[TData any](ctx context.Context, q Queryable, tableName string, v TData, idColumn string, mode StructScanMode, sec StructScanSafety) (TData, error) {
|
||||
|
||||
rval := reflect.ValueOf(v)
|
||||
|
||||
idRVal := rval.FieldByName(idColumn)
|
||||
if !idRVal.IsValid() || idRVal.IsZero() {
|
||||
return *new(TData), fmt.Errorf("failed to find idColumn '%s' in %T", idColumn, v)
|
||||
}
|
||||
|
||||
idValue, err := convertValueToDB(q, idRVal.Interface())
|
||||
if err != nil {
|
||||
return *new(TData), err
|
||||
}
|
||||
|
||||
_, err = InsertSingle[TData](ctx, q, tableName, v)
|
||||
if err != nil {
|
||||
return *new(TData), err
|
||||
}
|
||||
|
||||
pp := PP{}
|
||||
|
||||
//goland:noinspection ALL
|
||||
sqlstr := fmt.Sprintf("SELECT * FROM %s WHERE %s = :%s", tableName, idColumn, pp.Add(idValue))
|
||||
|
||||
return QuerySingle[TData](ctx, q, sqlstr, pp, mode, sec)
|
||||
}
|
||||
|
||||
func InsertMultiple[TData any](ctx context.Context, q Queryable, tableName string, vArr []TData, maxBatch int) ([]sql.Result, error) {
|
||||
|
||||
if len(vArr) == 0 {
|
||||
|
Loading…
Reference in New Issue
Block a user