From 211fddf4ee53fe519e51f2818708f9439cd6f1cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Garcia?= Date: Tue, 13 Dec 2022 22:36:23 -0300 Subject: [PATCH] Small refactor to the Patch() function --- ksql.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/ksql.go b/ksql.go index 690e592..808991a 100644 --- a/ksql.go +++ b/ksql.go @@ -686,7 +686,12 @@ func (c DB) Patch( 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 { return err } @@ -832,13 +837,9 @@ func buildUpdateQuery( dialect Dialect, tableName string, info structs.StructInfo, - record interface{}, + recordMap map[string]interface{}, idFieldNames ...string, ) (query string, args []interface{}, err error) { - recordMap, err := structs.StructToMap(record) - if err != nil { - return "", nil, err - } for key := range recordMap { if info.ByName(key).Modifier.SkipOnUpdate { delete(recordMap, key)