This commit is contained in:
John Guo 2022-01-10 15:50:15 +08:00
commit bc29e86e58

View File

@ -14,6 +14,7 @@ package gdb
import (
"context"
"database/sql"
"database/sql/driver"
"fmt"
"strings"
@ -204,3 +205,21 @@ func (d *DriverPgsql) DoInsert(ctx context.Context, link Link, table string, lis
return d.Core.DoInsert(ctx, link, table, list, option)
}
}
// ConvertDataForRecord converting for any data that will be inserted into table/collection as a record.
func (d *DriverPgsql) ConvertDataForRecord(ctx context.Context, value interface{}) map[string]interface{} {
data := DataToMapDeep(value)
var err error
for k, v := range data {
if valuer, ok := v.(driver.Valuer); ok {
data[k], err = valuer.Value()
if err != nil {
return nil
}
} else {
data[k] = d.Core.ConvertDataForRecordValue(ctx, v)
}
}
return data
}