postgres

package
v1.0.0-rc.3 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Execute

func Execute[RESULT any](session octobe.BuilderSession[Builder], f Handler[RESULT]) (RESULT, error)

Execute executes a handler with a session builder, injecting the builder of the driver into the handler.

func OpenPGX

func OpenPGX(ctx context.Context, dsn string) octobe.Open[pgxConn, pgxConfig, Builder]

OpenPGX creates a new database connection and returns a driver with the specified types. It takes a context and a data source name (DSN) as parameters. The returned function, when called, initializes a new connection using the provided DSN. If the connection creation fails, it returns an error. Otherwise, it returns a new conn instance with the created connection.

func OpenPGXPool

func OpenPGXPool(ctx context.Context, dsn string) octobe.Open[pgxpoolConn, pgxConfig, Builder]

Open creates a new database connection and returns a driver with the specified types.

func OpenPGXPoolWithPool

func OpenPGXPoolWithPool(pool PGXPool) octobe.Open[pgxpoolConn, pgxConfig, Builder]

OpenWithPool creates a new database connection using an existing connection pool.

func OpenPGXWithConn

func OpenPGXWithConn(c PGXConn) octobe.Open[pgxConn, pgxConfig, Builder]

OpenPGXWithConn creates a new database connection using an existing connection. It takes an existing connection as a parameter. The returned function, when called, returns a new conn instance with the provided connection. If the provided connection is nil, it returns an error.

func OpenPGXWithOptions

func OpenPGXWithOptions(ctx context.Context, dsn string, options ParseConfigOptions) octobe.Open[pgxConn, pgxConfig, Builder]

OpenWithOptions creates a new database connection with additional options and returns a driver with the specified types. It takes a context, a data source name (DSN), and additional parse config options as parameters. The returned function, when called, initializes a new connection using the provided DSN and options. If the connection creation fails, it returns an error. Otherwise, it returns a new conn instance with the created connection.

func OpenWithConn

func OpenWithConn(db SQL) octobe.Open[sqlConn, sqlConfig, Builder]

OpenWithConn is a function that can be used for opening a new database connection, it should always return a driver with set signature of types for the local driver. This function is used when a connection db is already available.

func WithPGXTxOptions

func WithPGXTxOptions(options PGXTxOptions) octobe.Option[pgxConfig]

WithTransaction enables the use of a transaction for the session.

func WithSQLTxOptions

func WithSQLTxOptions(options SQLTxOptions) octobe.Option[sqlConfig]

WithTransaction enables the use of a transaction for the session.

Types

type Builder

type Builder func(query string) Segment

Builder is a function signature used for building queries with the pgx driver.

type ExecResult

type ExecResult struct {
	RowsAffected int64
}

ExecResult is a struct that holds the result of an execution, specifically the number of rows affected by the query.

type Handler

type Handler[RESULT any] func(Builder) (RESULT, error)

Handler is a signature type for a handler. The handler receives a builder of the specific driver and returns a result and an error.

type PGXConn

PGXConn defines the interface for a PGX postgres connection.

type PGXDriver

type PGXDriver octobe.Driver[pgxConn, pgxConfig, Builder]

Driver is a type alias for octobe.Driver with specific types for conn, config, and Builder.

type PGXPool

type PGXPool interface {
	Close()
	Acquire(ctx context.Context) (c *pgxpool.Conn, err error)
	AcquireFunc(ctx context.Context, f func(*pgxpool.Conn) error) error
	AcquireAllIdle(ctx context.Context) []*pgxpool.Conn
	Reset()
	Config() *pgxpool.Config
	Stat() *pgxpool.Stat
	Begin(context.Context) (pgx.Tx, error)
	BeginTx(context.Context, pgx.TxOptions) (pgx.Tx, error)
	Exec(context.Context, string, ...any) (pgconn.CommandTag, error)
	Query(context.Context, string, ...any) (pgx.Rows, error)
	QueryRow(context.Context, string, ...any) pgx.Row
	SendBatch(ctx context.Context, b *pgx.Batch) pgx.BatchResults
	CopyFrom(ctx context.Context, tableName pgx.Identifier, columnNames []string, rowSrc pgx.CopyFromSource) (int64, error)
	Ping(ctx context.Context) error
}

PGXPool defines the interface for a connection pool.

type PGXTxOptions

type PGXTxOptions pgx.TxOptions

PGXTxOptions holds the options for a transaction.

type ParseConfigOptions

type ParseConfigOptions struct {
	pgconn.ParseConfigOptions
}

ParseConfigOptions contains options that control how a config is built such as getsslpassword.

type Rows

type Rows interface {
	// Err returns any error that occurred while reading. Err must only be called after the Rows is closed (either by
	// calling Close or by Next returning false). If it is called early it may return nil even if there was an error
	// executing the query.
	Err() error

	// Next prepares the next row for reading. It returns true if there is another
	// row and false if no more rows are available or a fatal error has occurred.
	// It automatically closes rows when all rows are read.
	//
	// Callers should check rows.Err() after rows.Next() returns false to detect
	// whether result-set reading ended prematurely due to an error. See
	// Conn.Query for details.
	//
	// For simpler error handling, consider using the higher-level pgx v5
	// CollectRows() and ForEachRow() helpers instead.
	Next() bool

	// Scan reads the values from the current row into dest values positionally.
	// dest can include pointers to core types, values implementing the Scanner
	// interface, and nil. nil will skip the value entirely. It is an error to
	// call Scan without first calling Next() and checking that it returned true.
	Scan(dest ...any) error
}

Rows is an interface that represents a set of rows returned by a query. It provides methods to iterate over the rows and read their values. It is compatible with both pgx.Rows and sql.Rows types, allowing for flexibility in handling database results.

type SQL

type SQL interface {
	Begin() (*sql.Tx, error)
	BeginTx(context.Context, *sql.TxOptions) (*sql.Tx, error)
	Close() error
	PingContext(ctx context.Context) error
	SetConnMaxLifetime(d time.Duration)
	SetMaxIdleConns(n int)
	SetMaxOpenConns(n int)
	Stats() sql.DBStats
	Exec(query string, args ...any) (sql.Result, error)
	ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error)
	Prepare(query string) (*sql.Stmt, error)
	PrepareContext(ctx context.Context, query string) (*sql.Stmt, error)
	Query(query string, args ...any) (*sql.Rows, error)
	QueryContext(ctx context.Context, query string, args ...any) (*sql.Rows, error)
	QueryRow(query string, args ...any) *sql.Row
	QueryRowContext(ctx context.Context, query string, args ...any) *sql.Row
}

SQL defines the interface for the database/sql connection.

type SQLDriver

type SQLDriver octobe.Driver[sqlConn, sqlConfig, Builder]

Driver is a type alias for octobe.Driver with specific types for conn, config, and Builder.

type SQLTxOptions

type SQLTxOptions sql.TxOptions

SQLTxOptions holds the options for a transaction in the sql driver.

type Segment

type Segment interface {
	Arguments(args ...any) Segment
	Exec() (ExecResult, error)
	QueryRow(dest ...any) error
	Query(cb func(Rows) error) error
}

PGXSegment is an interface that represents a specific query that can be run only once. It keeps track of the query, arguments, and execution state.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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