@@ -255,21 +255,14 @@ func (db *relationalDb) FindInTable(ctx context.Context, tableName string, recor
255
255
}()
256
256
257
257
if softDelete {
258
- if err = tx .Unscoped ().Table (tableName ).Where (record ).First (record ).Error ; err != nil {
259
- if errors .Is (err , gorm .ErrRecordNotFound ) {
260
- return ErrRecordNotFound .Wrap (err ).WithValue ("record" , fmt .Sprintf ("%+v" , record )).WithValue (DB_NAME , db .dbName )
261
- }
262
- db .logger .Debug (err )
263
- return ErrExecutingSqlStmt .Wrap (err ).WithValue (DB_NAME , db .dbName )
264
- }
265
- } else {
266
- if err = tx .Table (tableName ).Where (record ).First (record ).Error ; err != nil {
267
- if errors .Is (err , gorm .ErrRecordNotFound ) {
268
- return ErrRecordNotFound .Wrap (err ).WithValue ("record" , fmt .Sprintf ("%+v" , record )).WithValue (DB_NAME , db .dbName )
269
- }
270
- db .logger .Debug (err )
271
- return ErrExecutingSqlStmt .Wrap (err ).WithValue (DB_NAME , db .dbName )
258
+ tx = tx .Unscoped ()
259
+ }
260
+ if err = tx .Table (tableName ).Where (record ).First (record ).Error ; err != nil {
261
+ if errors .Is (err , gorm .ErrRecordNotFound ) {
262
+ return ErrRecordNotFound .Wrap (err ).WithValue ("record" , fmt .Sprintf ("%+v" , record )).WithValue (DB_NAME , db .dbName )
272
263
}
264
+ db .logger .Debug (err )
265
+ return ErrExecutingSqlStmt .Wrap (err ).WithValue (DB_NAME , db .dbName )
273
266
}
274
267
return db .commitWhenTxNotInsideCtx (ctx , tx )
275
268
}
@@ -320,15 +313,11 @@ func (db *relationalDb) FindWithFilterInTable(ctx context.Context, tableName str
320
313
}
321
314
322
315
if softDelete {
323
- if err = tx .Unscoped ().Table (tableName ).Where (record ).Error ; err != nil {
324
- db .logger .Debug (err )
325
- return ErrExecutingSqlStmt .Wrap (err ).WithValue (DB_NAME , db .dbName )
326
- }
327
- } else {
328
- if err = tx .Table (tableName ).Where (record ).Error ; err != nil {
329
- db .logger .Debug (err )
330
- return ErrExecutingSqlStmt .Wrap (err ).WithValue (DB_NAME , db .dbName )
331
- }
316
+ tx = tx .Unscoped ()
317
+ }
318
+ if err = tx .Table (tableName ).Where (record ).Error ; err != nil {
319
+ db .logger .Debug (err )
320
+ return ErrExecutingSqlStmt .Wrap (err ).WithValue (DB_NAME , db .dbName )
332
321
}
333
322
334
323
if pagination != nil {
@@ -338,16 +327,9 @@ func (db *relationalDb) FindWithFilterInTable(ctx context.Context, tableName str
338
327
}
339
328
}
340
329
341
- if softDelete {
342
- if err = tx .Unscoped ().Find (records ).Error ; err != nil {
343
- db .logger .Debug (err )
344
- return ErrExecutingSqlStmt .Wrap (err ).WithValue (DB_NAME , db .dbName )
345
- }
346
- } else {
347
- if err = tx .Find (records ).Error ; err != nil {
348
- db .logger .Debug (err )
349
- return ErrExecutingSqlStmt .Wrap (err ).WithValue (DB_NAME , db .dbName )
350
- }
330
+ if err = tx .Find (records ).Error ; err != nil {
331
+ db .logger .Debug (err )
332
+ return ErrExecutingSqlStmt .Wrap (err ).WithValue (DB_NAME , db .dbName )
351
333
}
352
334
353
335
return db .commitWhenTxNotInsideCtx (ctx , tx )
@@ -426,16 +408,12 @@ func (db *relationalDb) delete(ctx context.Context, tableName string, record Rec
426
408
}
427
409
}()
428
410
429
- if softDelete {
430
- if err = tx .Delete (record ).Error ; err != nil {
431
- db .logger .Debug (err )
432
- return 0 , ErrExecutingSqlStmt .Wrap (err ).WithValue (DB_NAME , db .dbName )
433
- }
434
- } else {
435
- if err = tx .Unscoped ().Delete (record ).Error ; err != nil {
436
- db .logger .Debug (err )
437
- return 0 , ErrExecutingSqlStmt .Wrap (err ).WithValue (DB_NAME , db .dbName )
438
- }
411
+ if ! softDelete {
412
+ tx = tx .Unscoped ()
413
+ }
414
+ if err = tx .Delete (record ).Error ; err != nil {
415
+ db .logger .Debug (err )
416
+ return 0 , ErrExecutingSqlStmt .Wrap (err ).WithValue (DB_NAME , db .dbName )
439
417
}
440
418
err = db .commitWhenTxNotInsideCtx (ctx , tx )
441
419
if err != nil {
0 commit comments