fix reflection

This commit is contained in:
c9s 2024-06-19 16:07:39 +08:00
parent 00b9c3156f
commit 82501ff57c
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54
2 changed files with 11 additions and 5 deletions

View File

@ -1,6 +1,6 @@
-- +up -- +up
-- +begin -- +begin
ALTER TABLE `trades` ADD COLUMN `inserted_at` DATETIME(3) DEFAULT CURRENT_TIMESTAMP NOT NULL AFTER `traded_at`; ALTER TABLE `trades` ADD COLUMN `inserted_at` DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL AFTER `traded_at`;
-- +end -- +end
-- +begin -- +begin

View File

@ -27,13 +27,16 @@ func tableNameOf(record interface{}) string {
} }
func placeholdersOf(record interface{}) []string { func placeholdersOf(record interface{}) []string {
vt := reflect.ValueOf(record)
rt := reflect.TypeOf(record) rt := reflect.TypeOf(record)
if rt.Kind() == reflect.Ptr { if rt.Kind() == reflect.Ptr {
rt = rt.Elem() rt = rt.Elem()
} }
vt := reflect.ValueOf(record)
if vt.Kind() == reflect.Ptr {
vt = vt.Elem()
}
if rt.Kind() != reflect.Struct { if rt.Kind() != reflect.Struct {
return nil return nil
} }
@ -60,13 +63,16 @@ func placeholdersOf(record interface{}) []string {
} }
func fieldsNamesOf(record interface{}) []string { func fieldsNamesOf(record interface{}) []string {
vt := reflect.ValueOf(record)
rt := reflect.TypeOf(record) rt := reflect.TypeOf(record)
if rt.Kind() == reflect.Ptr { if rt.Kind() == reflect.Ptr {
rt = rt.Elem() rt = rt.Elem()
} }
vt := reflect.ValueOf(record)
if vt.Kind() == reflect.Ptr {
vt = vt.Elem()
}
if rt.Kind() != reflect.Struct { if rt.Kind() != reflect.Struct {
return nil return nil
} }