Documentation
¶
Index ¶
- func NewDriver(d driver.Driver, logger Logger) driver.Driver
- func NewUID() string
- type Conn
- func (c *Conn) Begin() (_ driver.Tx, err error)deprecated
- func (c *Conn) BeginTx(ctx context.Context, opts driver.TxOptions) (_ driver.Tx, err error)
- func (c *Conn) CheckNamedValue(namedValue *driver.NamedValue) (err error)
- func (c *Conn) Close() (err error)
- func (c *Conn) Exec(query string, args []driver.Value) (_ driver.Result, err error)deprecated
- func (c *Conn) ExecContext(ctx context.Context, query string, args []driver.NamedValue) (_ driver.Result, err error)
- func (c *Conn) Ping(ctx context.Context) (err error)
- func (c *Conn) Prepare(query string) (_ driver.Stmt, err error)
- func (c *Conn) PrepareContext(ctx context.Context, query string) (_ driver.Stmt, err error)
- func (c *Conn) Query(query string, args []driver.Value) (_ driver.Rows, err error)deprecated
- func (c *Conn) QueryContext(ctx context.Context, query string, args []driver.NamedValue) (_ driver.Rows, err error)
- func (c *Conn) ResetSession(ctx context.Context) (err error)
- type Connector
- type Driver
- type Logger
- type Stmt
- func (s *Stmt) CheckNamedValue(namedValue *driver.NamedValue) (err error)
- func (s *Stmt) Close() (err error)
- func (s *Stmt) Exec(args []driver.Value) (_ driver.Result, err error)deprecated
- func (s *Stmt) ExecContext(ctx context.Context, args []driver.NamedValue) (_ driver.Result, err error)
- func (s *Stmt) NumInput() int
- func (s *Stmt) Query(args []driver.Value) (_ driver.Rows, err error)deprecated
- func (s *Stmt) QueryContext(ctx context.Context, args []driver.NamedValue) (_ driver.Rows, err error)
- type Tx
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Conn ¶
type Conn struct {
// contains filtered or unexported fields
}
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) CheckNamedValue ¶
func (c *Conn) CheckNamedValue(namedValue *driver.NamedValue) (err error)
func (*Conn) Exec
deprecated
Execer is an optional interface that may be implemented by a Conn.
If a Conn implements neither ExecerContext nor Execer, the sql package's DB.Exec will first prepare a query, execute the statement, and then close the statement.
Exec may return ErrSkip.
Deprecated: Drivers should implement ExecerContext instead.
func (*Conn) ExecContext ¶
func (c *Conn) ExecContext(ctx context.Context, query string, args []driver.NamedValue) (_ driver.Result, err error)
ExecerContext is an optional interface that may be implemented by a Conn.
If a Conn does not implement ExecerContext, the sql package's DB.Exec will fall back to Execer; if the Conn does not implement Execer either, DB.Exec will first prepare a query, execute the statement, and then close the statement.
ExecContext may return ErrSkip.
ExecContext must honor the context timeout and return when the context is canceled.
func (*Conn) Ping ¶
Pinger is an optional interface that may be implemented by a Conn.
If a Conn does not implement Pinger, the sql package's DB.Ping and DB.PingContext will check if there is at least one Conn available.
If Conn.Ping returns ErrBadConn, DB.Ping and DB.PingContext will remove the Conn from pool.
func (*Conn) PrepareContext ¶
ConnPrepareContext enhances the Conn interface with context.
func (*Conn) Query
deprecated
Queryer is an optional interface that may be implemented by a Conn.
If a Conn implements neither QueryerContext nor Queryer, the sql package's DB.Query will first prepare a query, execute the statement, and then close the statement.
Query may return ErrSkip.
Deprecated: Drivers should implement QueryerContext instead.
func (*Conn) QueryContext ¶
func (c *Conn) QueryContext(ctx context.Context, query string, args []driver.NamedValue) (_ driver.Rows, err error)
QueryerContext is an optional interface that may be implemented by a Conn.
If a Conn does not implement QueryerContext, the sql package's DB.Query will fall back to Queryer; if the Conn does not implement Queryer either, DB.Query will first prepare a query, execute the statement, and then close the statement.
QueryContext may return ErrSkip.
QueryContext must honor the context timeout and return when the context is canceled.
type Connector ¶
type Connector struct {
// contains filtered or unexported fields
}
Connector represents a driver in a fixed configuration.
func (*Connector) 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.
type Driver ¶
type Driver struct {
// contains filtered or unexported fields
}
Driver is the interface that must be implemented by a database.
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.
func (*Driver) OpenConnector ¶
If a Driver implements DriverContext, then sql.DB will call OpenConnector to obtain a Connector and then invoke that Connector's Connect method to obtain each needed connection, instead of invoking the Driver's Open method for each connection. The two-step sequence allows drivers to parse the name just once and also provides access to per-Conn contexts.
OpenConnector must parse the name in the same format that Driver.Open parses the name parameter.
type Logger ¶
type Logger struct { *slog.Logger BaseLevel slog.Level BasePrefix string StmtPrefix string TxPrefix string WithDuration bool WarnErrSkip bool }
type Stmt ¶
type Stmt struct {
// contains filtered or unexported fields
}
func (*Stmt) CheckNamedValue ¶
func (s *Stmt) CheckNamedValue(namedValue *driver.NamedValue) (err error)
CheckNamedValue is called before passing arguments to the driver and is called in place of any ColumnConverter. CheckNamedValue must do type validation and conversion as appropriate for the driver.
func (*Stmt) 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 (*Stmt) ExecContext ¶
func (s *Stmt) ExecContext(ctx context.Context, args []driver.NamedValue) (_ driver.Result, err 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 (*Stmt) 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 (*Stmt) QueryContext ¶
func (s *Stmt) QueryContext(ctx context.Context, args []driver.NamedValue) (_ driver.Rows, err error)
QueryContext executes a query that may return rows, such as a SELECT.
QueryContext must honor the context timeout and return when it is canceled.