WIP : create antrian operasi
This commit is contained in:
@@ -1332,6 +1332,7 @@ func (qb *QueryBuilder) ExecuteInsert(ctx context.Context, db *sqlx.DB, table st
|
||||
start := time.Now()
|
||||
result, err := db.ExecContext(ctx, sql, args...)
|
||||
if qb.enableQueryLogging {
|
||||
fmt.Printf("[DEBUG BuilderQuery] Final SQL query: %s\n", sql)
|
||||
fmt.Printf("[DEBUG] Insert query executed in %v\n", time.Since(start))
|
||||
}
|
||||
return result, err
|
||||
@@ -1712,6 +1713,39 @@ func (qb *QueryBuilder) BuildInsertQuery(table string, data InsertData, returnin
|
||||
return sql, args, nil
|
||||
}
|
||||
|
||||
func (qb *QueryBuilder) BuildBulkInsertQuery(table string, data InsertData, returningColumns ...string) (string, []interface{}, error) {
|
||||
// Validate columns
|
||||
for _, col := range data.Columns {
|
||||
if qb.allowedColumns != nil && !qb.allowedColumns[col] {
|
||||
return "", nil, fmt.Errorf("disallowed column: %s", col)
|
||||
}
|
||||
}
|
||||
|
||||
// Start with basic insert
|
||||
insert := qb.sqlBuilder.Insert(table).Columns(data.Columns...)
|
||||
|
||||
// loop insert data values
|
||||
for _, item := range data.Values {
|
||||
log.Printf("%s", item)
|
||||
insert.Values(item)
|
||||
}
|
||||
|
||||
if len(returningColumns) > 0 {
|
||||
if qb.dbType == DBTypePostgreSQL {
|
||||
insert = insert.Suffix("RETURNING " + strings.Join(returningColumns, ", "))
|
||||
} else {
|
||||
return "", nil, fmt.Errorf("RETURNING not supported for database type: %s", qb.dbType)
|
||||
}
|
||||
}
|
||||
|
||||
sql, args, err := insert.ToSql()
|
||||
if err != nil {
|
||||
return "", nil, fmt.Errorf("failed to build INSERT query: %w", err)
|
||||
}
|
||||
|
||||
return sql, args, nil
|
||||
}
|
||||
|
||||
// BuildUpdateQuery builds an UPDATE query
|
||||
func (qb *QueryBuilder) BuildUpdateQuery(table string, updateData UpdateData, filters []FilterGroup, returningColumns ...string) (string, []interface{}, error) {
|
||||
// Validate columns
|
||||
|
||||
Reference in New Issue
Block a user