adapter

package
v4.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2022 License: MIT Imports: 6 Imported by: 1

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 Conn

type Conn interface {
	Queryable
	// Ping checks if the DB and connection are alive.
	Ping(ctx context.Context) error
	// Begin starts a transaction with the default transaction mode.
	Begin(ctx context.Context) (Tx, error)
	// Release returns connection to the pool it was acquired from.
	// Once Release has been called, other methods must not be called.
	Release() error
}

Conn is a single PostgreSQL connection.

type ConnPool

type ConnPool interface {
	Queryable
	// Ping checks if the DB and connection are alive.
	Ping(ctx context.Context) error
	// Begin starts a transaction with the default transaction mode.
	Begin(ctx context.Context) (Tx, error)
	// Acquire returns a connection Conn from the ConnPool.
	// Connection must be returned to the pool after usage by calling Conn.Release().
	Acquire(ctx context.Context) (Conn, 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 any
}

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 any) 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.
	// args should be referenced positionally from the sql string as $1, $2, etc.
	Exec(ctx context.Context, sql string, args ...any) (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 ...any) Row
	// Query executes a query that returns rows, typically a SELECT.
	// The args are for any placeholder parameters in the query.
	Query(ctx context.Context, sql string, args ...any) (Rows, error)
}

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 ...any) error
}

Row represents single row returned by DB driver

type Rows

type Rows interface {
	// Next prepares the next row for reading. It returns true if there is another
	// row and false if no more rows are available. It automatically closes rows
	// when all rows are read.
	Next() bool
	// Scan reads the values from the current row into dest values positionally.
	Scan(dest ...any) error
	// Err returns any error that occurred while reading.
	Err() error
}

Rows represents rows set 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

Jump to

Keyboard shortcuts

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