mirror of
https://github.com/lightninglabs/lightning-terminal.git
synced 2026-08-13 12:33:36 +02:00
Here, we manually define some queries for the actions store. We do this so that we can manually build the "SELECT" and only add "WHERE" clauses that are actually needed for the query and hence ensure that available indexes are used.
66 lines
1.7 KiB
Go
66 lines
1.7 KiB
Go
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
|
|
)
|
|
|
|
// wrappedTX is a wrapper around a DBTX that also stores the database backend
|
|
// type.
|
|
type wrappedTX struct {
|
|
DBTX
|
|
|
|
backendType BackendType
|
|
}
|
|
|
|
// Backend returns the type of database backend we're using.
|
|
func (q *Queries) Backend() 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 wtx.backendType
|
|
}
|
|
|
|
// NewSqlite creates a new Queries instance for a SQLite database.
|
|
func NewSqlite(db DBTX) *Queries {
|
|
return &Queries{db: &wrappedTX{db, BackendTypeSqlite}}
|
|
}
|
|
|
|
// NewPostgres creates a new Queries instance for a Postgres database.
|
|
func NewPostgres(db DBTX) *Queries {
|
|
return &Queries{db: &wrappedTX{db, BackendTypePostgres}}
|
|
}
|
|
|
|
// 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() BackendType
|
|
}
|