9
9
"regexp"
10
10
"strconv"
11
11
"strings"
12
+ "time"
12
13
13
14
"github.com/Masterminds/squirrel"
14
15
"github.com/go-gorp/gorp/v3"
@@ -134,24 +135,38 @@ func (d *SqlDbConnection) PrepareQuery(query string) string {
134
135
return d .prepareQueryWithDialect (query , d .sql .Dialect )
135
136
}
136
137
138
+ func formatArgs (args []any ) (formattedArgs []any ) {
139
+ for _ , arg := range args {
140
+ switch typedArg := arg .(type ) {
141
+ case time.Time :
142
+ formattedArgs = append (formattedArgs , typedArg .Format ("2006-01-02 15:04:05.0000000" ))
143
+ default :
144
+ formattedArgs = append (formattedArgs , arg )
145
+ }
146
+ }
147
+ return
148
+ }
149
+
137
150
func (d * SqlDbConnection ) Insert (primaryKeyColumnName string , query string , args ... any ) (int , error ) {
138
151
var insertId int64
139
152
153
+ formattedArgs := formatArgs (args )
154
+
140
155
switch d .sql .Dialect .(type ) {
141
156
case gorp.PostgresDialect :
142
157
var err error
143
158
if primaryKeyColumnName != "" {
144
159
query += " returning " + primaryKeyColumnName
145
- err = d .sql .QueryRow (d .PrepareQuery (query ), args ... ).Scan (& insertId )
160
+ err = d .sql .QueryRow (d .PrepareQuery (query ), formattedArgs ... ).Scan (& insertId )
146
161
} else {
147
- _ , err = d .sql .Exec (d .PrepareQuery (query ), args ... )
162
+ _ , err = d .sql .Exec (d .PrepareQuery (query ), formattedArgs ... )
148
163
}
149
164
150
165
if err != nil {
151
166
return 0 , err
152
167
}
153
168
default :
154
- res , err := d .sql .Exec (d .PrepareQuery (query ), args ... )
169
+ res , err := d .sql .Exec (d .PrepareQuery (query ), formattedArgs ... )
155
170
if err != nil {
156
171
return 0 , err
157
172
}
@@ -364,8 +379,7 @@ func (d *SqlDb) insert(primaryKeyColumnName string, query string, args ...any) (
364
379
}
365
380
366
381
func (d * SqlDb ) exec (query string , args ... any ) (sql.Result , error ) {
367
- q := d .PrepareQuery (query )
368
- return d .Sql ().Exec (q , args ... )
382
+ return d .connection .Exec (query , args ... )
369
383
}
370
384
371
385
func (d * SqlDb ) execTx (tx * gorp.Transaction , query string , args ... any ) (sql.Result , error ) {
@@ -384,8 +398,7 @@ func (d *SqlDb) selectOne(holder any, query string, args ...any) error {
384
398
}
385
399
386
400
func (d * SqlDb ) selectAll (i any , query string , args ... any ) ([]any , error ) {
387
- q := d .PrepareQuery (query )
388
- return d .Sql ().Select (i , q , args ... )
401
+ return d .connection .SelectAll (i , query , args ... )
389
402
}
390
403
391
404
func connect () (* sql.DB , error ) {
0 commit comments