pgsql

package module
v0.0.0-...-e344c5b Latest Latest
Warning

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

Go to latest
Published: May 30, 2022 License: MIT Imports: 10 Imported by: 0

README

pgsql

AFAIRE

Go Report Card Go Reference

Licence

MIT.


Copyright (c) 2021-2022 losyme

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoRows = pgx.ErrNoRows
)

Functions

func CtxWithTimeout

func CtxWithTimeout(timeout time.Duration) (context.Context, context.CancelFunc)

Types

type Batch

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

func (*Batch) Len

func (b *Batch) Len() int

func (*Batch) Queue

func (b *Batch) Queue(query string, args ...interface{})

func (*Batch) Send

func (b *Batch) Send(ctx context.Context) (BatchResults, error)

type BatchResults

type BatchResults interface {
	Execute() (int64, error)
	Query() (Rows, error)
	QueryRow() Row
	Close() error
}

type CbOnError

type CbOnError func(host string, port int, err error)

type CbOnSuccess

type CbOnSuccess func(host string, port int, primary bool)

type Client

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

func (*Client) Database

func (c *Client) Database() string

func (*Client) Execute

func (c *Client) Execute(ctx context.Context, sql string, args ...interface{}) (int64, error)

func (*Client) Pool

func (c *Client) Pool() *pgxpool.Pool

func (*Client) Query

func (c *Client) Query(ctx context.Context, sql string, args ...interface{}) (Rows, error)

func (*Client) QueryRow

func (c *Client) QueryRow(ctx context.Context, sql string, args ...interface{}) Row

func (*Client) Transaction

func (c *Client) Transaction(ctx context.Context, fn func(*Transaction) error) error

type Config

type Config struct {
	Name      string  `cfg:"name"`
	Nodes     []*Node `cfg:"nodes"`
	OnError   CbOnError
	OnSuccess CbOnSuccess
	Logger    Logger
}

func (*Config) Decrypt

func (c *Config) Decrypt(crypto Crypto) error

type Crypto

type Crypto interface {
	DecryptString(text string) (string, error)
}

type Database

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

func NewDatabase

func NewDatabase(cfg *Config) (*Database, error)

func (*Database) Close

func (db *Database) Close()

func (*Database) NewBatch

func (db *Database) NewBatch() *Batch

func (*Database) Primary

func (db *Database) Primary() (*Client, error)

func (*Database) PrimaryPreferred

func (db *Database) PrimaryPreferred() (*Client, error)

type Logger

type Logger interface {
	zombie.Logger
	Debug(msg string, kv ...interface{})
	Info(msg string, kv ...interface{})
	Warning(msg string, kv ...interface{})
	Error(msg string, kv ...interface{})
}

type Node

type Node struct {
	Host               string        `cfg:"host"`
	Port               int           `cfg:"port"`
	Username           string        `cfg:"username"`
	Password           string        `cfg:"password"`
	MaxConns           int           `cfg:"max_conns"`
	MinConns           int           `cfg:"min_conns"`
	MaxConnLifetime    time.Duration `cfg:"max_conn_lifetime"`
	MaxConnIdleTime    time.Duration `cfg:"max_conn_idle_time"`
	HealthCheckPeriod  time.Duration `cfg:"health_check_period"`
	ConnectTimeout     time.Duration `cfg:"connect_timeout"`
	CheckTimeout       time.Duration `cfg:"check_timeout"`
	CheckPeriod        time.Duration `cfg:"check_period"`
	CheckPeriodOnError time.Duration `cfg:"check_period_on_errror"`
}

type Row

type Row interface {
	Scan(dest ...interface{}) error
}

type Rows

type Rows interface {
	Next() bool
	Scan(dest ...interface{}) error
	Close()
	Err() error
}

type Transaction

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

func (*Transaction) Execute

func (t *Transaction) Execute(sql string, args ...interface{}) (int64, error)

func (*Transaction) Query

func (t *Transaction) Query(sql string, args ...interface{}) (Rows, error)

func (*Transaction) QueryRow

func (t *Transaction) QueryRow(sql string, args ...interface{}) Row

Jump to

Keyboard shortcuts

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