Documentation
¶
Index ¶
- Variables
- type DB
- func (d *DB) Begin() (*sql.Tx, error)
- func (d *DB) BeginTx(ctx context.Context, opts *sql.TxOptions) (*sql.Tx, error)
- func (d *DB) Close() error
- func (d *DB) Conn(ctx context.Context) (*sql.Conn, error)
- func (d *DB) DB() *sql.DB
- func (d *DB) Dialect() string
- func (d *DB) DriverName() string
- func (d *DB) ErrorCode(err error) bserr.Code
- func (d *DB) ErrorColumn(err error) string
- func (d *DB) ErrorConstraint(err error) string
- func (d *DB) ErrorTable(err error) string
- func (d *DB) Exec(query string, args ...any) (sql.Result, error)
- func (d *DB) ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error)
- func (d *DB) HasErrorDetails() bool
- func (d *DB) Ping() error
- func (d *DB) PingContext(ctx context.Context) error
- func (d *DB) Prepare(query string) (*sql.Stmt, error)
- func (d *DB) PrepareContext(ctx context.Context, query string) (*sql.Stmt, error)
- func (d *DB) Query(query string, args ...any) (*sql.Rows, error)
- func (d *DB) QueryContext(ctx context.Context, query string, args ...any) (*sql.Rows, error)
- func (d *DB) QueryRow(query string, args ...any) *sql.Row
- func (d *DB) QueryRowContext(ctx context.Context, query string, args ...any) *sql.Row
- func (d *DB) RunInTransaction(ctx context.Context, opts *sql.TxOptions, ...) error
- func (d *DB) SQLDriver() sqldriver.Driver
- func (d *DB) SetConnMaxLifetime(dur time.Duration)
- func (d *DB) SetMaxIdleConns(n int)
- func (d *DB) SetMaxOpenConns(n int)
- func (d *DB) Stats() sql.DBStats
- type DBURLOpener
- type URLMux
Constants ¶
This section is empty.
Variables ¶
var NewDB = newDB
NewDB creates a new instance of DB.
Functions ¶
This section is empty.
Types ¶
type DB ¶
type DB struct {
// contains filtered or unexported fields
}
DB is a driver specific wrapper over the database/sql.DB.
func OpenDB ¶
OpenDB opens the database identified by the URL given. i.e. "mysql://user:password@localhost:3306/database" OpenDB is safe to call from multiple goroutines.
func (*DB) Conn ¶
Conn returns a single connection by either opening a new connection or returning an existing connection from the connection pool.
func (*DB) Dialect ¶
Dialect returns the dialect of the database connection. For the same driver (i.e.: postgres) a dialect may vary depending on the database server (i.e.: postgres, cockroachdb, yugabyte).
func (*DB) ErrorCode ¶
ErrorCode returns the error code of the given error if the driver supports it.
func (*DB) ErrorColumn ¶
ErrorColumn returns the column name of the given error if the driver doesn't support it, it should return an empty string.
func (*DB) ErrorConstraint ¶
ErrorConstraint returns the constraint name of the given error if the driver doesn't support it, it should return an empty string.
func (*DB) ErrorTable ¶
ErrorTable returns the table name of the given error if the driver doesn't support it, it should return an empty string.
func (*DB) Exec ¶
Exec executes a query without returning any rows. The args are for any placeholder parameters in the query.
func (*DB) ExecContext ¶
ExecContext executes a query without returning any rows. The args are for any placeholder parameters in the query.
func (*DB) HasErrorDetails ¶
HasErrorDetails returns true if the driver supports error details, such as column, table and constraint name.
func (*DB) Ping ¶
Ping verifies a connection to the database is still alive, establishing a connection if necessary.
func (*DB) PingContext ¶
PingContext verifies a connection to the database is still alive, establishing a connection if necessary.
func (*DB) Prepare ¶
Prepare creates a prepared statement for later queries or executions. Multiple queries or executions may be run concurrently from the returned statement. The caller must call the statement's Close method when the statement is no longer needed.
func (*DB) PrepareContext ¶
PrepareContext creates a prepared statement for later queries or executions. Multiple queries or executions may be run concurrently from the returned statement. The caller must call the statement's Close method when the statement is no longer needed.
func (*DB) Query ¶
Query executes a query that returns rows, typically a SELECT. The args are for any placeholder parameters in the query.
func (*DB) QueryContext ¶
QueryContext executes a query that returns rows, typically a SELECT. The args are for any placeholder parameters in the query.
func (*DB) QueryRow ¶
QueryRow executes a query that is expected to return at most one row. QueryRow always returns a non-nil value. Errors are deferred until Row's Scan method is called.
func (*DB) QueryRowContext ¶
QueryRowContext executes a query that is expected to return at most one row. QueryRowContext always returns a non-nil value. Errors are deferred until Row's Scan method is called.
func (*DB) RunInTransaction ¶
func (d *DB) RunInTransaction(ctx context.Context, opts *sql.TxOptions, fn func(ctx context.Context, tx *sql.Tx) error) error
RunInTransaction runs the given function in a transaction.
func (*DB) SQLDriver ¶
SQLDriver returns the underlying database/sql/driver.Driver. This is useful for using the database/sql package directly.
func (*DB) SetConnMaxLifetime ¶
SetConnMaxLifetime sets the maximum amount of time a connection may be reused.
func (*DB) SetMaxIdleConns ¶
SetMaxIdleConns sets the maximum number of connections in the idle connection pool.
func (*DB) SetMaxOpenConns ¶
SetMaxOpenConns sets the maximum number of open connections to the database.
type DBURLOpener ¶
type DBURLOpener interface { // OpenDBURL opens a database connection for the given URL. OpenDBURL(ctx context.Context, u *url.URL) (*DB, error) }
DBURLOpener is an interface that allows to open a database connection for a given URL.
type URLMux ¶
type URLMux struct {
// contains filtered or unexported fields
}
URLMux is URL opener multiplexer. It matches the scheme of the URLs against a set of registered schemes and calls the opener that matches the URL's scheme. See https://gocloud.dev/concepts/urls/ for more information.
func DefaultURLMux ¶
func DefaultURLMux() *URLMux
DefaultURLMux returns the URLMux used by OpenSender.
Driver packages can use this to register their SenderURLOpener on the mux.
func (*URLMux) OpenDB ¶
OpenDB calls OpenDBURL with the URL parsed from urlstr. OpenDB is safe to call from multiple goroutines.
func (*URLMux) RegisterDB ¶
func (mux *URLMux) RegisterDB(scheme string, opener DBURLOpener)
RegisterDB registers the opener with the given scheme. If an opener already exists for the scheme, RegisterDB panics.
func (*URLMux) ValidDBScheme ¶
ValidDBScheme returns true iff scheme has been registered for MailProviders.