Documentation
¶
Index ¶
Constants ¶
const ( StmtCheckJob = "gue_check_job" StmtDeleteJob = "gue_destroy_job" StmtInsertJob = "gue_insert_job" StmtLockJob = "gue_lock_job" StmtSetError = "gue_set_error" StmtUnlockJob = "gue_unlock_job" )
Names that are used internally for named prepared statements
const KeyError = "error"
KeyError is the default key for error field
Variables ¶
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") )
var PreparedStatements = map[string]string{ StmtCheckJob: sqlCheckJob, StmtDeleteJob: sqlDeleteJob, StmtInsertJob: sqlInsertJob, StmtLockJob: sqlLockJob, StmtSetError: sqlSetError, StmtUnlockJob: sqlUnlockJob, }
PreparedStatements is the list of the named statements used by the library that should be prepared per connection
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
// Begin starts a transaction with the default transaction mode for the
// current connection.
Begin(ctx context.Context) (Tx, error)
// Release returns c to the pool it was acquired from.
// Once Release has been called, other methods must not be called.
Release()
}
Conn is a PostgreSQL connection handle. It is not safe for concurrent usage. Use ConnPool to manage access to multiple database connections from multiple goroutines.
type ConnPool ¶
type ConnPool interface {
// Acquire takes exclusive use of a connection until it is released.
// Pool is responsible for preparing named statements for every connection it
// returns to the caller.
Acquire(ctx context.Context) (Conn, error)
// Stat returns connection pool statistics
Stat() ConnPoolStat
// 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 ConnPoolStat ¶
type ConnPoolStat struct {
// MaxConnections - max simultaneous connections to use
MaxConnections int
// CurrentConnections - current live connections
CurrentConnections int
// AvailableConnections - unused live connections
AvailableConnections int
}
ConnPoolStat is the connection pool statistics
type Field ¶
type Field struct {
Key string
Value interface{}
}
Field is the simple container for a single log 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(msg string, fields ...Field)
Debug implements Logger.Debug for /dev/null logger
func (NoOpLogger) Error ¶
func (l NoOpLogger) Error(msg string, fields ...Field)
Error implements Logger.Debug for /dev/null logger
func (NoOpLogger) Info ¶
func (l NoOpLogger) Info(msg string, fields ...Field)
Info implements Logger.Debug for /dev/null logger
func (NoOpLogger) With ¶
func (l NoOpLogger) With(fields ...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)
// Query 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 ¶
NewStdLogger instantiates new Logger using stdlib "log". Builder allows to set default set of fields for all the logs being written.
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.