From f04715bccb93b222156ba49ff056cef40ddef0fb Mon Sep 17 00:00:00 2001 From: starccck Date: Wed, 29 Dec 2021 00:13:22 +0800 Subject: [PATCH 1/3] support manipulate pg.Array type data --- database/gdb/gdb_driver_pgsql.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/database/gdb/gdb_driver_pgsql.go b/database/gdb/gdb_driver_pgsql.go index a581ee0d2..a081dee7f 100644 --- a/database/gdb/gdb_driver_pgsql.go +++ b/database/gdb/gdb_driver_pgsql.go @@ -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 +} From a3bab8db552f2352bf8ec564cd6dd289b068f5f2 Mon Sep 17 00:00:00 2001 From: flead <164035526@qq.com> Date: Sat, 8 Jan 2022 12:02:56 +0800 Subject: [PATCH 2/3] Use Copyfile() to back up the log, so as not to continue writing the log to the old file because the old fd is not closed #1366 --- os/glog/glog_logger_rotate.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/os/glog/glog_logger_rotate.go b/os/glog/glog_logger_rotate.go index 6e7ca96de..5a206f351 100644 --- a/os/glog/glog_logger_rotate.go +++ b/os/glog/glog_logger_rotate.go @@ -100,9 +100,13 @@ func (l *Logger) doRotateFile(ctx context.Context, filePath string) error { } } intlog.Printf(ctx, "rotating file by size from %s to %s", filePath, newFilePath) - if err := gfile.Rename(filePath, newFilePath); err != nil { + + if err := gfile.CopyFile(filePath, newFilePath); err != nil { + intlog.Error(ctx, "copy file to: ", newFilePath, err) return err } + gfile.Truncate(filePath, 0) + return nil } From 6232c873b88fc8f8c49598b6c469d3ce23b844a4 Mon Sep 17 00:00:00 2001 From: flead <164035526@qq.com> Date: Sat, 8 Jan 2022 12:10:39 +0800 Subject: [PATCH 3/3] Revert "Use Copyfile() to back up the log, so as not to continue writing the log to the old file because the old fd is not closed #1366" This reverts commit a3bab8db552f2352bf8ec564cd6dd289b068f5f2. --- os/glog/glog_logger_rotate.go | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/os/glog/glog_logger_rotate.go b/os/glog/glog_logger_rotate.go index 5a206f351..6e7ca96de 100644 --- a/os/glog/glog_logger_rotate.go +++ b/os/glog/glog_logger_rotate.go @@ -100,13 +100,9 @@ func (l *Logger) doRotateFile(ctx context.Context, filePath string) error { } } intlog.Printf(ctx, "rotating file by size from %s to %s", filePath, newFilePath) - - if err := gfile.CopyFile(filePath, newFilePath); err != nil { - intlog.Error(ctx, "copy file to: ", newFilePath, err) + if err := gfile.Rename(filePath, newFilePath); err != nil { return err } - gfile.Truncate(filePath, 0) - return nil }