mirror of https://github.com/VinGarcia/ksql.git
Small refactor to the Patch() function
parent
259b3a228a
commit
211fddf4ee
13
ksql.go
13
ksql.go
|
@ -686,7 +686,12 @@ func (c DB) Patch(
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
query, params, err := buildUpdateQuery(ctx, c.dialect, table.name, info, record, table.idColumns...)
|
recordMap, err := structs.StructToMap(record)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
query, params, err := buildUpdateQuery(ctx, c.dialect, table.name, info, recordMap, table.idColumns...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -832,13 +837,9 @@ func buildUpdateQuery(
|
||||||
dialect Dialect,
|
dialect Dialect,
|
||||||
tableName string,
|
tableName string,
|
||||||
info structs.StructInfo,
|
info structs.StructInfo,
|
||||||
record interface{},
|
recordMap map[string]interface{},
|
||||||
idFieldNames ...string,
|
idFieldNames ...string,
|
||||||
) (query string, args []interface{}, err error) {
|
) (query string, args []interface{}, err error) {
|
||||||
recordMap, err := structs.StructToMap(record)
|
|
||||||
if err != nil {
|
|
||||||
return "", nil, err
|
|
||||||
}
|
|
||||||
for key := range recordMap {
|
for key := range recordMap {
|
||||||
if info.ByName(key).Modifier.SkipOnUpdate {
|
if info.ByName(key).Modifier.SkipOnUpdate {
|
||||||
delete(recordMap, key)
|
delete(recordMap, key)
|
||||||
|
|
Loading…
Reference in New Issue