Skip to content

Commit 14e39b6

Browse files
firewalldb: add SQLMig6Queries to firewalldb
Add the `sqlcmig6` defintion of the the firewalldb queries to the firewalldb 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 c30aaee commit 14e39b6

File tree

4 files changed

+93
-0
lines changed

4 files changed

+93
-0
lines changed

firewalldb/actions_sql.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"github.com/lightninglabs/lightning-terminal/accounts"
1111
"github.com/lightninglabs/lightning-terminal/db"
1212
"github.com/lightninglabs/lightning-terminal/db/sqlc"
13+
"github.com/lightninglabs/lightning-terminal/db/sqlcmig6"
1314
"github.com/lightninglabs/lightning-terminal/session"
1415
"github.com/lightningnetwork/lnd/fn"
1516
"github.com/lightningnetwork/lnd/sqldb/v2"
@@ -22,6 +23,13 @@ type SQLAccountQueries interface {
2223
GetAccountIDByAlias(ctx context.Context, alias int64) (int64, error)
2324
}
2425

26+
// SQLMig6AccountQueries is a subset of the sqlcmig6.Queries interface that can
27+
// be used to interact with the accounts table.
28+
type SQLMig6AccountQueries interface {
29+
GetAccount(ctx context.Context, id int64) (sqlcmig6.Account, error)
30+
GetAccountIDByAlias(ctx context.Context, alias int64) (int64, error)
31+
}
32+
2533
// SQLActionQueries is a subset of the sqlc.Queries interface that can be used
2634
// to interact with action related tables.
2735
//
@@ -36,6 +44,20 @@ type SQLActionQueries interface {
3644
CountActions(ctx context.Context, arg sqlc.ActionQueryParams) (int64, error)
3745
}
3846

47+
// SQLMig6ActionQueries is a subset of the sqlcmig6.Queries interface that can
48+
// be used to interact with action related tables.
49+
//
50+
//nolint:lll
51+
type SQLMig6ActionQueries interface {
52+
SQLSessionQueries
53+
SQLMig6AccountQueries
54+
55+
InsertAction(ctx context.Context, arg sqlcmig6.InsertActionParams) (int64, error)
56+
SetActionState(ctx context.Context, arg sqlcmig6.SetActionStateParams) error
57+
ListActions(ctx context.Context, arg sqlcmig6.ListActionsParams) ([]sqlcmig6.Action, error)
58+
CountActions(ctx context.Context, arg sqlcmig6.ActionQueryParams) (int64, error)
59+
}
60+
3961
// sqlActionLocator helps us find an action in the SQL DB.
4062
type sqlActionLocator struct {
4163
// id is the DB level ID of the action.

firewalldb/kvstores_sql.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99

1010
"github.com/lightninglabs/lightning-terminal/db"
1111
"github.com/lightninglabs/lightning-terminal/db/sqlc"
12+
"github.com/lightninglabs/lightning-terminal/db/sqlcmig6"
1213
"github.com/lightninglabs/lightning-terminal/session"
1314
"github.com/lightningnetwork/lnd/fn"
1415
"github.com/lightningnetwork/lnd/sqldb/v2"
@@ -39,6 +40,31 @@ type SQLKVStoreQueries interface {
3940
GetRuleID(ctx context.Context, name string) (int64, error)
4041
}
4142

43+
// SQLMig6KVStoreQueries is a subset of the sqlcmig6.Queries interface that can
44+
// be used to interact with the kvstore tables.
45+
//
46+
//nolint:lll
47+
type SQLMig6KVStoreQueries interface {
48+
SQLSessionQueries
49+
50+
DeleteFeatureKVStoreRecord(ctx context.Context, arg sqlcmig6.DeleteFeatureKVStoreRecordParams) error
51+
DeleteGlobalKVStoreRecord(ctx context.Context, arg sqlcmig6.DeleteGlobalKVStoreRecordParams) error
52+
DeleteGroupKVStoreRecord(ctx context.Context, arg sqlcmig6.DeleteGroupKVStoreRecordParams) error
53+
GetFeatureKVStoreRecord(ctx context.Context, arg sqlcmig6.GetFeatureKVStoreRecordParams) ([]byte, error)
54+
GetGlobalKVStoreRecord(ctx context.Context, arg sqlcmig6.GetGlobalKVStoreRecordParams) ([]byte, error)
55+
GetGroupKVStoreRecord(ctx context.Context, arg sqlcmig6.GetGroupKVStoreRecordParams) ([]byte, error)
56+
UpdateFeatureKVStoreRecord(ctx context.Context, arg sqlcmig6.UpdateFeatureKVStoreRecordParams) error
57+
UpdateGlobalKVStoreRecord(ctx context.Context, arg sqlcmig6.UpdateGlobalKVStoreRecordParams) error
58+
UpdateGroupKVStoreRecord(ctx context.Context, arg sqlcmig6.UpdateGroupKVStoreRecordParams) error
59+
InsertKVStoreRecord(ctx context.Context, arg sqlcmig6.InsertKVStoreRecordParams) error
60+
ListAllKVStoresRecords(ctx context.Context) ([]sqlcmig6.Kvstore, error)
61+
DeleteAllTempKVStores(ctx context.Context) error
62+
GetOrInsertFeatureID(ctx context.Context, name string) (int64, error)
63+
GetOrInsertRuleID(ctx context.Context, name string) (int64, error)
64+
GetFeatureID(ctx context.Context, name string) (int64, error)
65+
GetRuleID(ctx context.Context, name string) (int64, error)
66+
}
67+
4268
// DeleteTempKVStores deletes all temporary kv stores.
4369
//
4470
// NOTE: part of the RulesDB interface.

firewalldb/privacy_mapper_sql.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"errors"
77

88
"github.com/lightninglabs/lightning-terminal/db/sqlc"
9+
"github.com/lightninglabs/lightning-terminal/db/sqlcmig6"
910
"github.com/lightninglabs/lightning-terminal/session"
1011
)
1112

@@ -22,6 +23,19 @@ type SQLPrivacyPairQueries interface {
2223
GetRealForPseudo(ctx context.Context, arg sqlc.GetRealForPseudoParams) (string, error)
2324
}
2425

26+
// SQLMig6PrivacyPairQueries is a subset of the sqlcmig6.Queries interface that
27+
// can be used to interact with the privacy map table.
28+
//
29+
//nolint:lll
30+
type SQLMig6PrivacyPairQueries interface {
31+
SQLSessionQueries
32+
33+
InsertPrivacyPair(ctx context.Context, arg sqlcmig6.InsertPrivacyPairParams) error
34+
GetAllPrivacyPairs(ctx context.Context, groupID int64) ([]sqlcmig6.GetAllPrivacyPairsRow, error)
35+
GetPseudoForReal(ctx context.Context, arg sqlcmig6.GetPseudoForRealParams) (string, error)
36+
GetRealForPseudo(ctx context.Context, arg sqlcmig6.GetRealForPseudoParams) (string, error)
37+
}
38+
2539
// PrivacyDB constructs a PrivacyMapDB that will be indexed under the given
2640
// group ID key.
2741
//

firewalldb/sql_store.go

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

77
"github.com/lightninglabs/lightning-terminal/db"
88
"github.com/lightninglabs/lightning-terminal/db/sqlc"
9+
"github.com/lightninglabs/lightning-terminal/db/sqlcmig6"
910
"github.com/lightningnetwork/lnd/clock"
1011
"github.com/lightningnetwork/lnd/sqldb/v2"
1112
)
@@ -27,6 +28,16 @@ type SQLQueries interface {
2728
SQLActionQueries
2829
}
2930

31+
// SQLMig6Queries is a subset of the sqlcmig6.Queries interface that can be used
32+
// to interact with various firewalldb tables.
33+
type SQLMig6Queries interface {
34+
sqldb.BaseQuerier
35+
36+
SQLMig6KVStoreQueries
37+
SQLMig6PrivacyPairQueries
38+
SQLMig6ActionQueries
39+
}
40+
3041
// BatchedSQLQueries combines the SQLQueries interface with the BatchedTx
3142
// interface, allowing for multiple queries to be executed in single SQL
3243
// transaction.
@@ -68,6 +79,26 @@ func NewSQLQueriesExecutor(baseDB *sqldb.BaseDB,
6879
}
6980
}
7081

82+
type SQLMig6QueriesExecutor[T sqldb.BaseQuerier] struct {
83+
*sqldb.TransactionExecutor[T]
84+
85+
SQLMig6Queries
86+
}
87+
88+
func NewSQLMig6QueriesExecutor(baseDB *sqldb.BaseDB,
89+
queries *sqlcmig6.Queries) *SQLMig6QueriesExecutor[SQLMig6Queries] {
90+
91+
executor := sqldb.NewTransactionExecutor(
92+
baseDB, func(tx *sql.Tx) SQLMig6Queries {
93+
return queries.WithTx(tx)
94+
},
95+
)
96+
return &SQLMig6QueriesExecutor[SQLMig6Queries]{
97+
TransactionExecutor: executor,
98+
SQLMig6Queries: queries,
99+
}
100+
}
101+
71102
// A compile-time assertion to ensure that SQLDB implements the RulesDB
72103
// interface.
73104
var _ RulesDB = (*SQLDB)(nil)

0 commit comments

Comments
 (0)