pgdb

package
v1.11.3 Latest Latest
Warning

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

Go to latest
Published: Feb 29, 2024 License: Apache-2.0 Imports: 18 Imported by: 4

Documentation

Index

Constants

View Source
const (
	// OrderTypeAsc means result should be sorted in ascending order.
	OrderTypeAsc = "asc"
	// OrderTypeDesc means result should be sorted in descending order.
	OrderTypeDesc = "desc"
)

Variables

This section is empty.

Functions

func IsConstraintErr

func IsConstraintErr(err error, name string) bool

func JSONScan

func JSONScan(src, dest interface{}) error

JSONScan is used to implement Scan method for structs which will be represented in database as raw json

func JSONValue

func JSONValue(data interface{}) (driver.Value, error)

JSONValue is used to implement Value method for structs which will be represented in database as raw json

Types

type Connection

type Connection interface {
	Transactor
	Queryer
}

Connection is yet another thin wrapper for sql.DB allowing to use squirrel queries directly

type CursorPageParams

type CursorPageParams struct {
	Cursor uint64 `page:"cursor" json:"cursor"`
	Order  string `page:"order" json:"order"`
	Limit  uint64 `page:"limit" json:"limit"`
}

CursorPageParams - page params of the db query

func (*CursorPageParams) ApplyTo

ApplyTo returns a new SelectBuilder after applying the paging effects of `p` to `sql`. This method provides the default case for paging: int64 cursor-based paging by an id column.

type DB

type DB struct {
	Queryer
	// contains filtered or unexported fields
}

func Open

func Open(opts Opts) (*DB, error)

func (*DB) Clone

func (db *DB) Clone() *DB

func (*DB) RawDB

func (db *DB) RawDB() *sql.DB

func (*DB) Transaction

func (db *DB) Transaction(fn TransactionFunc) (err error)

Transaction is generic helper method for specific Q's to implement Transaction capabilities

func (*DB) TransactionWithOptions added in v1.8.6

func (db *DB) TransactionWithOptions(opts *sql.TxOptions, fn TransactionFunc) (err error)

type Databaser

type Databaser interface {
	DB() *DB
	RawDB() *sql.DB
	NewListener() *pq.Listener
}

func NewDatabaser

func NewDatabaser(getter kv.Getter) Databaser

type EventsListenerOpts added in v1.9.0

type EventsListenerOpts struct {
	Log        *logan.Entry
	Payload    string // skip notifications from the channel if payload does not match. Empty string is treated as no filter is present
	TickPeriod time.Duration
	Handler    Handler
}

EventsListenerOpts - defines config for events listener

type EventsRouter added in v1.9.0

type EventsRouter interface {
	RunNewListener(ctx context.Context, opts EventsListenerOpts)
}

EventsRouter - listens to events of postgres channel and sends notification to listeners

func NewEventsRouter added in v1.9.0

func NewEventsRouter(ctx context.Context, opts EventsRouterOpts) EventsRouter

NewEventsRouter - creates new EventsRouter and starts corresponding routines

type EventsRouterOpts added in v1.9.0

type EventsRouterOpts struct {
	Log      *logan.Entry
	Channel  string
	Listener *pq.Listener
}

EventsRouterOpts - config for new EventsRouter

type Execer

type Execer interface {
	Exec(query squirrel.Sqlizer) error
	ExecContext(ctx context.Context, query squirrel.Sqlizer) error
	ExecRaw(query string, args ...interface{}) error
	ExecRawContext(ctx context.Context, query string, args ...interface{}) error
	ExecWithResult(query squirrel.Sqlizer) (sql.Result, error)
	ExecWithResultContext(ctx context.Context, query squirrel.Sqlizer) (sql.Result, error)
}

type Getter

type Getter interface {
	Get(dest interface{}, query squirrel.Sqlizer) error
	GetContext(ctx context.Context, dest interface{}, query squirrel.Sqlizer) error
	GetRaw(dest interface{}, query string, args ...interface{}) error
	GetRawContext(ctx context.Context, dest interface{}, query string, args ...interface{}) error
}

type Handler added in v1.9.0

type Handler interface {
	Handle(ctx context.Context) error
}

Handler - handles notification of new event received form postgres or ticks

type OffsetPageParams

type OffsetPageParams struct {
	Limit      uint64 `page:"limit" default:"15" json:"limit"`
	Order      string `page:"order" default:"desc" json:"order"`
	PageNumber uint64 `page:"number" json:"number"`
}

OffsetPageParams defines page params for offset-based pagination.

func (*OffsetPageParams) ApplyTo

ApplyTo returns a new SelectBuilder after applying the paging effects of `p` to `sql`.

type Opts

type Opts struct {
	URL                string
	MaxOpenConnections int
	MaxIdleConnections int
}

type Queryer

type Queryer interface {
	Execer
	Selecter
	Getter
}

Queryer overloads sqlx's interface name with different meaning, which is not cool.

type Selecter

type Selecter interface {
	Select(dest interface{}, query squirrel.Sqlizer) error
	SelectContext(ctx context.Context, dest interface{}, query squirrel.Sqlizer) error
	SelectRaw(dest interface{}, query string, args ...interface{}) error
	SelectRawContext(ctx context.Context, dest interface{}, query string, args ...interface{}) error
}

type Sort

type Sort string

Sort is a string that describes one sort parameter defined by client.

func (Sort) Desc

func (s Sort) Desc() bool

Desc returns whether sorting by specific column should be performed in descending order.

type SortedOffsetPageParams added in v1.10.0

type SortedOffsetPageParams struct {
	Limit      uint64   `page:"limit" default:"15"`
	Sort       []string `url:"sort"`
	PageNumber uint64   `page:"number"`
}

OffsetPageParams defines page params for offset-based pagination.

func (*SortedOffsetPageParams) ApplyTo added in v1.10.0

type Sorts

type Sorts []Sort

Sorts is a slice of sorting params that can be applied directly to sql query.

func (Sorts) ApplyTo

func (sorts Sorts) ApplyTo(stmt squirrel.SelectBuilder, columns map[string]string) squirrel.SelectBuilder

ApplyTo applies sorts to a prepared sql statement. Takes a map of <query-param>:<column> names (without minuses). Like:

	 map[string]string{}{
		"created_at": "books.created_at",
		"author.name": "authors.name",
  }

Panics if sort parameter in a slice isn't provided in "columns" map.

type TransactionFunc

type TransactionFunc func() error

type Transactor

type Transactor interface {
	Transaction(transactionFunc TransactionFunc) (err error)
}

Jump to

Keyboard shortcuts

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