mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-22 06:53:52 +00:00
fix reflect insert (remove gid field)
This commit is contained in:
parent
cca813e5e5
commit
e7dfd4a654
|
@ -40,6 +40,10 @@ func placeholdersOf(record interface{}) []string {
|
||||||
for i := 0; i < rt.NumField(); i++ {
|
for i := 0; i < rt.NumField(); i++ {
|
||||||
fieldType := rt.Field(i)
|
fieldType := rt.Field(i)
|
||||||
if tag, ok := fieldType.Tag.Lookup("db"); ok {
|
if tag, ok := fieldType.Tag.Lookup("db"); ok {
|
||||||
|
if tag == "gid" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
dbFields = append(dbFields, ":"+tag)
|
dbFields = append(dbFields, ":"+tag)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -61,6 +65,10 @@ func fieldsNamesOf(record interface{}) []string {
|
||||||
for i := 0; i < rt.NumField(); i++ {
|
for i := 0; i < rt.NumField(); i++ {
|
||||||
fieldType := rt.Field(i)
|
fieldType := rt.Field(i)
|
||||||
if tag, ok := fieldType.Tag.Lookup("db"); ok {
|
if tag, ok := fieldType.Tag.Lookup("db"); ok {
|
||||||
|
if tag == "gid" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
dbFields = append(dbFields, tag)
|
dbFields = append(dbFields, tag)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -68,6 +76,23 @@ func fieldsNamesOf(record interface{}) []string {
|
||||||
return dbFields
|
return dbFields
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ParseStructTag(s string) (string, map[string]string) {
|
||||||
|
opts := make(map[string]string)
|
||||||
|
ss := strings.Split(s, ",")
|
||||||
|
if len(ss) > 1 {
|
||||||
|
for _, opt := range ss[1:] {
|
||||||
|
aa := strings.SplitN(opt, "=", 2)
|
||||||
|
if len(aa) == 2 {
|
||||||
|
opts[aa[0]] = aa[1]
|
||||||
|
} else {
|
||||||
|
opts[aa[0]] = ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ss[0], opts
|
||||||
|
}
|
||||||
|
|
||||||
type ReflectCache struct {
|
type ReflectCache struct {
|
||||||
tableNames map[string]string
|
tableNames map[string]string
|
||||||
fields map[string][]string
|
fields map[string][]string
|
||||||
|
|
|
@ -58,7 +58,7 @@ func Test_fieldsNamesOf(t *testing.T) {
|
||||||
{
|
{
|
||||||
name: "MarginInterest",
|
name: "MarginInterest",
|
||||||
args: args{record: &types.MarginInterest{}},
|
args: args{record: &types.MarginInterest{}},
|
||||||
want: []string{"gid", "exchange", "asset", "principle", "interest", "interest_rate", "isolated_symbol", "time"},
|
want: []string{"exchange", "asset", "principle", "interest", "interest_rate", "isolated_symbol", "time"},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user