lightning-terminal/db/sqlcmig6/db_custom.go
Viktor Torstensson 9442c58cc1
sqlcmig6: add CustomQueries to Queries
In order to be able to use the custom queries with the
`sqlcmig6.Queries`, we assert at compile time that `sqlcmig6.Queries`
implements the `CustomQueries` interface.
2026-05-14 11:37:59 +02:00

50 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
}
var _ CustomQueries = (*Queries)(nil)