connection

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2021 License: Apache-2.0 Imports: 7 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EscapeArgs

func EscapeArgs(query string, args []interface{}) (string, []interface{}, error)

EscapeArgs return the query and args with the argument placeholder escaped.

Types

type DB

type DB interface {
	// Clone returns a stateful copy of this connection.
	Clone() DB
	// QueryIter returns closure allowing to load/fetch roads one by one.
	QueryIter(ctx context.Context, statement string, fields []string, args ...interface{}) (ResultFetchIter, error)
	// EQueryIter is QueryIter but will use EscapeArgs.
	EQueryIter(ctx context.Context, statement string, fields []string, args ...interface{}) (ResultFetchIter, error)
	// Query returns a closure that allows fetching of the results of the query.
	Query(ctx context.Context, statement string, fields []string, args ...interface{}) (ResultFetch, error)
	// EQuery is Query but will use EscapeArgs.
	EQuery(ctx context.Context, statement string, fields []string, args ...interface{}) (ResultFetch, error)
	// QueryPrimitive returns a closure that allows fetching of the results of a query to a
	// slice of primitives.
	QueryPrimitive(ctx context.Context, statement string, field string, args ...interface{}) (ResultFetch, error)
	// EQueryPrimitive is QueryPrimitive but will use EscapeArgs
	EQueryPrimitive(ctx context.Context, statement string, field string, args ...interface{}) (ResultFetch, error)
	// Raw ins intended to be an all raw query that runs statement with args and tries
	// to retrieve the results into fields without much magic whatsoever.
	Raw(ctx context.Context, statement string, args []interface{}, fields ...interface{}) error
	// ERaw is Raw but will use EscapeArgs
	ERaw(ctx context.Context, statement string, args []interface{}, fields ...interface{}) error
	// Exec is intended for queries that do not yield results (data modifiers)
	Exec(ctx context.Context, statement string, args ...interface{}) error
	// ExecResult is intended for queries that modify data and respond with how many rows were affected.
	ExecResult(ctx context.Context, statement string, args ...interface{}) (int64, error)
	// EExec is Exec but will use EscapeArgs.
	EExec(ctx context.Context, statement string, args ...interface{}) error
	// BeginTransaction returns a new DB that will use the transaction instead of the basic conn.
	BeginTransaction(ctx context.Context) (DB, error)
	// CommitTransaction commits the transaction
	CommitTransaction(ctx context.Context) error
	// RollbackTransaction rolls back the transaction
	RollbackTransaction(ctx context.Context) error
	// IsTransaction indicates if the DB is in the middle of a transaction.
	IsTransaction() bool
	// Set allows to change settings for the current transaction.
	Set(ctx context.Context, set string) error
	// BulkInsert Inserts in the most efficient way possible a lot of data.
	BulkInsert(ctx context.Context, tableName string, columns []string, values [][]interface{}) (execError error)
}

DB represents an active database connection.

type DatabaseHandler

type DatabaseHandler interface {
	// Open must be able to connect to the handled engine and return a db.
	Open(context.Context, *Information) (DB, error)
}

DatabaseHandler represents the boundary with a db.

type Information

type Information struct {
	Database        string
	User            string
	Password        string
	ConnMaxLifetime *time.Duration

	CustomDial func(ctx context.Context, network, addr string) (net.Conn, error)

	// MaxConnPoolConns where applies will be used to determine the maximum amount of connections
	// a pool can have.
	MaxConnPoolConns int

	Logger   logging.Logger
	LogLevel LogLevel
}

Information contains all required information to create a connection into a db. Copied almost verbatim from https://godoc.org/github.com/jackc/pgx#ConnConfig

type LogLevel added in v0.1.14

type LogLevel string

LogLevel is the type for the potential log levels a db can have

var (
	// Trace sets log level to trace.
	Trace LogLevel = "trace"
	// Debug sets log level to debug.
	Debug LogLevel = "debug"
	// Info sets log level to info.
	Info LogLevel = "info"
	// Warn sets log level to warn.
	Warn LogLevel = "warn"
	// Error sets log level to error.
	Error LogLevel = "error"
	// None sets log level to none.
	None LogLevel = "none"
)

type ResultFetch

type ResultFetch func(interface{}) error

ResultFetch represents a closure that receives a receiver struct and wil assign all the results it is expected that it receives a slice.

type ResultFetchIter

type ResultFetchIter func(interface{}) (bool, func(), error)

ResultFetchIter represents a closure that receives a receiver struct that will get the results assigned for one row and returns a tuple of `next item present`, `close function`, error

Jump to

Keyboard shortcuts

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