adapter

package
v3.3.0 Latest Latest
Warning

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

Go to latest
Published: Jan 1, 2022 License: MIT Imports: 6 Imported by: 2

Documentation

Index

Constants

View Source
const KeyError = "error"

KeyError is the default key for error field

Variables

View Source
var (
	// ErrNoRows abstract db driver-level "no rows in result set" error
	ErrNoRows = errors.New("no rows in result set")
	// ErrTxClosed abstract db driver-level "transaction is closed" error
	ErrTxClosed = errors.New("tx is closed")
)

Functions

This section is empty.

Types

type CommandTag

type CommandTag interface {
	// RowsAffected returns the number of rows affected. If the CommandTag was not
	// for a row affecting command (such as "CREATE TABLE") then it returns 0
	RowsAffected() int64
}

CommandTag is the result of an Exec function

type ConnPool

type ConnPool interface {
	Queryable
	// Begin starts a transaction with the default transaction mode.
	Begin(ctx context.Context) (Tx, error)
	// Close ends the use of a connection pool. It prevents any new connections from
	// being acquired and closes available underlying connections. Any acquired
	// connections will be closed when they are released.
	Close() error
}

ConnPool is a PostgreSQL connection pool handle.

type Field

type Field struct {
	Key   string
	Value interface{}
}

Field is the simple container for a single log field

func Err

func Err(err error) Field

Err returns error as field

func F

func F(key string, value interface{}) Field

F returns value as field

type Logger

type Logger interface {
	Debug(msg string, fields ...Field)
	Info(msg string, fields ...Field)
	Error(msg string, fields ...Field)

	With(fields ...Field) Logger
}

Logger declares base logging methods

type NoOpLogger

type NoOpLogger struct{}

NoOpLogger implements Logger that does nothing, all logs are going to /dev/null

func (NoOpLogger) Debug

func (l NoOpLogger) Debug(string, ...Field)

Debug implements Logger.Debug for /dev/null logger

func (NoOpLogger) Error

func (l NoOpLogger) Error(string, ...Field)

Error implements Logger.Debug for /dev/null logger

func (NoOpLogger) Info

func (l NoOpLogger) Info(string, ...Field)

Info implements Logger.Debug for /dev/null logger

func (NoOpLogger) With

func (l NoOpLogger) With(...Field) Logger

With implements nested logger for /dev/null logger

type Queryable

type Queryable interface {
	// Exec executes sql. sql can be either a prepared statement name or an SQL string.
	// arguments should be referenced positionally from the sql string as $1, $2, etc.
	Exec(ctx context.Context, sql string, arguments ...interface{}) (CommandTag, error)
	// QueryRow executes sql with args. Any error that occurs while
	// querying is deferred until calling Scan on the returned Row. That Row will
	// error with ErrNoRows if no rows are returned.
	QueryRow(ctx context.Context, sql string, args ...interface{}) Row
}

Queryable is the base interface for different types of db connections that should implement basic querying operations.

type Row

type Row interface {
	// Scan reads the values from the current row into dest values positionally.
	// If no rows were found it returns ErrNoRows. If multiple rows are returned it
	// ignores all but the first.
	Scan(dest ...interface{}) error
}

Row represents single row returned by DB driver

type StdLogger

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

StdLogger implements Logger that uses stdlib "log" as output

func NewStdLogger

func NewStdLogger(fields ...Field) *StdLogger

NewStdLogger instantiates new Logger using stdlib "log". Builder allows to set default set of fields for all the logs being written.

func (*StdLogger) Debug

func (l *StdLogger) Debug(msg string, fields ...Field)

Debug implements Logger.Debug for stdlib "log" logger

func (*StdLogger) Error

func (l *StdLogger) Error(msg string, fields ...Field)

Error implements Logger.Debug for stdlib "log" logger

func (*StdLogger) Info

func (l *StdLogger) Info(msg string, fields ...Field)

Info implements Logger.Debug for stdlib "log" logger

func (*StdLogger) With

func (l *StdLogger) With(fields ...Field) Logger

With implements nested logger for stdlib "log" logger

type Tx

type Tx interface {
	Queryable
	// Rollback rolls back the transaction. Rollback will return ErrTxClosed if the
	// Tx is already closed, but is otherwise safe to call multiple times. Hence, a
	// defer tx.Rollback() is safe even if tx.Commit() will be called first in a
	// non-error condition.
	Rollback(ctx context.Context) error
	// Commit commits the transaction
	Commit(ctx context.Context) error
}

Tx represents a database transaction.

Directories

Path Synopsis
Package gopgv10 implements github.com/go-pg/pg/v10 adapter.
Package gopgv10 implements github.com/go-pg/pg/v10 adapter.

Jump to

Keyboard shortcuts

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