pgdriver

package module
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: May 19, 2021 License: BSD-2-Clause Imports: 22 Imported by: 363

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Logger logging = &logger{
	log: log.New(os.Stderr, "pgdriver: ", log.LstdFlags|log.Lshortfile),
}

Functions

func NewConnector

func NewConnector(opts ...DriverOption) driver.Connector

Types

type Channel

type Channel struct {
	C chan Notification
	// contains filtered or unexported fields
}

type ChannelOption

type ChannelOption func(c *Channel)

func WithChannelSize

func WithChannelSize(size int) ChannelOption

type Config added in v0.1.3

type Config struct {
	Network     string
	Addr        string
	DialTimeout time.Duration
	Dialer      func(ctx context.Context, network, addr string) (net.Conn, error)

	User     string
	Password string
	Database string
	AppName  string

	ReadTimeout  time.Duration
	WriteTimeout time.Duration
}

type Conn

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

func (*Conn) Begin

func (cn *Conn) Begin() (driver.Tx, error)

func (*Conn) Close

func (cn *Conn) Close() error

func (*Conn) ExecContext

func (cn *Conn) ExecContext(
	ctx context.Context, query string, args []driver.NamedValue,
) (driver.Result, error)

func (*Conn) Prepare

func (cn *Conn) Prepare(query string) (driver.Stmt, error)

func (*Conn) QueryContext

func (cn *Conn) QueryContext(
	ctx context.Context, query string, args []driver.NamedValue,
) (driver.Rows, error)

type Driver

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

func NewDriver

func NewDriver() Driver

func (Driver) Open

func (d Driver) Open(name string) (driver.Conn, error)

func (Driver) OpenConnector

func (d Driver) OpenConnector(name string) (driver.Connector, error)

type DriverOption

type DriverOption func(*driverConnector)

func WithAddr

func WithAddr(addr string) DriverOption

func WithApplicationName

func WithApplicationName(appName string) DriverOption

func WithDSN

func WithDSN(dsn string) DriverOption

func WithDatabase

func WithDatabase(database string) DriverOption

func WithDialTimeout

func WithDialTimeout(dialTimeout time.Duration) DriverOption

func WithPassword

func WithPassword(password string) DriverOption

func WithReadTimeout

func WithReadTimeout(readTimeout time.Duration) DriverOption

func WithTimeout

func WithTimeout(timeout time.Duration) DriverOption

func WithUser

func WithUser(user string) DriverOption

func WithWriteTimeout

func WithWriteTimeout(writeTimeout time.Duration) DriverOption

type DriverStats

type DriverStats struct {
	Queries uint64
	Errors  uint64
}

type Error

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

Error represents an error returned by PostgreSQL server using PostgreSQL ErrorResponse protocol.

https://www.postgresql.org/docs/10/static/protocol-message-formats.html

func (Error) Error

func (err Error) Error() string

func (Error) Field

func (err Error) Field(k byte) string

func (Error) IntegrityViolation

func (err Error) IntegrityViolation() bool

type Listener

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

func NewListener

func NewListener(db *bun.DB) *Listener

func (*Listener) Channel

func (ln *Listener) Channel(opts ...ChannelOption) *Channel

Channel returns a channel for concurrently receiving notifications. It periodically sends Ping notification to test connection health.

The channel is closed with Listener. Receive* APIs can not be used after channel is created.

func (*Listener) Close

func (ln *Listener) Close() error

Close closes the listener, releasing any open resources.

func (*Listener) Listen

func (ln *Listener) Listen(ctx context.Context, channels ...string) error

Listen starts listening for notifications on channels.

func (*Listener) Receive

func (ln *Listener) Receive(ctx context.Context) (channel string, payload string, err error)

Receive indefinitely waits for a notification. This is low-level API and in most cases Channel should be used instead.

func (*Listener) ReceiveTimeout

func (ln *Listener) ReceiveTimeout(
	ctx context.Context, timeout time.Duration,
) (channel, payload string, err error)

ReceiveTimeout waits for a notification until timeout is reached. This is low-level API and in most cases Channel should be used instead.

func (*Listener) Unlisten

func (ln *Listener) Unlisten(ctx context.Context, channels ...string) error

Unlisten stops listening for notifications on channels.

type Notification

type Notification struct {
	Channel string
	Payload string
}

Notification received with LISTEN command.

Jump to

Keyboard shortcuts

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