@@ -37,29 +37,33 @@ func InsertWithHeap(c *crypto.Crypto, ctx context.Context, tx *sql.Tx, tableName
37
37
entityValue := reflect .ValueOf (entity )
38
38
entityType := entityValue .Type ()
39
39
40
- fieldNames := make ( []string , entityType . NumField ())
41
- placeholders := make ([] string , entityType . NumField ())
42
- args := make ([] interface {}, entityType . NumField ())
40
+ var fieldNames []string
41
+ var args [] interface {}
42
+ var placeholders [] string
43
43
44
44
var th []TextHeap
45
45
for i := 0 ; i < entityType .NumField (); i ++ {
46
46
field := entityType .Field (i )
47
- fieldNames [i ] = field .Tag .Get ("db" )
48
- args [i ] = entityValue .Field (i ).Interface ()
47
+ fieldName := field .Tag .Get ("db" )
48
+ if fieldName == "" {
49
+ continue
50
+ }
49
51
50
- if field .Tag .Get ("bidx_col" ) != "" {
51
- fieldNames = append (fieldNames , field .Tag .Get ("bidx_col" ))
52
+ fieldNames = append (fieldNames , fieldName )
53
+ args = append (args , entityValue .Field (i ).Interface ())
54
+
55
+ if bidxCol := field .Tag .Get ("bidx_col" ); bidxCol != "" {
56
+ fieldNames = append (fieldNames , bidxCol )
52
57
placeholders = append (placeholders , "$" + fmt .Sprint (len (placeholders )+ 1 ))
53
58
54
- switch entityValue .Field (i ).Interface ().(type ) {
59
+ switch fieldValue := entityValue .Field (i ).Interface ().(type ) {
55
60
case types.AESChiper :
56
- fieldValue := entityValue .Field (i ).Interface ().(types.AESChiper )
57
61
str , heaps := BuildHeap (c , fieldValue .To (), field .Tag .Get ("txt_heap_table" ))
58
62
th = append (th , heaps ... )
59
63
args = append (args , str )
60
64
}
61
65
}
62
- placeholders [ i ] = "$" + fmt .Sprint (i + 1 )
66
+ placeholders = append ( placeholders , "$" + fmt .Sprint (len ( placeholders ) + 1 ) )
63
67
}
64
68
65
69
query := fmt .Sprintf ("INSERT INTO %s (%s) VALUES (%s)" , tableName , strings .Join (fieldNames , ", " ), strings .Join (placeholders , ", " ))
0 commit comments