Skip to content

Commit

Permalink
fix: insert heap
Browse files Browse the repository at this point in the history
  • Loading branch information
dyaksa committed Jul 17, 2024
1 parent f88a24d commit 1ebc3f2
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions crypto/query/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,29 +37,33 @@ func InsertWithHeap(c *crypto.Crypto, ctx context.Context, tx *sql.Tx, tableName
entityValue := reflect.ValueOf(entity)
entityType := entityValue.Type()

fieldNames := make([]string, entityType.NumField())
placeholders := make([]string, entityType.NumField())
args := make([]interface{}, entityType.NumField())
var fieldNames []string
var args []interface{}
var placeholders []string

var th []TextHeap
for i := 0; i < entityType.NumField(); i++ {
field := entityType.Field(i)
fieldNames[i] = field.Tag.Get("db")
args[i] = entityValue.Field(i).Interface()
fieldName := field.Tag.Get("db")
if fieldName == "" {
continue
}

if field.Tag.Get("bidx_col") != "" {
fieldNames = append(fieldNames, field.Tag.Get("bidx_col"))
fieldNames = append(fieldNames, fieldName)
args = append(args, entityValue.Field(i).Interface())

if bidxCol := field.Tag.Get("bidx_col"); bidxCol != "" {
fieldNames = append(fieldNames, bidxCol)
placeholders = append(placeholders, "$"+fmt.Sprint(len(placeholders)+1))

switch entityValue.Field(i).Interface().(type) {
switch fieldValue := entityValue.Field(i).Interface().(type) {
case types.AESChiper:
fieldValue := entityValue.Field(i).Interface().(types.AESChiper)
str, heaps := BuildHeap(c, fieldValue.To(), field.Tag.Get("txt_heap_table"))
th = append(th, heaps...)
args = append(args, str)
}
}
placeholders[i] = "$" + fmt.Sprint(i+1)
placeholders = append(placeholders, "$"+fmt.Sprint(len(placeholders)+1))
}

query := fmt.Sprintf("INSERT INTO %s (%s) VALUES (%s)", tableName, strings.Join(fieldNames, ", "), strings.Join(placeholders, ", "))
Expand Down

0 comments on commit 1ebc3f2

Please sign in to comment.