Skip to content

Commit a94a892

Browse files
committed
accounts: add SQLMig6Queries to accounts
Add the `sqlcmig6` defintion of the the accounts queries to the accounts package, along with a transaction executor that uses those queries. Note that while the standard Queiries interface, that use the standard sqlc queries, may change, the `SQLMig6Queries` interface is intended to remain the same.
1 parent 0347e2d commit a94a892

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

accounts/store_sql.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111

1212
"github.com/lightninglabs/lightning-terminal/db"
1313
"github.com/lightninglabs/lightning-terminal/db/sqlc"
14+
"github.com/lightninglabs/lightning-terminal/db/sqlcmig6"
1415
"github.com/lightningnetwork/lnd/clock"
1516
"github.com/lightningnetwork/lnd/fn"
1617
"github.com/lightningnetwork/lnd/lnrpc"
@@ -56,6 +57,33 @@ type SQLQueries interface {
5657
GetAccountInvoice(ctx context.Context, arg sqlc.GetAccountInvoiceParams) (sqlc.AccountInvoice, error)
5758
}
5859

60+
// SQLMig6Queries is a subset of the sqlcmig6.Queries interface that can be used
61+
// to interact with accounts related tables.
62+
//
63+
//nolint:lll
64+
type SQLMig6Queries interface {
65+
sqldb.BaseQuerier
66+
67+
AddAccountInvoice(ctx context.Context, arg sqlcmig6.AddAccountInvoiceParams) error
68+
DeleteAccount(ctx context.Context, id int64) error
69+
DeleteAccountPayment(ctx context.Context, arg sqlcmig6.DeleteAccountPaymentParams) error
70+
GetAccount(ctx context.Context, id int64) (sqlcmig6.Account, error)
71+
GetAccountByLabel(ctx context.Context, label sql.NullString) (sqlcmig6.Account, error)
72+
GetAccountIDByAlias(ctx context.Context, alias int64) (int64, error)
73+
GetAccountIndex(ctx context.Context, name string) (int64, error)
74+
GetAccountPayment(ctx context.Context, arg sqlcmig6.GetAccountPaymentParams) (sqlcmig6.AccountPayment, error)
75+
InsertAccount(ctx context.Context, arg sqlcmig6.InsertAccountParams) (int64, error)
76+
ListAccountInvoices(ctx context.Context, id int64) ([]sqlcmig6.AccountInvoice, error)
77+
ListAccountPayments(ctx context.Context, id int64) ([]sqlcmig6.AccountPayment, error)
78+
ListAllAccounts(ctx context.Context) ([]sqlcmig6.Account, error)
79+
SetAccountIndex(ctx context.Context, arg sqlcmig6.SetAccountIndexParams) error
80+
UpdateAccountBalance(ctx context.Context, arg sqlcmig6.UpdateAccountBalanceParams) (int64, error)
81+
UpdateAccountExpiry(ctx context.Context, arg sqlcmig6.UpdateAccountExpiryParams) (int64, error)
82+
UpdateAccountLastUpdate(ctx context.Context, arg sqlcmig6.UpdateAccountLastUpdateParams) (int64, error)
83+
UpsertAccountPayment(ctx context.Context, arg sqlcmig6.UpsertAccountPaymentParams) error
84+
GetAccountInvoice(ctx context.Context, arg sqlcmig6.GetAccountInvoiceParams) (sqlcmig6.AccountInvoice, error)
85+
}
86+
5987
// BatchedSQLQueries combines the SQLQueries interface with the BatchedTx
6088
// interface, allowing for multiple queries to be executed in single SQL
6189
// transaction.
@@ -97,6 +125,26 @@ func NewSQLQueriesExecutor(baseDB *sqldb.BaseDB,
97125
}
98126
}
99127

128+
type SQLMig6QueriesExecutor[T sqldb.BaseQuerier] struct {
129+
*sqldb.TransactionExecutor[T]
130+
131+
SQLMig6Queries
132+
}
133+
134+
func NewSQLMig6QueriesExecutor(baseDB *sqldb.BaseDB,
135+
queries *sqlcmig6.Queries) *SQLMig6QueriesExecutor[SQLMig6Queries] {
136+
137+
executor := sqldb.NewTransactionExecutor(
138+
baseDB, func(tx *sql.Tx) SQLMig6Queries {
139+
return queries.WithTx(tx)
140+
},
141+
)
142+
return &SQLMig6QueriesExecutor[SQLMig6Queries]{
143+
TransactionExecutor: executor,
144+
SQLMig6Queries: queries,
145+
}
146+
}
147+
100148
// NewSQLStore creates a new SQLStore instance given an open BatchedSQLQueries
101149
// storage backend.
102150
func NewSQLStore(sqlDB *sqldb.BaseDB, queries *sqlc.Queries,

0 commit comments

Comments
 (0)