db+sqlc: use sqldb/v2 BackendType definition

The `sqldb/v2` package now provides a definition for the `BackendType`
type. As useage of `sqldb/v2` requires useage of that type, we update
`litd` to use the `BackendType` definition from `sqldb/v2`, instead of
it's own definition.
This commit is contained in:
Viktor Torstensson 2025-07-24 13:15:03 +02:00
parent ee4a1e338b
commit 91ed65954d
No known key found for this signature in database
GPG key ID: 961CC8259AE675D4
2 changed files with 11 additions and 23 deletions

View file

@ -8,6 +8,7 @@ import (
"time"
"github.com/lightninglabs/lightning-terminal/db/sqlc"
"github.com/lightningnetwork/lnd/sqldb/v2"
)
var (
@ -56,7 +57,7 @@ type BatchedTx[Q any] interface {
txBody func(Q) error) error
// Backend returns the type of the database backend used.
Backend() sqlc.BackendType
Backend() sqldb.BackendType
}
// Tx represents a database transaction that can be committed or rolled back.
@ -277,7 +278,7 @@ func (t *TransactionExecutor[Q]) ExecTx(ctx context.Context,
}
// Backend returns the type of the database backend used.
func (t *TransactionExecutor[Q]) Backend() sqlc.BackendType {
func (t *TransactionExecutor[Q]) Backend() sqldb.BackendType {
return t.BatchedQuerier.Backend()
}
@ -301,7 +302,7 @@ func (s *BaseDB) BeginTx(ctx context.Context, opts TxOptions) (*sql.Tx, error) {
}
// Backend returns the type of the database backend used.
func (s *BaseDB) Backend() sqlc.BackendType {
func (s *BaseDB) Backend() sqldb.BackendType {
return s.Queries.Backend()
}

View file

@ -2,21 +2,8 @@ package sqlc
import (
"context"
)
// BackendType is an enum that represents the type of database backend we're
// using.
type BackendType uint8
const (
// BackendTypeUnknown indicates we're using an unknown backend.
BackendTypeUnknown BackendType = iota
// BackendTypeSqlite indicates we're using a SQLite backend.
BackendTypeSqlite
// BackendTypePostgres indicates we're using a Postgres backend.
BackendTypePostgres
"github.com/lightningnetwork/lnd/sqldb/v2"
)
// wrappedTX is a wrapper around a DBTX that also stores the database backend
@ -24,16 +11,16 @@ const (
type wrappedTX struct {
DBTX
backendType BackendType
backendType sqldb.BackendType
}
// Backend returns the type of database backend we're using.
func (q *Queries) Backend() BackendType {
func (q *Queries) Backend() sqldb.BackendType {
wtx, ok := q.db.(*wrappedTX)
if !ok {
// Shouldn't happen unless a new database backend type is added
// but not initialized correctly.
return BackendTypeUnknown
return sqldb.BackendTypeUnknown
}
return wtx.backendType
@ -41,12 +28,12 @@ func (q *Queries) Backend() BackendType {
// NewSqlite creates a new Queries instance for a SQLite database.
func NewSqlite(db DBTX) *Queries {
return &Queries{db: &wrappedTX{db, BackendTypeSqlite}}
return &Queries{db: &wrappedTX{db, sqldb.BackendTypeSqlite}}
}
// NewPostgres creates a new Queries instance for a Postgres database.
func NewPostgres(db DBTX) *Queries {
return &Queries{db: &wrappedTX{db, BackendTypePostgres}}
return &Queries{db: &wrappedTX{db, sqldb.BackendTypePostgres}}
}
// CustomQueries defines a set of custom queries that we define in addition
@ -62,5 +49,5 @@ type CustomQueries interface {
arg ListActionsParams) ([]Action, error)
// Backend returns the type of the database backend used.
Backend() BackendType
Backend() sqldb.BackendType
}