@@ -33,7 +33,7 @@ type TextHeap struct {
33
33
Hash string
34
34
}
35
35
36
- func InsertWithHeap [T Entity ](c * crypto.Crypto , ctx context.Context , tx * sql.Tx , tableName string , entity T ) (a T , err error ) {
36
+ func InsertWithHeap [T Entity ](c * crypto.Crypto , ctx context.Context , tx * sql.Tx , tableName string , entity any , generic T ) (a T , err error ) {
37
37
entityValue := reflect .ValueOf (entity )
38
38
entityType := entityValue .Type ()
39
39
var fieldNames []string
@@ -104,15 +104,15 @@ func InsertWithHeap[T Entity](c *crypto.Crypto, ctx context.Context, tx *sql.Tx,
104
104
placeholders = append (placeholders , "$" + fmt .Sprint (len (placeholders )+ 1 ))
105
105
}
106
106
107
- query := fmt .Sprintf ("INSERT INTO %s (%s) VALUES (%s) RETURNING (%s) " , tableName , strings .Join (fieldNames , ", " ), strings .Join (placeholders , ", " ), strings . Join ( fieldNames , ", " ))
107
+ query := fmt .Sprintf ("INSERT INTO %s (%s) VALUES (%s) RETURNING id " , tableName , strings .Join (fieldNames , ", " ), strings .Join (placeholders , ", " ))
108
108
109
- // stmt, err := tx.PrepareContext(ctx, query)
110
- // if err != nil {
111
- // return a, fmt.Errorf("failed to prepare statement: %w", err)
112
- // }
113
- // defer stmt.Close()
109
+ stmt , err := tx .PrepareContext (ctx , query )
110
+ if err != nil {
111
+ return a , fmt .Errorf ("failed to prepare statement: %w" , err )
112
+ }
113
+ defer stmt .Close ()
114
114
115
- err = tx .QueryRowContext (ctx , query , args ... ).Scan (& a )
115
+ err = stmt .QueryRowContext (ctx , args ... ).Scan (& a )
116
116
if err != nil {
117
117
return a , fmt .Errorf ("failed to execute statement: %w" , err )
118
118
}
0 commit comments