Documentation
¶
Index ¶
- Variables
- func ConvertToNamedValues(values []driver.Value) []driver.NamedValue
- func NewSqlDb(store SqlStore, dsn string) *sql.DB
- type Conn
- func (c *Conn) Begin() (driver.Tx, error)deprecated
- func (c *Conn) BeginTx(ctx context.Context, opts driver.TxOptions) (driver.Tx, error)
- func (c *Conn) Close() error
- func (c *Conn) Exec(query string, args []driver.Value) (driver.Result, error)deprecated
- func (c *Conn) ExecContext(ctx context.Context, query string, args []driver.NamedValue) (driver.Result, error)
- func (c *Conn) IsValid() bool
- func (c *Conn) Prepare(query string) (driver.Stmt, error)
- func (c *Conn) Query(query string, args []driver.Value) (driver.Rows, error)deprecated
- func (c *Conn) QueryContext(ctx context.Context, query string, args []driver.NamedValue) (driver.Rows, error)
- func (c *Conn) Release()
- func (c *Conn) ResetSession(ctx context.Context) error
- type ConnStmt
- func (s *ConnStmt) Close() error
- func (s *ConnStmt) Exec(args []driver.Value) (driver.Result, error)deprecated
- func (s *ConnStmt) ExecContext(ctx context.Context, args []driver.NamedValue) (driver.Result, error)
- func (s *ConnStmt) NumInput() int
- func (s *ConnStmt) Query(args []driver.Value) (driver.Rows, error)deprecated
- func (s *ConnStmt) QueryContext(ctx context.Context, args []driver.NamedValue) (driver.Rows, error)
- type ConnTx
- type Controller
- func (c *Controller) Close() error
- func (c *Controller) Execute(ctx context.Context) error
- func (c *Controller) GetControllerInfo() *controller.Info
- func (c *Controller) GetSqlStore(ctx context.Context) (SqlStore, error)
- func (c *Controller) HandleDirective(ctx context.Context, inst directive.Instance) ([]directive.Resolver, error)
- type Driver
- type DriverConnector
- type LookupSqlStore
- type LookupSqlStoreValue
- type SqlConn
- type SqlOps
- type SqlStore
- type SqlTransaction
Constants ¶
This section is empty.
Variables ¶
var ErrEmptySqlDbId = errors.New("empty sql db id")
ErrEmptySqlDbId is returned if the sql db id is empty.
Functions ¶
func ConvertToNamedValues ¶
func ConvertToNamedValues(values []driver.Value) []driver.NamedValue
ConvertToNamedValues converts the driver.Value slice to a driver.NamedValue slice.
Types ¶
type Conn ¶
type Conn struct {
// contains filtered or unexported fields
}
Conn implements sql/driver.Conn with a SqlStore.
The Conn can service a single query at a time. When starting a new SQL transaction and/or when executing the first statement, the Conn will call SqlStore.NewSqlTransaction to build a SqlTransaction handle.
When rolling back a sql transaction and/or resetting the conn, if non-nil, SqlTransaction.Discard is called to discard the transaction.
Because there can be multiple underlying sql Conn instances as transactions are built and discarded, the database name (USE) must be remembered by Conn.
func (*Conn) BeginTx ¶
BeginTx starts and returns a new transaction. If the context is canceled by the user the sql package will call Tx.Rollback before discarding and closing the connection.
This must check opts.Isolation to determine if there is a set isolation level. If the driver does not support a non-default level and one is set or if there is a non-default isolation level that is not supported, an error must be returned.
This must also check opts.ReadOnly to determine if the read-only value is true to either set the read-only transaction property if supported or return an error if it is not supported.
func (*Conn) Close ¶
Close invalidates and potentially stops any current prepared statements and transactions, marking this connection as no longer in use.
Because the sql package maintains a free pool of connections and only calls Close when there's a surplus of idle connections, it shouldn't be necessary for drivers to do their own connection caching.
Drivers must ensure all network calls made by Close do not block indefinitely (e.g. apply a timeout).
func (*Conn) ExecContext ¶
func (c *Conn) ExecContext(ctx context.Context, query string, args []driver.NamedValue) (driver.Result, error)
ExecContext executes a query in the Exec mode.
func (*Conn) IsValid ¶
IsValid is called prior to placing the connection into the connection pool. The connection will be discarded if false is returned.
type ConnStmt ¶
type ConnStmt struct {
// contains filtered or unexported fields
}
ConnStmt implements driver.Stmt with a Conn. Construct with conn.Prepare.
func (*ConnStmt) Close ¶
Close closes the statement.
As of Go 1.1, a Stmt will not be closed if it's in use by any queries.
Drivers must ensure all network calls made by Close do not block indefinitely (e.g. apply a timeout).
func (*ConnStmt) ExecContext ¶
func (s *ConnStmt) ExecContext(ctx context.Context, args []driver.NamedValue) (driver.Result, error)
ExecContext executes a query that doesn't return rows, such as an INSERT or UPDATE.
ExecContext must honor the context timeout and return when it is canceled.
func (*ConnStmt) NumInput ¶
NumInput returns the number of placeholder parameters.
If NumInput returns >= 0, the sql package will sanity check argument counts from callers and return errors to the caller before the statement's Exec or Query methods are called.
NumInput may also return -1, if the driver doesn't know its number of placeholders. In that case, the sql package will not sanity check Exec or Query argument counts.
func (*ConnStmt) QueryContext ¶
QueryContext executes a query that may return rows, such as a SELECT.
QueryContext must honor the context timeout and return when it is canceled.
type ConnTx ¶
type ConnTx struct {
// contains filtered or unexported fields
}
ConnTx implements driver.Tx attached to a Conn. NOTE: you should use BeginTx to construct this.
type Controller ¶
type Controller struct {
// contains filtered or unexported fields
}
Controller is a common implementation of a SQL engine controller.
func NewController ¶
func NewController( info *controller.Info, dbID string, execute func(ctx context.Context, ctr *ccontainer.CContainer[*SqlStore]) error, ) *Controller
NewController constructs a common SQL engine controller.
func (*Controller) Close ¶
func (c *Controller) Close() error
Close releases any resources used by the controller.
func (*Controller) Execute ¶
func (c *Controller) Execute(ctx context.Context) error
Execute executes the controller.
func (*Controller) GetControllerInfo ¶
func (c *Controller) GetControllerInfo() *controller.Info
GetControllerInfo returns information about the controller.
func (*Controller) GetSqlStore ¶
func (c *Controller) GetSqlStore(ctx context.Context) (SqlStore, error)
GetSqlStore waits for the store to be built.
func (*Controller) HandleDirective ¶
func (c *Controller) HandleDirective( ctx context.Context, inst directive.Instance, ) ([]directive.Resolver, error)
HandleDirective asks if the handler can resolve the directive.
type Driver ¶
type Driver struct {
// contains filtered or unexported fields
}
Driver implements sql.Driver with a common SqlStore.
func NewDriver ¶
NewDriver constructs a new Driver from a SqlStore.
dsn is the default database name string.
func (*Driver) Connect ¶
Connect returns a connection to the database. Connect may return a cached connection (one previously closed), but doing so is unnecessary; the sql package maintains a pool of idle connections for efficient re-use.
The provided context.Context is for dialing purposes only (see net.DialContext) and should not be stored or used for other purposes. A default timeout should still be used when dialing as a connection pool may call Connect asynchronously to any query.
The returned connection is only used by one goroutine at a time.
func (*Driver) Driver ¶
Driver returns the underlying Driver of the Connector, mainly to maintain compatibility with the Driver method on sql.DB.
func (*Driver) Open ¶
Open returns a new connection to the database. The name is a string in a driver-specific format.
Open may return a cached connection (one previously closed), but doing so is unnecessary; the sql package maintains a pool of idle connections for efficient re-use.
The returned connection is only used by one goroutine at a time.
type DriverConnector ¶
type DriverConnector struct {
// contains filtered or unexported fields
}
DriverConnector implements sql.Connector with a Driver.
func NewDriverConnector ¶
func NewDriverConnector(driver *Driver, dsn string) *DriverConnector
NewDriverConnector constructs a new DriverConnector from a SqlStore.
func (*DriverConnector) Connect ¶
Connect returns a connection to the database. Connect may return a cached connection (one previously closed), but doing so is unnecessary; the sql package maintains a pool of idle connections for efficient re-use.
The provided context.Context is for dialing purposes only (see net.DialContext) and should not be stored or used for other purposes. A default timeout should still be used when dialing as a connection pool may call Connect asynchronously to any query.
The returned connection is only used by one goroutine at a time.
func (*DriverConnector) Driver ¶
func (d *DriverConnector) Driver() driver.Driver
Driver returns the underlying Driver of the Connector, mainly to maintain compatibility with the Driver method on sql.DB.
type LookupSqlStore ¶
type LookupSqlStore interface {
// Directive indicates LookupSqlStore is a directive.
directive.Directive
// LookupSqlStoreId returns the sql db id to lookup.
LookupSqlStoreId() string
}
LookupSqlStore is a directive to lookup a SQL store.
func NewLookupSqlStore ¶
func NewLookupSqlStore(dbID string) LookupSqlStore
NewLookupSqlStore constructs a new LookupSqlStore directive.
type LookupSqlStoreValue ¶
type LookupSqlStoreValue = SqlStore
LookupSqlStoreValue is the result type for LookupSqlStore. Multiple results may be pushed to the directive.
func ExLookupSqlStore ¶
func ExLookupSqlStore( ctx context.Context, b bus.Bus, dbID string, returnIfIdle bool, valDisposeCb func(), ) (LookupSqlStoreValue, directive.Instance, directive.Reference, error)
ExLookupSqlStore waits for the sql db to be resolved. if returnIfIdle is set and the directive becomes idle, returns nil, nil, nil,
type SqlConn ¶
type SqlConn interface {
driver.Conn
driver.ConnBeginTx
driver.SessionResetter
driver.Validator
driver.ExecerContext
driver.QueryerContext
}
SqlConn is the set of interfaces that Conn implements.
type SqlOps ¶
type SqlOps interface {
driver.Execer //nolint:staticcheck
driver.ExecerContext
driver.Queryer //nolint:staticcheck
driver.QueryerContext
}
SqlOps are operations on the SQL DB transaction.
type SqlStore ¶
type SqlStore interface {
// NewSqlTransaction starts a new SqlStore transaction.
//
// If !write, the transaction should be read-only.
// dsn is the default database name for the transaction.
NewSqlTransaction(
ctx context.Context,
write bool,
dsn string,
) (SqlTransaction, error)
}
SqlStore is a transactional MySQL store.
type SqlTransaction ¶
type SqlTransaction interface {
// Tx is the transaction interface.
tx.Tx
// GetReadOnly returns if the transaction is read-only.
GetReadOnly() bool
// GetSqlOps returns the sql operations interface.
// see the comments in the stdlib sql/driver package for more information.
GetSqlOps(ctx context.Context) (SqlOps, error)
}
SqlTransaction is a SQL DB transaction.