postgres

package
v2.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 22, 2023 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Execute

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

Execute is a function that can be used for executing a handler with a session builder. This function injects the builder of the driver into the handler.

func Open

func Open(ctx context.Context, dsn string, opts ...octobe.Option[config]) octobe.Open[postgres, config, Builder]

Open 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.

func OpenWithPool

func OpenWithPool(pool *pgx.Conn, opts ...octobe.Option[config]) octobe.Open[postgres, config, Builder]

OpenWithPool 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 pool is already available.

func WithTransaction

func WithTransaction(options TxOptions) octobe.Option[config]

WithTransaction enables the use of a transaction for the session, enforce the usage of commit and rollback.

func WithoutTransaction

func WithoutTransaction() octobe.Option[config]

WithoutTransaction disables the use of a transaction for the session, this will not enforce the usage of commit and rollback.

Types

type Builder

type Builder func(query string) Segment

Builder is a function signature that is used for building queries with postgres

type Driver

type Driver octobe.Driver[postgres, config, Builder]

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 Segment

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

Segment is a specific query that can be run only once it keeps a few fields for keeping track on the Segment

func (*Segment) Arguments

func (s *Segment) Arguments(args ...interface{}) *Segment

Arguments receives unknown amount of arguments to use in the query

func (*Segment) Exec

func (s *Segment) Exec() (pgconn.CommandTag, error)

Exec will execute a query. Used for inserts or updates

func (*Segment) Query

func (s *Segment) Query(cb func(pgx.Rows) error) error

Query will perform a normal query against database that returns rows

func (*Segment) QueryRow

func (s *Segment) QueryRow(dest ...interface{}) error

QueryRow will return one result and put them into destination pointers

type TxOptions

type TxOptions pgx.TxOptions

TxOptions is a struct that holds the options for a transaction

Jump to

Keyboard shortcuts

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