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: 7 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 interface {
	BeginFunc(ctx context.Context, f func(pgx.Tx) error) error
	// contains filtered or unexported methods
}

type CreateChatRow

type CreateChatRow struct {
	ID        int64              `json:"id"`
	CreatedAt pgtype.Timestamptz `json:"created_at"`
}

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

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

CreateChat implements Querier.CreateChat.

func (*DBQuerier) CreateChatBatch

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

CreateChatBatch implements Querier.CreateChatBatch.

func (*DBQuerier) CreateChatScan

func (q *DBQuerier) CreateChatScan(results pgx.BatchResults) (CreateChatRow, error)

CreateChatScan implements Querier.CreateChatScan.

func (*DBQuerier) Delete

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

Delete implements Querier.Delete.

func (*DBQuerier) DeleteBatch

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

DeleteBatch implements Querier.DeleteBatch.

func (*DBQuerier) DeleteScan

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

DeleteScan implements Querier.DeleteScan.

func (*DBQuerier) FindAllActiveChats

func (q *DBQuerier) FindAllActiveChats(ctx context.Context) ([]FindAllActiveChatsRow, error)

FindAllActiveChats implements Querier.FindAllActiveChats.

func (*DBQuerier) FindAllActiveChatsBatch

func (q *DBQuerier) FindAllActiveChatsBatch(batch genericBatch)

FindAllActiveChatsBatch implements Querier.FindAllActiveChatsBatch.

func (*DBQuerier) FindAllActiveChatsScan

func (q *DBQuerier) FindAllActiveChatsScan(results pgx.BatchResults) ([]FindAllActiveChatsRow, error)

FindAllActiveChatsScan implements Querier.FindAllActiveChatsScan.

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

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

FindByTgID implements Querier.FindByTgID.

func (*DBQuerier) FindByTgIDBatch

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

FindByTgIDBatch implements Querier.FindByTgIDBatch.

func (*DBQuerier) FindByTgIDScan

func (q *DBQuerier) FindByTgIDScan(results pgx.BatchResults) (FindByTgIDRow, error)

FindByTgIDScan implements Querier.FindByTgIDScan.

func (*DBQuerier) UndeleteChat

func (q *DBQuerier) UndeleteChat(ctx context.Context, chatID int64) (pgconn.CommandTag, error)

UndeleteChat implements Querier.UndeleteChat.

func (*DBQuerier) UndeleteChatBatch

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

UndeleteChatBatch implements Querier.UndeleteChatBatch.

func (*DBQuerier) UndeleteChatScan

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

UndeleteChatScan implements Querier.UndeleteChatScan.

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 FindAllActiveChatsRow

type FindAllActiveChatsRow struct {
	ID        int64              `json:"id"`
	ChatID    int64              `json:"chat_id"`
	GroupID   int                `json:"group_id"`
	CreatedAt pgtype.Timestamptz `json:"created_at"`
	DeletedAt pgtype.Timestamptz `json:"deleted_at"`
}

type FindByIDRow

type FindByIDRow struct {
	ID        int64              `json:"id"`
	ChatID    int64              `json:"chat_id"`
	GroupID   int                `json:"group_id"`
	CreatedAt pgtype.Timestamptz `json:"created_at"`
	DeletedAt pgtype.Timestamptz `json:"deleted_at"`
}

type FindByTgIDRow

type FindByTgIDRow struct {
	ID        int64              `json:"id"`
	ChatID    int64              `json:"chat_id"`
	GroupID   int                `json:"group_id"`
	CreatedAt pgtype.Timestamptz `json:"created_at"`
	DeletedAt pgtype.Timestamptz `json:"deleted_at"`
}

type Querier

type Querier interface {
	CreateChat(ctx context.Context, chatID int64) (CreateChatRow, error)
	// CreateChatBatch enqueues a CreateChat query into batch to be executed
	// later by the batch.
	CreateChatBatch(batch genericBatch, chatID int64)
	// CreateChatScan scans the result of an executed CreateChatBatch query.
	CreateChatScan(results pgx.BatchResults) (CreateChatRow, error)

	FindByTgID(ctx context.Context, chatID int64) (FindByTgIDRow, error)
	// FindByTgIDBatch enqueues a FindByTgID query into batch to be executed
	// later by the batch.
	FindByTgIDBatch(batch genericBatch, chatID int64)
	// FindByTgIDScan scans the result of an executed FindByTgIDBatch query.
	FindByTgIDScan(results pgx.BatchResults) (FindByTgIDRow, 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)

	FindAllActiveChats(ctx context.Context) ([]FindAllActiveChatsRow, error)
	// FindAllActiveChatsBatch enqueues a FindAllActiveChats query into batch to be executed
	// later by the batch.
	FindAllActiveChatsBatch(batch genericBatch)
	// FindAllActiveChatsScan scans the result of an executed FindAllActiveChatsBatch query.
	FindAllActiveChatsScan(results pgx.BatchResults) ([]FindAllActiveChatsRow, error)

	UndeleteChat(ctx context.Context, chatID int64) (pgconn.CommandTag, error)
	// UndeleteChatBatch enqueues a UndeleteChat query into batch to be executed
	// later by the batch.
	UndeleteChatBatch(batch genericBatch, chatID int64)
	// UndeleteChatScan scans the result of an executed UndeleteChatBatch query.
	UndeleteChatScan(results pgx.BatchResults) (pgconn.CommandTag, error)

	Delete(ctx context.Context, chatID int64) (pgconn.CommandTag, error)
	// DeleteBatch enqueues a Delete query into batch to be executed
	// later by the batch.
	DeleteBatch(batch genericBatch, chatID 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) Create

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

func (*Repository) Delete

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

func (*Repository) FindAllActiveChats

func (r *Repository) FindAllActiveChats(ctx context.Context) ([]*ModelDTO, error)

func (*Repository) FindByID

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

func (*Repository) FindByTelegramID

func (r *Repository) FindByTelegramID(ctx context.Context, id int64) (*ModelDTO, error)

func (*Repository) RestoreFromDeleted

func (r *Repository) RestoreFromDeleted(ctx context.Context, id int64) error

func (*Repository) Session

func (r *Repository) Session(ctx context.Context, fn func(session Storage) error) error

func (*Repository) UpdateChatGroup

func (r *Repository) UpdateChatGroup(ctx context.Context, id int64, group *int) error

Jump to

Keyboard shortcuts

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