# Functions
AsPopulatable casts an object as populatable.
ColumnNamesCSV returns a csv of column names.
Columns returns the cached column metadata for an object.
ColumnsFromType reflects a reflect.Type into a column collection.
Each iterates over a given result set, calling the rows consumer.
Error returns a new exception by parsing (potentially) a driver error into relevant pieces.
ExecRowsAffected is a helper for use with .Exec() (sql.Result, error) that returns the rows affected.
First returns the first result of a result set to a consumer.
GetConnection adds a given connection to the context.
IgnoreExecResult is a helper for use with .Exec() (sql.Result, error) that ignores the result return.
IsConfigUnset returns if the error is an `ErrConfigUnset`.
IsConnectionClosed returns if the error is an `ErrConnectionClosed`.
IsDurationConversion returns if an error is an `ErrDurationConversion`.
IsPasswordUnset returns if an error is an `ErrPasswordUnset`.
IsPlanCacheKeyUnset returns if the error is an `ErrPlanCacheKeyUnset`.
IsPlanCacheUnset returns if the error is an `ErrConnectionClosed`.
IsPopulatable returns if an object is populatable.
IsSkipQueryLogging returns if we should skip triggering logger listeners for a context.
IsUnsafeSSLMode returns if an error is an `ErrUnsafeSSLMode`.
IsUsernameUnset returns if an error is an `ErrUsernameUnset`.
JSON returns the json representation of a given object for inserts / updates.
LabelRequiredStatementInterceptor returns a statement interceptor that requires a label to be set.
MakeWhereClause returns the sql `where` clause for a column collection, starting at a given index (used in sql $1 parameterization).
MustNew returns a new connection and panics on error.
MustNewConfigFromEnv returns a new config from the environment, it will panic if there is an error.
New returns a new Connection.
NewColumnCollection returns a new empty column collection.
NewColumnCollectionWithPrefix makes a new column collection with a column prefix.
NewColumnFromFieldTag reads the contents of a field tag, ex: `json:"foo" db:"bar,isprimarykey,isserial".
NewConfigFromDSN creates a new config from a DSN.
NewConfigFromEnv returns a new config from the environment.
NewQueryEvent creates a new query event.
NewQueryEventFilter returns a new query event filter.
NewQueryEventListener returns a new listener for query events.
NewQueryStartEvent creates a new query start event.
NewQueryStartEventFilter returns a new query event filter.
NewQueryStartEventListener returns a new listener for query events.
Open opens a connection, testing an error and returning it if not nil, and if nil, opening the connection.
OptCancel sets the context cancel func..
OptConfig sets the config on a connection.
OptConfigFromEnv sets the config on a connection from the environment.
OptConnection sets the underlying driver connection.
OptContext sets a context on an invocation.
OptDatabase sets the connection database.
OptDialect sets the connection dialect.
OptEngine sets the connection engine.
OptHost sets the connection host.
OptInvocationDB is an invocation option that sets the underlying invocation db.
OptInvocationLog sets the invocation logger.
OptInvocationStatementInterceptor sets the invocation statement interceptor.
OptInvocationTracer sets the invocation tracer.
OptLabel sets the Label on the invocation.
OptLog sets the tracer on the connection.
OptPassword sets the connection ssl mode.
OptPort sets the connection port.
OptQueryEventBody sets a field on the query event.
OptQueryEventDatabase sets a field on the query event.
OptQueryEventElapsed sets a field on the query event.
OptQueryEventEngine sets a field on the query event.
OptQueryEventErr sets a field on the query event.
OptQueryEventLabel sets a field on the query event.
OptQueryEventUsername sets a field on the query event.
OptQueryStartEventBody sets a field on the query event.
OptQueryStartEventDatabase sets a field on the query event.
OptQueryStartEventEngine sets a field on the query event.
OptQueryStartEventLabel sets a field on the query event.
OptQueryStartEventUsername sets a field on the query event.
OptSchema sets the connection schema path.
OptSSLMode sets the connection ssl mode.
OptStatementInterceptor sets the statement interceptor on the connection.
OptTimeout sets a command timeout for the invocation.
OptTracer sets the tracer on the connection.
OptTx is an invocation option that sets the invocation transaction.
OptUsername sets the connection ssl mode.
Out reads a given rows set out into an object reference.
OutMany reads a given result set into a given collection.
ParamTokens returns a csv token string in the form "$1,$2,$3...$N" if passed (1, N).
ParamTokensCSV returns a csv token string in the form "$1,$2,$3...$N".
ParseURL no longer needs to be used by clients of this library since supplying a URL as a connection string to sql.Open() is now supported:
sql.Open("postgres", "postgres://bob:[email protected]:5432/mydb?sslmode=verify-full")
It remains exported here for backwards-compatibility.
PoolCloseFinalizer is intended to be used in `defer` blocks with a named `error` return.
PopulateByName sets the values of an object from the values of a sql.Rows object using column names.
PopulateInOrder sets the values of an object in order from a sql.Rows object.
ReflectSliceType returns the inner type of a slice following pointers.
ReflectType retruns the reflect.Type for an object following pointers.
ReflectValue returns the reflect.Value for an object following pointers.
Scan reads the first row from a resultset and scans it to a given set of args.
StatementInterceptorChain nests interceptors such that a list of interceptors is returned as a single function.
TableName returns the mapped table name for a given instance; it will sniff for the `TableName()` function on the type.
TableNameByType returns the table name for a given reflect.Type by instantiating it and calling o.TableName().
TxRollbackFinalizer is intended to be used in `defer` blocks with a named `error` return.
WithConnection adds a given connection to the context.
WithSkipQueryLogging sets the context to skip logger listener triggers.
Zero resets an object.
# Constants
DefaultBufferPoolSize is the default number of buffer pool entries to maintain.
DefaultConnectTimeout is the default connect timeout.
DefaultDatabase is the default database to connect to, we use `postgres` to not pollute the template databases.
"postgres".
DefaultHost is the default database hostname, typically used when developing locally.
DefaultIdleConnections is the default number of idle connections.
DefaultMaxConnections is the default maximum number of connections.
DefaultMaxIdleTime is the default maximum idle time of driver connections.
DefaultMaxLifetime is the default maximum lifetime of driver connections.
DefaultPort is the default postgres port.
DefaultSchema is the default schema to connect to.
EnvVarDatabaseURL is the environment variable used to set the entire database connection string.
EnvVarDBApplicationName is the environment variable used to set the `application_name` configuration parameter in a `lib/pq` connection string.
EnvVarDBBufferPoolSize is the environment variable used to set the buffer pool size on a connection in a connection pool.
EnvVarDBConnectTimeout is is the environment variable used to set the connect timeout in a database connection string.
EnvVarDBDialect is the environment variable used to set the dialect on a connection configuration (e.g.
EnvVarDBEngine is the environment variable used to set the Go `sql` driver.
EnvVarDBHost is the environment variable used to set the host in a database connection string.
EnvVarDBIdleConnections is the environment variable used to set the maximum number of idle connections allowed in a connection pool.
EnvVarDBLockTimeout is is the environment variable used to set the lock timeout on a database config.
EnvVarDBMaxConnections is the environment variable used to set the maximum number of connections allowed in a connection pool.
EnvVarDBMaxIdleTime is the environment variable used to set the maximum time a connection can be idle.
EnvVarDBMaxLifetime is the environment variable used to set the maximum lifetime of a connection in a connection pool.
EnvVarDBName is the environment variable used to set the database name in a database connection string.
EnvVarDBPassword is the environment variable used to set the password in a database connection string.
EnvVarDBPort is the environment variable used to set the port in a database connection string.
EnvVarDBSchema is the environment variable used to set the database schema in a database connection string.
EnvVarDBSSLMode is the environment variable used to set the SSL mode in a database connection string.
EnvVarDBStatementTimeout is is the environment variable used to set the statement timeout on a database config.
EnvVarDBUser is the environment variable used to set the user in a database connection string.
ErrCollectionNotSlice is an error returned by OutMany if the destination is not a slice.
ErrConfigUnset is an exception class.
ErrConnectionAlreadyOpen is an error indicating the db connection was already opened.
ErrConnectionClosed is an error indicating the db connection hasn't been opened.
ErrDestinationNotStruct is an exception class.
ErrDurationConversion is the error returned when a duration cannot be converted to multiple of some base (e.g.
ErrInvalidIDs is an error returned by Get if the ids aren't provided.
ErrNetwork is a grouped error for network issues.
ErrNoPrimaryKey is an error returned by a number of operations that depend on a primary key.
ErrPasswordUnset is an error indicating there is no password set in a prodlike environment.
ErrPlanCacheKeyUnset is an error indicating the plan cache key is unset.
ErrPlanCacheUnset is an error indicating the statement cache is unset.
ErrRowsNotColumnsProvider is returned by `PopulateByName` if you do not pass in `sql.Rows` as the scanner.
ErrTooManyRows is returned by Out if there is more than one row returned by the query.
ErrUnsafeSSLMode is an error indicating unsafe ssl mode in production.
ErrUsernameUnset is an error indicating there is no username set in a prodlike environment.
Logger flags.
Logger flags.
SSLModeAllow is an ssl mode.
SSLModeDisable is an ssl mode.
SSLModePrefer is an ssl mode.
SSLModeRequire is an ssl mode.
SSLModeVerifyCA is an ssl mode.
SSLModeVerifyFull is an ssl mode.
# Variables
DialectCockroachDB is the crdb dialect.
DialectPostgres is the postgres dialect.
DialectRedshift is the redshift dialect.
DialectUnknown is an unknown dialect, typically inferred as DialectPostgres.
Errors.
# Structs
Column represents a single field on a struct that is mapped to the database.
ColumnCollection represents the column metadata for a given struct.
Config is a set of connection config options.
Connection is the basic wrapper for connection parameters and saves a reference to the created sql.Connection.
Invocation is a specific operation against a context.
Query is the intermediate result of a query.
QueryEvent represents a database query.
QueryStartEvent represents the start of a database query.
# Interfaces
Any is a loose type alias to interface{}.
ColumnMetaCacheKeyProvider is a provider for a column meta key.
ColumnsProvider is a type that can return columns.
DatabaseMapped is the interface that any objects passed into database mapped methods like Create, Update, Delete, Get, GetAll etc.
DB is a handler for queries.
Populatable is an interface that you can implement if your object is read often and is performance critical.
Rows provides the relevant fields to populate by name.
Scanner is a type that can scan into variadic values.
TableNameProvider is a type that implements the TableName() function.
TraceFinisher is a type that can finish traces.
Tracer is a type that can implement traces.
# Type aliases
Annotations is a loose type alias to map[string]string.
Dialect is the flavor of sql.
InvocationOption is an option for invocations.
Labels is a loose type alias to map[string]string.
Option is an option for database connections.
QueryEventOption mutates a query event.
QueryStartEventOption mutates a query start event.
RowsConsumer is the function signature that is called from within Each().
StatementInterceptor is an interceptor for statements.
Values is a loose type alias to map[string]interface{}.