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: 9 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 CreateJobParams

type CreateJobParams struct {
	ChatID int64
	SendAt time.Time
	Flags  pgtype.Int2
	Title  pgtype.Varchar
}

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) CountInChat

func (q *DBQuerier) CountInChat(ctx context.Context, chatID int64) (int64, error)

CountInChat implements Querier.CountInChat.

func (*DBQuerier) CountInChatBatch

func (q *DBQuerier) CountInChatBatch(batch genericBatch, chatID int64)

CountInChatBatch implements Querier.CountInChatBatch.

func (*DBQuerier) CountInChatScan

func (q *DBQuerier) CountInChatScan(results pgx.BatchResults) (int64, error)

CountInChatScan implements Querier.CountInChatScan.

func (*DBQuerier) CreateJob

func (q *DBQuerier) CreateJob(ctx context.Context, params CreateJobParams) (int64, error)

CreateJob implements Querier.CreateJob.

func (*DBQuerier) CreateJobBatch

func (q *DBQuerier) CreateJobBatch(batch genericBatch, params CreateJobParams)

CreateJobBatch implements Querier.CreateJobBatch.

func (*DBQuerier) CreateJobScan

func (q *DBQuerier) CreateJobScan(results pgx.BatchResults) (int64, error)

CreateJobScan implements Querier.CreateJobScan.

func (*DBQuerier) Delete

func (q *DBQuerier) Delete(ctx context.Context, id int64) (pgconn.CommandTag, error)

Delete implements Querier.Delete.

func (*DBQuerier) DeleteBatch

func (q *DBQuerier) DeleteBatch(batch genericBatch, id int64)

DeleteBatch implements Querier.DeleteBatch.

func (*DBQuerier) DeleteScan

func (q *DBQuerier) DeleteScan(results pgx.BatchResults) (pgconn.CommandTag, error)

DeleteScan implements Querier.DeleteScan.

func (*DBQuerier) FindAtTime

func (q *DBQuerier) FindAtTime(ctx context.Context, at time.Time) ([]FindAtTimeRow, error)

FindAtTime implements Querier.FindAtTime.

func (*DBQuerier) FindAtTimeBatch

func (q *DBQuerier) FindAtTimeBatch(batch genericBatch, at time.Time)

FindAtTimeBatch implements Querier.FindAtTimeBatch.

func (*DBQuerier) FindAtTimeScan

func (q *DBQuerier) FindAtTimeScan(results pgx.BatchResults) ([]FindAtTimeRow, error)

FindAtTimeScan implements Querier.FindAtTimeScan.

func (*DBQuerier) FindByChat

func (q *DBQuerier) FindByChat(ctx context.Context, chatID int64) ([]FindByChatRow, error)

FindByChat implements Querier.FindByChat.

func (*DBQuerier) FindByChatBatch

func (q *DBQuerier) FindByChatBatch(batch genericBatch, chatID int64)

FindByChatBatch implements Querier.FindByChatBatch.

func (*DBQuerier) FindByChatScan

func (q *DBQuerier) FindByChatScan(results pgx.BatchResults) ([]FindByChatRow, error)

FindByChatScan implements Querier.FindByChatScan.

func (*DBQuerier) FindByID

func (q *DBQuerier) FindByID(ctx context.Context, id int64) (FindByIDRow, error)

FindByID implements Querier.FindByID.

func (*DBQuerier) FindByIDBatch

func (q *DBQuerier) FindByIDBatch(batch genericBatch, id int64)

FindByIDBatch implements Querier.FindByIDBatch.

func (*DBQuerier) FindByIDScan

func (q *DBQuerier) FindByIDScan(results pgx.BatchResults) (FindByIDRow, error)

FindByIDScan implements Querier.FindByIDScan.

func (*DBQuerier) FindInPeriod

func (q *DBQuerier) FindInPeriod(ctx context.Context, at time.Time, period time.Duration) ([]FindInPeriodRow, error)

FindInPeriod implements Querier.FindInPeriod.

func (*DBQuerier) FindInPeriodBatch

func (q *DBQuerier) FindInPeriodBatch(batch genericBatch, at time.Time, period time.Duration)

FindInPeriodBatch implements Querier.FindInPeriodBatch.

func (*DBQuerier) FindInPeriodScan

func (q *DBQuerier) FindInPeriodScan(results pgx.BatchResults) ([]FindInPeriodRow, error)

FindInPeriodScan implements Querier.FindInPeriodScan.

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 FindAtTimeRow

type FindAtTimeRow struct {
	ID     int64          `json:"id"`
	ChatID int64          `json:"chat_id"`
	Title  pgtype.Varchar `json:"title"`
	SendAt time.Time      `json:"send_at"`
	Flags  pgtype.Int2    `json:"flags"`
}

type FindByChatRow

type FindByChatRow struct {
	ID     int64          `json:"id"`
	ChatID int64          `json:"chat_id"`
	Title  pgtype.Varchar `json:"title"`
	SendAt time.Time      `json:"send_at"`
	Flags  pgtype.Int2    `json:"flags"`
}

type FindByIDRow

type FindByIDRow struct {
	ID     int64          `json:"id"`
	ChatID int64          `json:"chat_id"`
	Title  pgtype.Varchar `json:"title"`
	SendAt time.Time      `json:"send_at"`
	Flags  pgtype.Int2    `json:"flags"`
}

type FindInPeriodRow

type FindInPeriodRow struct {
	ID     int64          `json:"id"`
	ChatID int64          `json:"chat_id"`
	Title  pgtype.Varchar `json:"title"`
	SendAt time.Time      `json:"send_at"`
	Flags  pgtype.Int2    `json:"flags"`
}

type Querier

type Querier interface {
	CreateJob(ctx context.Context, params CreateJobParams) (int64, error)
	// CreateJobBatch enqueues a CreateJob query into batch to be executed
	// later by the batch.
	CreateJobBatch(batch genericBatch, params CreateJobParams)
	// CreateJobScan scans the result of an executed CreateJobBatch query.
	CreateJobScan(results pgx.BatchResults) (int64, error)

	FindByID(ctx context.Context, id int64) (FindByIDRow, error)
	// FindByIDBatch enqueues a FindByID query into batch to be executed
	// later by the batch.
	FindByIDBatch(batch genericBatch, id int64)
	// FindByIDScan scans the result of an executed FindByIDBatch query.
	FindByIDScan(results pgx.BatchResults) (FindByIDRow, error)

	FindInPeriod(ctx context.Context, at time.Time, period time.Duration) ([]FindInPeriodRow, error)
	// FindInPeriodBatch enqueues a FindInPeriod query into batch to be executed
	// later by the batch.
	FindInPeriodBatch(batch genericBatch, at time.Time, period time.Duration)
	// FindInPeriodScan scans the result of an executed FindInPeriodBatch query.
	FindInPeriodScan(results pgx.BatchResults) ([]FindInPeriodRow, error)

	CountInChat(ctx context.Context, chatID int64) (int64, error)
	// CountInChatBatch enqueues a CountInChat query into batch to be executed
	// later by the batch.
	CountInChatBatch(batch genericBatch, chatID int64)
	// CountInChatScan scans the result of an executed CountInChatBatch query.
	CountInChatScan(results pgx.BatchResults) (int64, error)

	FindByChat(ctx context.Context, chatID int64) ([]FindByChatRow, error)
	// FindByChatBatch enqueues a FindByChat query into batch to be executed
	// later by the batch.
	FindByChatBatch(batch genericBatch, chatID int64)
	// FindByChatScan scans the result of an executed FindByChatBatch query.
	FindByChatScan(results pgx.BatchResults) ([]FindByChatRow, error)

	FindAtTime(ctx context.Context, at time.Time) ([]FindAtTimeRow, error)
	// FindAtTimeBatch enqueues a FindAtTime query into batch to be executed
	// later by the batch.
	FindAtTimeBatch(batch genericBatch, at time.Time)
	// FindAtTimeScan scans the result of an executed FindAtTimeBatch query.
	FindAtTimeScan(results pgx.BatchResults) ([]FindAtTimeRow, error)

	Delete(ctx context.Context, id int64) (pgconn.CommandTag, error)
	// DeleteBatch enqueues a Delete query into batch to be executed
	// later by the batch.
	DeleteBatch(batch genericBatch, id int64)
	// DeleteScan scans the result of an executed DeleteBatch query.
	DeleteScan(results pgx.BatchResults) (pgconn.CommandTag, 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) CountInChat

func (r *Repository) CountInChat(ctx context.Context, chatId int64) (int64, error)

func (*Repository) Delete

func (r *Repository) Delete(ctx context.Context, cronId int64) error

func (*Repository) FindAtTime

func (r *Repository) FindAtTime(ctx context.Context, at time.Time) ([]scheduler.CronJob, error)

func (*Repository) FindByChat

func (r *Repository) FindByChat(ctx context.Context, chatId int64) ([]scheduler.CronJob, error)

func (*Repository) FindByID

func (r *Repository) FindByID(ctx context.Context, chatId int64) (*scheduler.CronJob, error)

func (*Repository) FindInPeriod

func (r *Repository) FindInPeriod(ctx context.Context, at time.Time, periodRange time.Duration) ([]scheduler.CronJob, error)

func (*Repository) Insert

func (r *Repository) Insert(ctx context.Context, cron scheduler.CronJob) (int64, error)

func (*Repository) Update

func (r *Repository) Update(ctx context.Context, job scheduler.CronJob) error

Jump to

Keyboard shortcuts

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