Skip to content

Commit 9cbc1f8

Browse files
committed
multi: use sqldb.NoOpReset helper
Define a re-usable "reset" function, sqldb.NoOpReset, that can be used for the reset parameter in sql ExecTx calls.
1 parent c4e6f23 commit 9cbc1f8

File tree

5 files changed

+19
-15
lines changed

5 files changed

+19
-15
lines changed

graph/db/sql_store.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ func (s *SQLStore) FetchLightningNode(pubKey route.Vertex) (
177177
_, node, err = getNodeByPubKey(ctx, db, pubKey)
178178

179179
return err
180-
}, func() {})
180+
}, sqldb.NoOpReset)
181181
if err != nil {
182182
return nil, fmt.Errorf("unable to fetch node: %w", err)
183183
}
@@ -221,7 +221,7 @@ func (s *SQLStore) HasLightningNode(pubKey [33]byte) (time.Time, bool,
221221
}
222222

223223
return nil
224-
}, func() {})
224+
}, sqldb.NoOpReset)
225225
if err != nil {
226226
return time.Time{}, false,
227227
fmt.Errorf("unable to fetch node: %w", err)
@@ -255,7 +255,7 @@ func (s *SQLStore) AddrsForNode(nodePub *btcec.PublicKey) (bool, []net.Addr,
255255
}
256256

257257
return nil
258-
}, func() {})
258+
}, sqldb.NoOpReset)
259259
if err != nil {
260260
return false, nil, fmt.Errorf("unable to get addresses for "+
261261
"node(%x): %w", nodePub.SerializeCompressed(), err)
@@ -294,7 +294,7 @@ func (s *SQLStore) DeleteLightningNode(pubKey route.Vertex) error {
294294
}
295295

296296
return err
297-
}, func() {})
297+
}, sqldb.NoOpReset)
298298
if err != nil {
299299
return fmt.Errorf("unable to delete node: %w", err)
300300
}
@@ -342,7 +342,7 @@ func (s *SQLStore) LookupAlias(pub *btcec.PublicKey) (string, error) {
342342
alias = dbNode.Alias.String
343343

344344
return nil
345-
}, func() {})
345+
}, sqldb.NoOpReset)
346346
if err != nil {
347347
return "", fmt.Errorf("unable to look up alias: %w", err)
348348
}
@@ -370,7 +370,7 @@ func (s *SQLStore) SourceNode() (*models.LightningNode, error) {
370370
_, node, err = getNodeByPubKey(ctx, db, nodePub)
371371

372372
return err
373-
}, func() {})
373+
}, sqldb.NoOpReset)
374374
if err != nil {
375375
return nil, fmt.Errorf("unable to fetch source node: %w", err)
376376
}
@@ -410,7 +410,7 @@ func (s *SQLStore) SetSourceNode(node *models.LightningNode) error {
410410
}
411411

412412
return db.AddSourceNode(ctx, id)
413-
}, func() {})
413+
}, sqldb.NoOpReset)
414414
}
415415

416416
// NodeUpdatesInHorizon returns all the known lightning node which have an
@@ -447,7 +447,7 @@ func (s *SQLStore) NodeUpdatesInHorizon(startTime,
447447
}
448448

449449
return nil
450-
}, func() {})
450+
}, sqldb.NoOpReset)
451451
if err != nil {
452452
return nil, fmt.Errorf("unable to fetch nodes: %w", err)
453453
}

invoices/kv_sql_migration_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ func TestMigrationWithChannelDB(t *testing.T) {
7676
ctxb, kvStore.Backend, kvStore, tx,
7777
batchSize,
7878
)
79-
}, func() {},
79+
}, sqldb.NoOpReset,
8080
)
8181
require.NoError(t, err)
8282

invoices/sql_migration_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ func testMigrateSingleInvoiceRapid(t *rapid.T, store *SQLStore, mpp bool,
325325
}
326326

327327
return nil
328-
}, func() {})
328+
}, sqldb.NoOpReset)
329329
require.NoError(t, err)
330330

331331
// Fetch and compare each migrated invoice from the store with the

invoices/sql_store.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ func (i *SQLStore) AddInvoice(ctx context.Context,
322322
AddedAt: newInvoice.CreationDate.UTC(),
323323
InvoiceID: invoiceID,
324324
})
325-
}, func() {})
325+
}, sqldb.NoOpReset)
326326
if err != nil {
327327
mappedSQLErr := sqldb.MapSQLError(err)
328328
var uniqueConstraintErr *sqldb.ErrSQLUniqueConstraintViolation
@@ -702,7 +702,7 @@ func (i *SQLStore) LookupInvoice(ctx context.Context,
702702
invoice, err = fetchInvoice(ctx, db, ref)
703703

704704
return err
705-
}, func() {})
705+
}, sqldb.NoOpReset)
706706
if txErr != nil {
707707
return Invoice{}, txErr
708708
}
@@ -1488,7 +1488,7 @@ func (i *SQLStore) UpdateInvoice(ctx context.Context, ref InvoiceRef,
14881488
)
14891489

14901490
return err
1491-
}, func() {})
1491+
}, sqldb.NoOpReset)
14921492
if txErr != nil {
14931493
// If the invoice is already settled, we'll return the
14941494
// (unchanged) invoice and the ErrInvoiceAlreadySettled error.
@@ -1552,7 +1552,7 @@ func (i *SQLStore) DeleteInvoice(ctx context.Context,
15521552
}
15531553

15541554
return nil
1555-
}, func() {})
1555+
}, sqldb.NoOpReset)
15561556

15571557
if err != nil {
15581558
return fmt.Errorf("unable to delete invoices: %w", err)
@@ -1572,7 +1572,7 @@ func (i *SQLStore) DeleteCanceledInvoices(ctx context.Context) error {
15721572
}
15731573

15741574
return nil
1575-
}, func() {})
1575+
}, sqldb.NoOpReset)
15761576
if err != nil {
15771577
return fmt.Errorf("unable to delete invoices: %w", err)
15781578
}

sqldb/sqlutils.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ import (
77
"golang.org/x/exp/constraints"
88
)
99

10+
// NoOpReset is a no-op function that can be used as a default
11+
// reset function ExecTx calls.
12+
var NoOpReset = func() {}
13+
1014
// SQLInt32 turns a numerical integer type into the NullInt32 that sql/sqlc
1115
// uses when an integer field can be permitted to be NULL.
1216
//

0 commit comments

Comments
 (0)