Documentation ¶
Index ¶
- Variables
- 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)
- func (c *Conn) ExecContext(ctx context.Context, query string, args []driver.NamedValue) (driver.Result, error)
- func (c *Conn) NamedValue(args []driver.Value) []driver.NamedValue
- func (c *Conn) Ping(ctx context.Context) error
- func (c *Conn) Prepare(query string) (driver.Stmt, error)
- func (c *Conn) PrepareContext(ctx context.Context, 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)
- type Connector
- type Driver
- type Result
- type Rows
- type Stmt
- func (s *Stmt) Close() error
- func (s *Stmt) Exec(args []driver.Value) (driver.Result, error)deprecated
- func (s *Stmt) ExecContext(ctx context.Context, args []driver.Value) (driver.Result, error)
- func (s *Stmt) NumInput() int
- func (s *Stmt) Query(args []driver.Value) (driver.Rows, error)deprecated
- func (s *Stmt) QueryContext(ctx context.Context, args []driver.Value) (driver.Rows, error)
- type Tx
Constants ¶
This section is empty.
Variables ¶
var (
ErrConnClosed = fmt.Errorf("%w connection is closed", ErrDummy)
)
var ErrDummy = errors.New("dummy")
var (
ErrInvalidDSN = fmt.Errorf("%w invalid dsn", ErrDummy)
)
var (
ErrRowsClosed = errors.New("rows closed")
)
var (
ErrStmtClosed = fmt.Errorf("%w statement is closed", ErrDummy)
)
var (
ErrTxDone = fmt.Errorf("%w transaction is done", ErrDummy)
)
Functions ¶
This section is empty.
Types ¶
type Conn ¶
Conn - connection to dummydb.
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 that doesn't return rows, such as an INSERT or UPDATE.
func (*Conn) NamedValue ¶
func (c *Conn) NamedValue(args []driver.Value) []driver.NamedValue
NamedValue convert []driver.Value into []driver.NamedValue.
func (*Conn) PrepareContext ¶
PrepareContext returns a prepared statement, bound to this connection. context is for the preparation of the statement, it must not store the context within the statement itself.
type Connector ¶
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{}
Driver of dummy 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 Result ¶
func (*Result) LastInsertId ¶
LastInsertId returns the database's internal ID of the last inserted row. This is typically not useful to applications. A dummy implementation is returned.
func (*Result) RowsAffected ¶
RowsAffected returns the number of rows affected by the query. A dummy implementation is returned.
type Rows ¶
type Rows struct {
Closed bool
}
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 Stmt ¶
func (*Stmt) Close ¶
Close closes the statement.
Drivers must ensure all network calls made by Close do not block indefinitely (e.g. apply a timeout).
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.