pgdb

package
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: May 13, 2020 License: Apache-2.0 Imports: 15 Imported by: 0

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"`
	Order  string `page:"order"`
	Limit  uint64 `page:"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

type Databaser

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

func NewDatabaser

func NewDatabaser(getter kv.Getter) Databaser

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 OffsetPageParams

type OffsetPageParams struct {
	Limit      uint64 `page:"limit" default:"15"`
	Order      string `page:"order" default:"desc"`
	PageNumber uint64 `page:"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 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