mirror of
https://github.com/lightninglabs/lightning-terminal.git
synced 2026-08-13 12:33:36 +02:00
This commit introduces the `sqlcmig6` package, which at the time of this commit contains the same queries and models as `sqlc` package. Importantly though, once the kvdb to sql migration is made available in production, the `sqlcmig6` package will not change, as it is intended to represent the sql db as it was at the time of the migration. The sqlcmig6 package is therefore intended to be used in the kvdb to sql migration code, as it is will always be compatible with the sql database when all sql migrations prior to the kvdb to sql migration are applied. When additional sql migrations are added in the future, they may effect the `sqlc` package in such a way that the standard `sqlc` queries and models aren't compatible with kvdb to sql migration code any longer. By preserving the `sqlcmig6` package, we ensure that the kvdb to sql migration code can always use the same queries and models that were available at the time of the migration, even if the `sqlc` package changes in the future. Note that the `sqlcmig6` package have not been generated by `sqlc` (the queries and models are copied from the `sqlc` package), as it is not intended to be changed in the future.
48 lines
1.3 KiB
Go
48 lines
1.3 KiB
Go
package sqlcmig6
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/lightningnetwork/lnd/sqldb/v2"
|
|
)
|
|
|
|
// wrappedTX is a wrapper around a DBTX that also stores the database backend
|
|
// type.
|
|
type wrappedTX struct {
|
|
DBTX
|
|
|
|
backendType sqldb.BackendType
|
|
}
|
|
|
|
// Backend returns the type of database backend we're using.
|
|
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 sqldb.BackendTypeUnknown
|
|
}
|
|
|
|
return wtx.backendType
|
|
}
|
|
|
|
// NewForType creates a new Queries instance for the given database type.
|
|
func NewForType(db DBTX, typ sqldb.BackendType) *Queries {
|
|
return &Queries{db: &wrappedTX{db, typ}}
|
|
}
|
|
|
|
// CustomQueries defines a set of custom queries that we define in addition
|
|
// to the ones generated by sqlc.
|
|
type CustomQueries interface {
|
|
// CountActions returns the number of actions that match the provided
|
|
// ActionQueryParams.
|
|
CountActions(ctx context.Context, arg ActionQueryParams) (int64, error)
|
|
|
|
// ListActions retrieves a list of actions based on the provided
|
|
// ListActionsParams.
|
|
ListActions(ctx context.Context,
|
|
arg ListActionsParams) ([]Action, error)
|
|
|
|
// Backend returns the type of the database backend used.
|
|
Backend() sqldb.BackendType
|
|
}
|