Documentation ¶
Index ¶
- Variables
- type ContextExecable
- type Database
- func (ld *Database) Begin() (*LoggingTxn, error)
- func (ld *Database) BeginTx(ctx context.Context, opts *sql.TxOptions) (*LoggingTxn, error)
- func (db *Database) Child(versionTable string, upgradeTable UpgradeTable, log DatabaseLogger) *Database
- func (db *Database) Configure(cfg bridgeconfig.DatabaseConfig) error
- func (db *Database) Upgrade() error
- type DatabaseLogger
- type Dialect
- type Execable
- type LoggingExecable
- func (le *LoggingExecable) Exec(query string, args ...interface{}) (sql.Result, error)
- func (le *LoggingExecable) ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
- func (le *LoggingExecable) Query(query string, args ...interface{}) (*sql.Rows, error)
- func (le *LoggingExecable) QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)
- func (le *LoggingExecable) QueryRow(query string, args ...interface{}) *sql.Row
- func (le *LoggingExecable) QueryRowContext(ctx context.Context, query string, args ...interface{}) *sql.Row
- type LoggingTxn
- type Scannable
- type Transaction
- type UpgradeTable
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrForeignTables = fmt.Errorf("the database contains foreign tables")
View Source
var ErrNotOwned = fmt.Errorf("the database is owned by")
View Source
var ErrUnsupportedDatabaseVersion = fmt.Errorf("unsupported database schema version")
Functions ¶
This section is empty.
Types ¶
type ContextExecable ¶
type Database ¶
type Database struct { RawDB *sql.DB Owner string VersionTable string Log DatabaseLogger Dialect Dialect UpgradeTable UpgradeTable IgnoreForeignTables bool IgnoreUnsupportedDatabase bool // contains filtered or unexported fields }
func NewFromConfig ¶
func NewFromConfig(owner string, cfg bridgeconfig.DatabaseConfig, logger DatabaseLogger) (*Database, error)
func NewWithDialect ¶
func (*Database) Begin ¶
func (ld *Database) Begin() (*LoggingTxn, error)
func (*Database) Child ¶
func (db *Database) Child(versionTable string, upgradeTable UpgradeTable, log DatabaseLogger) *Database
func (*Database) Configure ¶
func (db *Database) Configure(cfg bridgeconfig.DatabaseConfig) error
type DatabaseLogger ¶
type DatabaseLogger interface { QueryTiming(ctx context.Context, method, query string, args []interface{}, duration time.Duration) WarnUnsupportedVersion(current, latest int) PrepareUpgrade(current, latest int) DoUpgrade(from, to int, message string) // Deprecated: legacy warning method, return errors instead Warn(msg string, args ...interface{}) }
var NoopLogger DatabaseLogger = &noopLogger{}
func MauLogger ¶
func MauLogger(log maulogger.Logger) DatabaseLogger
func ZeroLogger ¶
func ZeroLogger(log zerolog.Logger) DatabaseLogger
func ZeroLoggerPtr ¶
func ZeroLoggerPtr(log *zerolog.Logger) DatabaseLogger
type LoggingExecable ¶
type LoggingExecable struct { UnderlyingExecable Execable // contains filtered or unexported fields }
LoggingExecable is a wrapper for anything with database Exec methods (i.e. sql.Conn, sql.DB and sql.Tx) that can preprocess queries (e.g. replacing $ with ? on SQLite) and log query durations.
func (*LoggingExecable) Exec ¶
func (le *LoggingExecable) Exec(query string, args ...interface{}) (sql.Result, error)
func (*LoggingExecable) ExecContext ¶
func (*LoggingExecable) Query ¶
func (le *LoggingExecable) Query(query string, args ...interface{}) (*sql.Rows, error)
func (*LoggingExecable) QueryContext ¶
func (*LoggingExecable) QueryRow ¶
func (le *LoggingExecable) QueryRow(query string, args ...interface{}) *sql.Row
func (*LoggingExecable) QueryRowContext ¶
type LoggingTxn ¶
type LoggingTxn struct { LoggingExecable UnderlyingTx *sql.Tx // contains filtered or unexported fields }
func (*LoggingTxn) Commit ¶
func (lt *LoggingTxn) Commit() error
func (*LoggingTxn) Rollback ¶
func (lt *LoggingTxn) Rollback() error
type Transaction ¶
type UpgradeTable ¶
type UpgradeTable []upgrade
func (*UpgradeTable) Register ¶
func (ut *UpgradeTable) Register(from, to int, message string, fn upgradeFunc)
func (*UpgradeTable) RegisterFS ¶
func (ut *UpgradeTable) RegisterFS(fs fullFS)
func (*UpgradeTable) RegisterFSPath ¶
func (ut *UpgradeTable) RegisterFSPath(fs fullFS, dir string)
Click to show internal directories.
Click to hide internal directories.