device

package
v0.0.0-...-1a642c0 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2023 License: MIT Imports: 5 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 sqlgen 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 CompositeUserOneTwoColsRow

type CompositeUserOneTwoColsRow struct {
	Num  int32 `json:"num"`
	User User  `json:"user"`
}

type CompositeUserRow

type CompositeUserRow struct {
	Mac  pgtype.Macaddr `json:"mac"`
	Type DeviceType     `json:"type"`
	User User           `json:"user"`
}

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

func (q *DBQuerier) CompositeUser(ctx context.Context) ([]CompositeUserRow, error)

CompositeUser implements Querier.CompositeUser.

func (*DBQuerier) CompositeUserBatch

func (q *DBQuerier) CompositeUserBatch(batch genericBatch)

CompositeUserBatch implements Querier.CompositeUserBatch.

func (*DBQuerier) CompositeUserMany

func (q *DBQuerier) CompositeUserMany(ctx context.Context) ([]User, error)

CompositeUserMany implements Querier.CompositeUserMany.

func (*DBQuerier) CompositeUserManyBatch

func (q *DBQuerier) CompositeUserManyBatch(batch genericBatch)

CompositeUserManyBatch implements Querier.CompositeUserManyBatch.

func (*DBQuerier) CompositeUserManyScan

func (q *DBQuerier) CompositeUserManyScan(results pgx.BatchResults) ([]User, error)

CompositeUserManyScan implements Querier.CompositeUserManyScan.

func (*DBQuerier) CompositeUserOne

func (q *DBQuerier) CompositeUserOne(ctx context.Context) (User, error)

CompositeUserOne implements Querier.CompositeUserOne.

func (*DBQuerier) CompositeUserOneBatch

func (q *DBQuerier) CompositeUserOneBatch(batch genericBatch)

CompositeUserOneBatch implements Querier.CompositeUserOneBatch.

func (*DBQuerier) CompositeUserOneScan

func (q *DBQuerier) CompositeUserOneScan(results pgx.BatchResults) (User, error)

CompositeUserOneScan implements Querier.CompositeUserOneScan.

func (*DBQuerier) CompositeUserOneTwoCols

func (q *DBQuerier) CompositeUserOneTwoCols(ctx context.Context) (CompositeUserOneTwoColsRow, error)

CompositeUserOneTwoCols implements Querier.CompositeUserOneTwoCols.

func (*DBQuerier) CompositeUserOneTwoColsBatch

func (q *DBQuerier) CompositeUserOneTwoColsBatch(batch genericBatch)

CompositeUserOneTwoColsBatch implements Querier.CompositeUserOneTwoColsBatch.

func (*DBQuerier) CompositeUserOneTwoColsScan

func (q *DBQuerier) CompositeUserOneTwoColsScan(results pgx.BatchResults) (CompositeUserOneTwoColsRow, error)

CompositeUserOneTwoColsScan implements Querier.CompositeUserOneTwoColsScan.

func (*DBQuerier) CompositeUserScan

func (q *DBQuerier) CompositeUserScan(results pgx.BatchResults) ([]CompositeUserRow, error)

CompositeUserScan implements Querier.CompositeUserScan.

func (*DBQuerier) FindDevicesByUser

func (q *DBQuerier) FindDevicesByUser(ctx context.Context, id int) ([]FindDevicesByUserRow, error)

FindDevicesByUser implements Querier.FindDevicesByUser.

func (*DBQuerier) FindDevicesByUserBatch

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

FindDevicesByUserBatch implements Querier.FindDevicesByUserBatch.

func (*DBQuerier) FindDevicesByUserScan

func (q *DBQuerier) FindDevicesByUserScan(results pgx.BatchResults) ([]FindDevicesByUserRow, error)

FindDevicesByUserScan implements Querier.FindDevicesByUserScan.

func (*DBQuerier) InsertDevice

func (q *DBQuerier) InsertDevice(ctx context.Context, mac pgtype.Macaddr, owner int) (pgconn.CommandTag, error)

InsertDevice implements Querier.InsertDevice.

func (*DBQuerier) InsertDeviceBatch

func (q *DBQuerier) InsertDeviceBatch(batch genericBatch, mac pgtype.Macaddr, owner int)

InsertDeviceBatch implements Querier.InsertDeviceBatch.

func (*DBQuerier) InsertDeviceScan

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

InsertDeviceScan implements Querier.InsertDeviceScan.

func (*DBQuerier) InsertUser

func (q *DBQuerier) InsertUser(ctx context.Context, userID int, name string) (pgconn.CommandTag, error)

InsertUser implements Querier.InsertUser.

func (*DBQuerier) InsertUserBatch

func (q *DBQuerier) InsertUserBatch(batch genericBatch, userID int, name string)

InsertUserBatch implements Querier.InsertUserBatch.

func (*DBQuerier) InsertUserScan

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

InsertUserScan implements Querier.InsertUserScan.

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 DeviceType

type DeviceType string

DeviceType represents the Postgres enum "device_type".

const (
	DeviceTypeUndefined DeviceType = "undefined"
	DeviceTypePhone     DeviceType = "phone"
	DeviceTypeLaptop    DeviceType = "laptop"
	DeviceTypeIpad      DeviceType = "ipad"
	DeviceTypeDesktop   DeviceType = "desktop"
	DeviceTypeIot       DeviceType = "iot"
)

func (DeviceType) String

func (d DeviceType) String() string

type FindDevicesByUserRow

type FindDevicesByUserRow struct {
	ID       int                 `json:"id"`
	Name     string              `json:"name"`
	MacAddrs pgtype.MacaddrArray `json:"mac_addrs"`
}

type Querier

type Querier interface {
	FindDevicesByUser(ctx context.Context, id int) ([]FindDevicesByUserRow, error)
	// FindDevicesByUserBatch enqueues a FindDevicesByUser query into batch to be executed
	// later by the batch.
	FindDevicesByUserBatch(batch genericBatch, id int)
	// FindDevicesByUserScan scans the result of an executed FindDevicesByUserBatch query.
	FindDevicesByUserScan(results pgx.BatchResults) ([]FindDevicesByUserRow, error)

	CompositeUser(ctx context.Context) ([]CompositeUserRow, error)
	// CompositeUserBatch enqueues a CompositeUser query into batch to be executed
	// later by the batch.
	CompositeUserBatch(batch genericBatch)
	// CompositeUserScan scans the result of an executed CompositeUserBatch query.
	CompositeUserScan(results pgx.BatchResults) ([]CompositeUserRow, error)

	CompositeUserOne(ctx context.Context) (User, error)
	// CompositeUserOneBatch enqueues a CompositeUserOne query into batch to be executed
	// later by the batch.
	CompositeUserOneBatch(batch genericBatch)
	// CompositeUserOneScan scans the result of an executed CompositeUserOneBatch query.
	CompositeUserOneScan(results pgx.BatchResults) (User, error)

	CompositeUserOneTwoCols(ctx context.Context) (CompositeUserOneTwoColsRow, error)
	// CompositeUserOneTwoColsBatch enqueues a CompositeUserOneTwoCols query into batch to be executed
	// later by the batch.
	CompositeUserOneTwoColsBatch(batch genericBatch)
	// CompositeUserOneTwoColsScan scans the result of an executed CompositeUserOneTwoColsBatch query.
	CompositeUserOneTwoColsScan(results pgx.BatchResults) (CompositeUserOneTwoColsRow, error)

	CompositeUserMany(ctx context.Context) ([]User, error)
	// CompositeUserManyBatch enqueues a CompositeUserMany query into batch to be executed
	// later by the batch.
	CompositeUserManyBatch(batch genericBatch)
	// CompositeUserManyScan scans the result of an executed CompositeUserManyBatch query.
	CompositeUserManyScan(results pgx.BatchResults) ([]User, error)

	InsertUser(ctx context.Context, userID int, name string) (pgconn.CommandTag, error)
	// InsertUserBatch enqueues a InsertUser query into batch to be executed
	// later by the batch.
	InsertUserBatch(batch genericBatch, userID int, name string)
	// InsertUserScan scans the result of an executed InsertUserBatch query.
	InsertUserScan(results pgx.BatchResults) (pgconn.CommandTag, error)

	InsertDevice(ctx context.Context, mac pgtype.Macaddr, owner int) (pgconn.CommandTag, error)
	// InsertDeviceBatch enqueues a InsertDevice query into batch to be executed
	// later by the batch.
	InsertDeviceBatch(batch genericBatch, mac pgtype.Macaddr, owner int)
	// InsertDeviceScan scans the result of an executed InsertDeviceBatch query.
	InsertDeviceScan(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 sqlgen-generated pgtype.ValueTranscoder.
	//
	// If OIDs are available for an input parameter type and all of its
	// transitive dependencies, sqlgen will use the binary encoding format for
	// the input parameter.
	DataTypes []pgtype.DataType
}

type User

type User struct {
	ID   *int    `json:"id"`
	Name *string `json:"name"`
}

User represents the Postgres composite type "user".

Jump to

Keyboard shortcuts

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