Documentation ¶
Overview ¶
Package driver implements a driver for Go's database/sql support.
Caveats ¶
Transactions have no effect.
sql.Result.LastInsertID is not implemented.
Index ¶
- Variables
- type Conn
- func (c *Conn) Begin() (driver.Tx, error)
- func (c *Conn) Close() error
- func (c *Conn) DSN() string
- func (c *Conn) Exec(query string, args []driver.Value) (driver.Result, error)
- func (c *Conn) ExecContext(ctx context.Context, query string, args []driver.NamedValue) (driver.Result, error)
- func (c *Conn) Prepare(query string) (driver.Stmt, error)
- func (c *Conn) Query(query string, args []driver.Value) (driver.Rows, error)
- func (c *Conn) QueryContext(ctx context.Context, query string, args []driver.NamedValue) (driver.Rows, error)
- func (c *Conn) Session() sql.Session
- type Connector
- type ContextBuilder
- type DefaultContextBuilder
- type DefaultSessionBuilder
- type Driver
- type Options
- type Provider
- type ProviderWithContextBuilder
- type ProviderWithSessionBuilder
- type Result
- type ResultNotFound
- type Rows
- func (r *Rows) Close() error
- func (r *Rows) ColumnTypeDatabaseTypeName(i int) string
- func (r *Rows) ColumnTypeLength(i int) (int64, bool)
- func (r *Rows) ColumnTypeNullable(i int) (nullable, ok bool)
- func (r *Rows) ColumnTypeScanType(i int) reflect.Type
- func (r *Rows) Columns() []string
- func (r *Rows) Next(dest []driver.Value) error
- type ScanKind
- type SessionBuilder
- type Stmt
- func (s *Stmt) Close() error
- func (s *Stmt) Exec(args []driver.Value) (driver.Result, error)
- func (s *Stmt) ExecContext(ctx context.Context, args []driver.NamedValue) (driver.Result, error)
- func (s *Stmt) NumInput() int
- func (s *Stmt) Query(args []driver.Value) (driver.Rows, error)
- func (s *Stmt) QueryContext(ctx context.Context, args []driver.NamedValue) (driver.Rows, error)
Constants ¶
This section is empty.
Variables ¶
var ErrUnsupportedType = errors.New("unsupported type")
ErrUnsupportedType is returned when a query argument of an unsupported type is passed to a statement
Functions ¶
This section is empty.
Types ¶
type Conn ¶
type Conn struct {
// contains filtered or unexported fields
}
Conn is a connection to a database.
func (*Conn) ExecContext ¶
func (c *Conn) ExecContext(ctx context.Context, query string, args []driver.NamedValue) (driver.Result, error)
ExecContext executes a query that doesn't return rows.
type Connector ¶
type Connector struct {
// contains filtered or unexported fields
}
A Connector represents a driver in a fixed configuration and can create any number of equivalent Conns for use by multiple goroutines.
type ContextBuilder ¶
type ContextBuilder interface { // NewContext constructs a sql.Context with the given conn and options set. NewContext(context.Context, *Conn, ...sql.ContextOption) (*sql.Context, error) }
A ContextBuilder creates SQL contexts.
type DefaultContextBuilder ¶
type DefaultContextBuilder struct{}
DefaultContextBuilder creates basic SQL contexts.
func (DefaultContextBuilder) NewContext ¶
func (DefaultContextBuilder) NewContext(ctx context.Context, conn *Conn, opts ...sql.ContextOption) (*sql.Context, error)
NewContext calls sql.NewContext.
type DefaultSessionBuilder ¶
type DefaultSessionBuilder struct{}
DefaultSessionBuilder creates basic SQL sessions.
func (DefaultSessionBuilder) NewSession ¶
func (DefaultSessionBuilder) NewSession(ctx context.Context, id uint32, conn *Connector) (sql.Session, error)
NewSession calls sql.NewBaseSessionWithClientServer.
type Driver ¶
type Driver struct {
// contains filtered or unexported fields
}
A Driver exposes an engine as a stdlib SQL driver.
type Options ¶
type Options struct { // JSON indicates how JSON row values should be scanned JSON ScanKind }
Options for the driver.
type Provider ¶
type Provider interface { // Resolve determines the server name and DatabaseProvider for the given dsn. // The will create a separate sql.Engine for each "server name" value. Resolve(dsn string, options *Options) (string, sql.DatabaseProvider, error) }
Provider resolves SQL catalogs from DSNs.
Provider can optionally implement ProviderWithSessionBuilder and ProviderWithSessionBuilder.
type ProviderWithContextBuilder ¶
type ProviderWithContextBuilder interface { Provider ContextBuilder }
ProviderWithContextBuilder is a Provider that also provides a base sql.Context. Provider should parse the DSN and use it to adjust the context in NewContext.
type ProviderWithSessionBuilder ¶
type ProviderWithSessionBuilder interface { Provider SessionBuilder }
ProviderWithSessionBuilder is a Provider that also constructs sessions.
type Result ¶
type Result struct {
// contains filtered or unexported fields
}
Result is the result of a query execution.
func (*Result) LastInsertId ¶
LastInsertId returns the row auto-generated ID.
For example: after an INSERT into a table with primary key.
func (*Result) RowsAffected ¶
RowsAffected returns the number of rows affected by the query.
type ResultNotFound ¶
type ResultNotFound struct{}
ResultNotFound is returned when a row iterator does not return a result.
func (*ResultNotFound) LastInsertId ¶
func (r *ResultNotFound) LastInsertId() (int64, error)
LastInsertId returns an error
func (*ResultNotFound) RowsAffected ¶
func (r *ResultNotFound) RowsAffected() (int64, error)
RowsAffected returns an error
type Rows ¶
type Rows struct {
// contains filtered or unexported fields
}
Rows is an iterator over an executed query's results.
func (*Rows) ColumnTypeDatabaseTypeName ¶ added in v0.14.7
func (*Rows) ColumnTypeLength ¶ added in v0.14.7
func (*Rows) ColumnTypeNullable ¶ added in v0.14.7
func (*Rows) ColumnTypeScanType ¶ added in v0.14.7
func (*Rows) Columns ¶
Columns returns the names of the columns. The number of columns of the result is inferred from the length of the slice. If a particular column name isn't known, an empty string should be returned for that entry.
func (*Rows) Next ¶
Next is called to populate the next row of data into the provided slice. The provided slice will be the same size as the Columns() are wide.
Next should return io.EOF when there are no more rows.
The dest should not be written to outside of Next. Care should be taken when closing Rows not to modify a buffer held in dest.
type ScanKind ¶
type ScanKind int
ScanKind indicates how values should be scanned.
const ( // ScanAsString indicates values should be scanned as strings. // // Applies to JSON columns. ScanAsString ScanKind = iota // ScanAsBytes indicates values should be scanned as byte arrays. // // Applies to JSON columns. ScanAsBytes // ScanAsObject indicates values should be scanned as objects. // // Applies to JSON columns. ScanAsObject // ScanAsStored indicates values should not be modified during scanning. // // Applies to JSON columns. ScanAsStored )
type SessionBuilder ¶
type SessionBuilder interface {
NewSession(ctx context.Context, id uint32, conn *Connector) (sql.Session, error)
}
A SessionBuilder creates SQL sessions.
type Stmt ¶
type Stmt struct {
// contains filtered or unexported fields
}
Stmt is a prepared statement.
func (*Stmt) ExecContext ¶
ExecContext executes a query that doesn't return rows, such as an INSERT or UPDATE.
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 ¶
QueryContext executes a query that may return rows, such as a SELECT.