Documentation ¶
Index ¶
- type Fake
- func (f *Fake) Begin() (tx driver.Tx, e error)
- func (f *Fake) Close() (err error)
- func (f *Fake) LastQuery() (string, []driver.Value)
- func (f *Fake) Name() string
- func (f *Fake) Open(name string) (con driver.Conn, err error)
- func (f *Fake) Prepare(q string) (driver.Stmt, error)
- func (f *Fake) SetNumInputs(i int)
- type FakeStmt
- type Wrapper
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Fake ¶
type Fake struct {
// contains filtered or unexported fields
}
func NewFake ¶
returns a new database and a fake object that you can use to check, what has been queried. Before running a query, first use SetNumInputs() to set the number of parameters you want to pass to Exec or Query and then run the query. After the Query you may run LastQuery() to get the last query and the last parameters that have been committed to the database.
The fake database is not threadsafe and is not meant to be used in an asynchronous way. Instead, open a new fake database for every goroutine.
func (*Fake) SetNumInputs ¶
type Wrapper ¶
type Wrapper struct { driver.Driver // is called after a new connection (innerConn) has been successfully returned by innerDriver // you have to return a driver.Conn here to the library. in most cases you // will want to return innerConn here HandleOpen func(name string, innerConn driver.Conn) (driver.Conn, error) // is called instead of innerConn.Begin, which you might want to call at some point HandleBegin func(innerConn driver.Conn) (driver.Tx, error) // is called instead of innerConn.Prepare, which you might want to call at some point HandlePrepare func(innerConn driver.Conn, query string) (driver.Stmt, error) // is called instead of innerConn.Close, which you might want to call at some point HandleClose func(innerConn driver.Conn) error // is called instead of innerConn.(driver.Execer), if innerConn may be casted to a driver.Execer // you might want to call conn.Exec at some point HandleExec func(conn driver.Execer, query string, args []driver.Value) (driver.Result, error) // is called instead of innerConn.(driver.Queryer), if innerConn may be casted to a driver.Queryer // you might want to call conn.Query at some point HandleQuery func(conn driver.Queryer, query string, args []driver.Value) (driver.Rows, error) // is called before each method BeforeAll func(conn driver.Conn, event string, data ...interface{}) // is called after each method AfterAll func(conn driver.Conn, event string, data ...interface{}) }
func New ¶
registeres a Wrapper as a database driver with the given name and returns it.
the Wrapper is based on the given inner driver and will forward any method call to the underlying innerDriver
before you open a connection to the Wrapper, you may set the different handlers on it it set, they are called instead of the method of the innerDriver and they are given the underlying driver.Conn, so that you may call it
to open a connection, use it the usual way, e.g.
sql.Open(name, connectString)
where name is the given name here and connectString is the same you would pass to innerDriver