Documentation ¶
Index ¶
- type BaseQuerier
- func (d *BaseQuerier[T]) Exec(ctx context.Context, query litsql.Query, params any) (pgconn.CommandTag, error)
- func (d *BaseQuerier[T]) Handler() T
- func (d *BaseQuerier[T]) Prepare(ctx context.Context, name string, query litsql.Query) (*Stmt[T], error)
- func (d *BaseQuerier[T]) Query(ctx context.Context, query litsql.Query, params any) (pgx.Rows, error)
- func (d *BaseQuerier[T]) QueryRow(ctx context.Context, query litsql.Query, params any) (pgx.Row, error)
- type DB
- type DBT
- type Option
- type PGXQuerier
- type PGXQuerierDB
- type PGXQuerierTx
- type QuerierDB
- type QuerierDBT
- type QuerierStmt
- type QuerierStmtT
- type QuerierT
- type QuerierTx
- type QuerierTxT
- type Stmt
- type Tx
- type TxT
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BaseQuerier ¶
type BaseQuerier[T PGXQuerier] struct { // contains filtered or unexported fields }
func NewBaseQuerier ¶
func NewBaseQuerier[T PGXQuerier](querier T, options ...Option) *BaseQuerier[T]
func (*BaseQuerier[T]) Exec ¶
func (d *BaseQuerier[T]) Exec(ctx context.Context, query litsql.Query, params any) (pgconn.CommandTag, error)
func (*BaseQuerier[T]) Handler ¶
func (d *BaseQuerier[T]) Handler() T
type DB ¶
type DB = DBT[*pgx.Conn]
Example ¶
ctx := context.Background() conn, err := pgx.Connect(ctx, "test") if err != nil { panic(err) } // wrap *pgx.Conn instance ddb := lpgx.NewDB(conn) query := psql.Select( sm.Columns("film_id", "title", "length"), sm.From("film"), sm.WhereClause("length > ?", sq.NamedArg("length")), sm.Limit(10), ) // generate SQL string from litsql and execute it, replacing named parameters. rows, err := ddb.Query(ctx, query, map[string]any{ "length": 90, }) if err != nil { panic(err) } defer rows.Close() for rows.Next() { var film_id, length int var title string err = rows.Scan(&film_id, &title, &length) if err != nil { panic(err) } } if rows.Err() != nil { panic(err) }
Output:
type DBT ¶
type DBT[T PGXQuerierDB] struct { *BaseQuerier[T] }
func NewDBT ¶
func NewDBT[T PGXQuerierDB](querier T, options ...Option) *DBT[T]
type PGXQuerier ¶
type PGXQuerier interface { Query(ctx context.Context, sql string, args ...any) (pgx.Rows, error) QueryRow(ctx context.Context, sql string, args ...any) pgx.Row Exec(ctx context.Context, sql string, args ...any) (commandTag pgconn.CommandTag, err error) Prepare(ctx context.Context, name, sql string) (sd *pgconn.StatementDescription, err error) }
PGXQuerier is something that lpgx can query and get the pgx.Rows from. For example, it can be: pgx.Conn or pgx.Tx.
type PGXQuerierDB ¶
type PGXQuerierDB interface { PGXQuerier BeginTx(ctx context.Context, txOptions pgx.TxOptions) (pgx.Tx, error) }
type PGXQuerierTx ¶
type QuerierDB ¶
type QuerierDB = QuerierDBT[*pgx.Conn, pgx.Tx]
type QuerierDBT ¶
type QuerierDBT[ST PGXQuerier, TT PGXQuerierTx] interface { QuerierT[ST] BeginTx(ctx context.Context, opts pgx.TxOptions) (*TxT[TT], error) }
type QuerierStmt ¶
type QuerierStmt = QuerierStmtT
type QuerierStmtT ¶
type QuerierT ¶
type QuerierT[ST PGXQuerier] interface { Query(ctx context.Context, query litsql.Query, params any) (pgx.Rows, error) QueryRow(ctx context.Context, query litsql.Query, params any) (pgx.Row, error) Exec(ctx context.Context, query litsql.Query, params any) (pgconn.CommandTag, error) Prepare(ctx context.Context, name string, query litsql.Query) (*Stmt[ST], error) }
type QuerierTx ¶
type QuerierTx = QuerierTxT[pgx.Tx]
type QuerierTxT ¶
type Stmt ¶
type Stmt[T PGXQuerier] struct { // contains filtered or unexported fields }
Example ¶
ctx := context.Background() conn, err := pgx.Connect(ctx, "test") if err != nil { panic(err) } // wrap *pgx.Conn instance ddb := lpgx.NewDB(conn) query := psql.Select( sm.Columns("film_id", "title", "length"), sm.From("film"), sm.WhereClause("length > ?", sq.NamedArg("length")), sm.Limit(10), ) queryName := "query1" // generate SQL string from litsql and prepare it, storing the named parameters to be replaced later dstmt, err := ddb.Prepare(ctx, queryName, query) if err != nil { panic(err) } // execute prepared query, replacing named parameters rows, err := dstmt.Query(ctx, map[string]any{ "length": 90, }) if err != nil { panic(err) } defer rows.Close() for rows.Next() { var film_id, length int var title string err = rows.Scan(&film_id, &title, &length) if err != nil { panic(err) } } if rows.Err() != nil { panic(err) }
Output:
func NewStmt ¶
func NewStmt[T PGXQuerier](querier T, desc *pgconn.StatementDescription, args []any, options ...Option) *Stmt[T]
func (*Stmt[T]) Handler ¶
func (d *Stmt[T]) Handler() PGXQuerier
type TxT ¶
type TxT[T PGXQuerierTx] struct { *BaseQuerier[T] }
func NewTxT ¶
func NewTxT[T PGXQuerierTx](querier T, options ...Option) *TxT[T]
Source Files ¶
Click to show internal directories.
Click to hide internal directories.