postgres

package
v0.0.0-...-cc467f2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 1, 2023 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PrepareAllQueries

func PrepareAllQueries(ctx context.Context, p preparer) error

PrepareAllQueries executes a PREPARE statement for all pggen generated SQL queries in querier files. Typical usage is as the AfterConnect callback for pgxpool.Config

pgx will use the prepared statement if available. Calling PrepareAllQueries is an optional optimization to avoid a network round-trip the first time pgx runs a query if pgx statement caching is enabled.

Types

type Connection

type Connection genericConn

type DBQuerier

type DBQuerier struct {
	// contains filtered or unexported fields
}

func NewQuerier

func NewQuerier(conn genericConn) *DBQuerier

NewQuerier creates a DBQuerier that implements Querier. conn is typically *pgx.Conn, pgx.Tx, or *pgxpool.Pool.

func NewQuerierConfig

func NewQuerierConfig(conn genericConn, cfg QuerierConfig) *DBQuerier

NewQuerierConfig creates a DBQuerier that implements Querier with the given config. conn is typically *pgx.Conn, pgx.Tx, or *pgxpool.Pool.

func (*DBQuerier) GroupByID

func (q *DBQuerier) GroupByID(ctx context.Context, id int) (GroupByIDRow, error)

GroupByID implements Querier.GroupByID.

func (*DBQuerier) GroupByIDBatch

func (q *DBQuerier) GroupByIDBatch(batch genericBatch, id int)

GroupByIDBatch implements Querier.GroupByIDBatch.

func (*DBQuerier) GroupByIDScan

func (q *DBQuerier) GroupByIDScan(results pgx.BatchResults) (GroupByIDRow, error)

GroupByIDScan implements Querier.GroupByIDScan.

func (*DBQuerier) IDByGroup

func (q *DBQuerier) IDByGroup(ctx context.Context, params IDByGroupParams) (int, error)

IDByGroup implements Querier.IDByGroup.

func (*DBQuerier) IDByGroupBatch

func (q *DBQuerier) IDByGroupBatch(batch genericBatch, params IDByGroupParams)

IDByGroupBatch implements Querier.IDByGroupBatch.

func (*DBQuerier) IDByGroupScan

func (q *DBQuerier) IDByGroupScan(results pgx.BatchResults) (int, error)

IDByGroupScan implements Querier.IDByGroupScan.

func (*DBQuerier) SelectNumsForYearAndSpec

func (q *DBQuerier) SelectNumsForYearAndSpec(ctx context.Context, year int, spec pgtype.Text) ([]int, error)

SelectNumsForYearAndSpec implements Querier.SelectNumsForYearAndSpec.

func (*DBQuerier) SelectNumsForYearAndSpecBatch

func (q *DBQuerier) SelectNumsForYearAndSpecBatch(batch genericBatch, year int, spec pgtype.Text)

SelectNumsForYearAndSpecBatch implements Querier.SelectNumsForYearAndSpecBatch.

func (*DBQuerier) SelectNumsForYearAndSpecScan

func (q *DBQuerier) SelectNumsForYearAndSpecScan(results pgx.BatchResults) ([]int, error)

SelectNumsForYearAndSpecScan implements Querier.SelectNumsForYearAndSpecScan.

func (*DBQuerier) SelectSpecsForYear

func (q *DBQuerier) SelectSpecsForYear(ctx context.Context, year int) ([]pgtype.Text, error)

SelectSpecsForYear implements Querier.SelectSpecsForYear.

func (*DBQuerier) SelectSpecsForYearBatch

func (q *DBQuerier) SelectSpecsForYearBatch(batch genericBatch, year int)

SelectSpecsForYearBatch implements Querier.SelectSpecsForYearBatch.

func (*DBQuerier) SelectSpecsForYearScan

func (q *DBQuerier) SelectSpecsForYearScan(results pgx.BatchResults) ([]pgtype.Text, error)

SelectSpecsForYearScan implements Querier.SelectSpecsForYearScan.

func (*DBQuerier) SelectYears

func (q *DBQuerier) SelectYears(ctx context.Context) ([]int, error)

SelectYears implements Querier.SelectYears.

func (*DBQuerier) SelectYearsBatch

func (q *DBQuerier) SelectYearsBatch(batch genericBatch)

SelectYearsBatch implements Querier.SelectYearsBatch.

func (*DBQuerier) SelectYearsScan

func (q *DBQuerier) SelectYearsScan(results pgx.BatchResults) ([]int, error)

SelectYearsScan implements Querier.SelectYearsScan.

func (*DBQuerier) WithTx

func (q *DBQuerier) WithTx(tx pgx.Tx) (*DBQuerier, error)

WithTx creates a new DBQuerier that uses the transaction to run all queries.

type GroupByIDRow

type GroupByIDRow struct {
	Year int         `json:"year"`
	Spec pgtype.Text `json:"spec"`
	Num  int         `json:"num"`
}

type IDByGroupParams

type IDByGroupParams struct {
	Year int
	Spec pgtype.Text
	Num  int
}

type Querier

type Querier interface {
	GroupByID(ctx context.Context, id int) (GroupByIDRow, error)
	// GroupByIDBatch enqueues a GroupByID query into batch to be executed
	// later by the batch.
	GroupByIDBatch(batch genericBatch, id int)
	// GroupByIDScan scans the result of an executed GroupByIDBatch query.
	GroupByIDScan(results pgx.BatchResults) (GroupByIDRow, error)

	IDByGroup(ctx context.Context, params IDByGroupParams) (int, error)
	// IDByGroupBatch enqueues a IDByGroup query into batch to be executed
	// later by the batch.
	IDByGroupBatch(batch genericBatch, params IDByGroupParams)
	// IDByGroupScan scans the result of an executed IDByGroupBatch query.
	IDByGroupScan(results pgx.BatchResults) (int, error)

	SelectYears(ctx context.Context) ([]int, error)
	// SelectYearsBatch enqueues a SelectYears query into batch to be executed
	// later by the batch.
	SelectYearsBatch(batch genericBatch)
	// SelectYearsScan scans the result of an executed SelectYearsBatch query.
	SelectYearsScan(results pgx.BatchResults) ([]int, error)

	SelectSpecsForYear(ctx context.Context, year int) ([]pgtype.Text, error)
	// SelectSpecsForYearBatch enqueues a SelectSpecsForYear query into batch to be executed
	// later by the batch.
	SelectSpecsForYearBatch(batch genericBatch, year int)
	// SelectSpecsForYearScan scans the result of an executed SelectSpecsForYearBatch query.
	SelectSpecsForYearScan(results pgx.BatchResults) ([]pgtype.Text, error)

	SelectNumsForYearAndSpec(ctx context.Context, year int, spec pgtype.Text) ([]int, error)
	// SelectNumsForYearAndSpecBatch enqueues a SelectNumsForYearAndSpec query into batch to be executed
	// later by the batch.
	SelectNumsForYearAndSpecBatch(batch genericBatch, year int, spec pgtype.Text)
	// SelectNumsForYearAndSpecScan scans the result of an executed SelectNumsForYearAndSpecBatch query.
	SelectNumsForYearAndSpecScan(results pgx.BatchResults) ([]int, error)
}

Querier is a typesafe Go interface backed by SQL queries.

Methods ending with Batch enqueue a query to run later in a pgx.Batch. After calling SendBatch on pgx.Conn, pgxpool.Pool, or pgx.Tx, use the Scan methods to parse the results.

type QuerierConfig

type QuerierConfig struct {
	// DataTypes contains pgtype.Value to use for encoding and decoding instead
	// of pggen-generated pgtype.ValueTranscoder.
	//
	// If OIDs are available for an input parameter type and all of its
	// transitive dependencies, pggen will use the binary encoding format for
	// the input parameter.
	DataTypes []pgtype.DataType
}

type Repository

type Repository struct {
	// contains filtered or unexported fields
}

func NewRepository

func NewRepository(conn Connection) *Repository

func (*Repository) FindByID

func (r *Repository) FindByID(ctx context.Context, id int) (group.Group, error)

func (*Repository) FindID

func (r *Repository) FindID(ctx context.Context, params group.Group) (int, error)

func (*Repository) Nums

func (r *Repository) Nums(ctx context.Context, year int, spec string) ([]int, error)

func (*Repository) Specs

func (r *Repository) Specs(ctx context.Context, year int) ([]string, error)

func (*Repository) Years

func (r *Repository) Years(ctx context.Context) ([]int, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL