Documentation ¶
Index ¶
- Constants
- Variables
- func ContainsOperation(list []Operation, item Operation) bool
- func ConvertNamedValuesToValues(namedValues []driver.NamedValue) []driver.Value
- func Register(name string, hooks ...Hook) (string, error)
- type Configuration
- type Connection
- func (c *Connection) Begin() (driver.Tx, error)
- func (c *Connection) BeginTx(ctx context.Context, opts driver.TxOptions) (driver.Tx, error)
- func (c *Connection) Close() error
- func (c *Connection) Exec(query string, args []driver.Value) (driver.Result, error)
- func (c *Connection) ExecContext(ctx context.Context, query string, args []driver.NamedValue) (driver.Result, error)
- func (c *Connection) Ping(ctx context.Context) error
- func (c *Connection) Prepare(query string) (driver.Stmt, error)
- func (c *Connection) PrepareContext(ctx context.Context, query string) (driver.Stmt, error)
- func (c *Connection) Query(query string, args []driver.Value) (driver.Rows, error)
- func (c *Connection) QueryContext(ctx context.Context, query string, args []driver.NamedValue) (driver.Rows, error)
- func (c *Connection) ResetSession(ctx context.Context) error
- type Connector
- type DefaultDriverFactory
- type DefaultDriverRegistry
- type Driver
- type DriverFactory
- type DriverRegistry
- type Hook
- type HookEvent
- func (e *HookEvent) Arguments() any
- func (e *HookEvent) Error() error
- func (e *HookEvent) LastInsertId() int64
- func (e *HookEvent) Latency() (time.Duration, error)
- func (e *HookEvent) Operation() Operation
- func (e *HookEvent) Query() string
- func (e *HookEvent) RowsAffected() int64
- func (e *HookEvent) SetError(err error) *HookEvent
- func (e *HookEvent) SetLastInsertId(lastInsertId int64) *HookEvent
- func (e *HookEvent) SetRowsAffected(rowsAffected int64) *HookEvent
- func (e *HookEvent) Start() *HookEvent
- func (e *HookEvent) Stop() *HookEvent
- func (e *HookEvent) System() System
- type Operation
- type Statement
- func (s *Statement) Close() error
- func (s *Statement) Exec(args []driver.Value) (driver.Result, error)
- func (s *Statement) ExecContext(ctx context.Context, args []driver.NamedValue) (driver.Result, error)
- func (s *Statement) NumInput() int
- func (s *Statement) Query(args []driver.Value) (driver.Rows, error)
- func (s *Statement) QueryContext(ctx context.Context, args []driver.NamedValue) (driver.Rows, error)
- type System
- type Transaction
Constants ¶
const DriverRegistrationPrefix = "yokai"
Variables ¶
var ( GlobalDriverRegistry DriverRegistry GlobalDriverFactory DriverFactory )
Functions ¶
func ContainsOperation ¶
ContainsOperation returns true if a given Operation item is contained id a list of Operation.
func ConvertNamedValuesToValues ¶
func ConvertNamedValuesToValues(namedValues []driver.NamedValue) []driver.Value
ConvertNamedValuesToValues converts a list of driver.NamedValue into a list of driver.Value.
Types ¶
type Configuration ¶
type Configuration struct {
// contains filtered or unexported fields
}
Configuration is the SQL components (driver, connector, connection, etc) configuration.
func NewConfiguration ¶
func NewConfiguration(system System, hooks ...Hook) *Configuration
NewConfiguration returns a new Configuration.
func (*Configuration) Hooks ¶
func (c *Configuration) Hooks() []Hook
Hooks returns the Configuration list of Hook.
func (*Configuration) System ¶
func (c *Configuration) System() System
System returns the Configuration System.
type Connection ¶
type Connection struct {
// contains filtered or unexported fields
}
Connection is a SQL driver connection wrapping a driver.Conn.
func NewConnection ¶
func NewConnection(base driver.Conn, configuration *Configuration) *Connection
NewConnection returns a new Connection.
func (*Connection) Begin ¶
func (c *Connection) Begin() (driver.Tx, error)
Begin starts a transaction and returns a driver.Tx.
func (*Connection) ExecContext ¶
func (c *Connection) ExecContext(ctx context.Context, query string, args []driver.NamedValue) (driver.Result, error)
ExecContext executes a query for a context and returns a driver.Result.
func (*Connection) Ping ¶
func (c *Connection) Ping(ctx context.Context) error
Ping pings a connection for context.
func (*Connection) Prepare ¶
func (c *Connection) Prepare(query string) (driver.Stmt, error)
Prepare prepares a query and returns a driver.Stmt.
func (*Connection) PrepareContext ¶
PrepareContext prepares a query for a context and returns a driver.Stmt.
func (*Connection) QueryContext ¶
func (c *Connection) QueryContext(ctx context.Context, query string, args []driver.NamedValue) (driver.Rows, error)
QueryContext executes a query for a context and returns a driver.Rows.
func (*Connection) ResetSession ¶
func (c *Connection) ResetSession(ctx context.Context) error
ResetSession resets a connection session for context.
type Connector ¶
type Connector struct {
// contains filtered or unexported fields
}
Connector is a SQL driver connector wrapping a driver.Connector.
func NewConnector ¶
NewConnector returns a new Connector.
type DefaultDriverFactory ¶
type DefaultDriverFactory struct{}
DefaultDriverFactory is the default DriverFactory implementation.
func NewDefaultDriverFactory ¶
func NewDefaultDriverFactory() *DefaultDriverFactory
NewDefaultDriverFactory returns a new DefaultDriverFactory.
type DefaultDriverRegistry ¶
type DefaultDriverRegistry struct {
// contains filtered or unexported fields
}
DefaultDriverRegistry is the default DriverRegistry implementation.
func NewDefaultDriverRegistry ¶
func NewDefaultDriverRegistry() *DefaultDriverRegistry
NewDefaultDriverRegistry returns a new DefaultDriverRegistry.
func (*DefaultDriverRegistry) Add ¶
func (r *DefaultDriverRegistry) Add(name string, driver *Driver) (err error)
Add adds and register a given Driver for a name.
func (*DefaultDriverRegistry) Get ¶
func (r *DefaultDriverRegistry) Get(name string) (*Driver, error)
Get returns a registered driver for a given name.
func (*DefaultDriverRegistry) Has ¶
func (r *DefaultDriverRegistry) Has(name string) bool
Has returns true is a driver is already registered for a given name.
type Driver ¶
type Driver struct {
// contains filtered or unexported fields
}
Driver is a SQL driver wrapping a driver.Driver.
func NewDriver ¶
func NewDriver(base driver.Driver, configuration *Configuration) *Driver
NewDriver returns a new Driver.
func (*Driver) Configuration ¶
func (d *Driver) Configuration() *Configuration
Configuration returns the Configuration of the Driver.
type DriverFactory ¶
DriverFactory is the interface for Driver factories.
type DriverRegistry ¶
type DriverRegistry interface { Has(name string) bool Add(name string, driver *Driver) error Get(name string) (*Driver, error) }
DriverRegistry is the interface for Driver registries.
type Hook ¶
type Hook interface { Before(context.Context, *HookEvent) context.Context After(context.Context, *HookEvent) }
Hook is the interface for database hooks.
type HookEvent ¶
type HookEvent struct {
// contains filtered or unexported fields
}
HookEvent is representing an event provided to a database Hook.
func NewHookEvent ¶
func NewHookEvent(system System, operation Operation, query string, arguments interface{}) *HookEvent
NewHookEvent returns a new HookEvent.
func (*HookEvent) LastInsertId ¶
LastInsertId returns the HookEvent database last inserted id.
func (*HookEvent) Latency ¶
Latency returns the HookEvent latency (duration between start and end times).
func (*HookEvent) RowsAffected ¶
RowsAffected returns the HookEvent database affected rows.
func (*HookEvent) SetLastInsertId ¶
SetLastInsertId sets the HookEvent database last inserted id.
func (*HookEvent) SetRowsAffected ¶
SetRowsAffected sets the HookEvent database affected rows.
type Operation ¶
type Operation string
Operation is an enum for the supported database operations.
const ( UnknownOperation Operation = "unknown" ConnectionBeginOperation Operation = "connection:begin" ConnectionBeginTxOperation Operation = "connection:begin-tx" ConnectionExecOperation Operation = "connection:exec" ConnectionExecContextOperation Operation = "connection:exec-context" ConnectionQueryOperation Operation = "connection:query" ConnectionQueryContextOperation Operation = "connection:query-context" ConnectionPrepareOperation Operation = "connection:prepare" ConnectionPrepareContextOperation Operation = "connection:prepare-context" ConnectionPingOperation Operation = "connection:ping" ConnectionResetSessionOperation Operation = "connection:reset-session" ConnectionCloseOperation Operation = "connection:close" StatementExecOperation Operation = "statement:exec" StatementExecContextOperation Operation = "statement:exec-context" StatementQueryOperation Operation = "statement:query" StatementQueryContextOperation Operation = "statement:query-context" TransactionCommitOperation Operation = "transaction:commit" TransactionRollbackOperation Operation = "transaction:rollback" )
func FetchOperation ¶
FetchOperation returns an Operation for a given name.
func FetchOperations ¶ added in v1.1.0
FetchOperations returns a list of Operation for a given list of names.
type Statement ¶
type Statement struct {
// contains filtered or unexported fields
}
Statement is a SQL driver statement wrapping a driver.Stmt.
func NewStatement ¶
func NewStatement(base driver.Stmt, ctx context.Context, query string, configuration *Configuration) *Statement
NewStatement returns a new Statement.
func (*Statement) ExecContext ¶
func (s *Statement) ExecContext(ctx context.Context, args []driver.NamedValue) (driver.Result, error)
ExecContext executes a statement for a context and returns a driver.Result.
func (*Statement) QueryContext ¶
func (s *Statement) QueryContext(ctx context.Context, args []driver.NamedValue) (driver.Rows, error)
QueryContext executes a statement for a context and returns a driver.Rows.
type System ¶
type System string
System is an enum for the supported database systems.
func FetchSystem ¶
FetchSystem returns a System for a given name.
type Transaction ¶
type Transaction struct {
// contains filtered or unexported fields
}
Transaction is a SQL driver transaction wrapping a driver.Tx.
func NewTransaction ¶
func NewTransaction(base driver.Tx, ctx context.Context, configuration *Configuration) *Transaction
NewTransaction returns a new Transaction.
func (*Transaction) Rollback ¶
func (t *Transaction) Rollback() error
Rollback rollbacks the Transaction.