Overview
- 作り方確認
sample
- とりあえずコード
package stubs
import (
"context"
"database/sql"
"database/sql/driver"
"fmt"
)
func init() {
sql.Register("stubs", &stubDriver{})
}
type Rows struct{}
func (r *Rows) Columns() []string {
return []string{}
}
func (r *Rows) Close() error {
return nil
}
func (r *Rows) Next(_ []driver.Value) error {
return nil
}
type Conn struct{}
func (dc *Conn) Query(_ string, _ []driver.Value) (driver.Rows, error) {
return nil, nil
}
func (dc *Conn) QueryContext(ctx context.Context, _ string, _ []driver.NamedValue) (driver.Rows, error) {
return nil, fmt.Errorf("test")
}
func (dc *Conn) Prepare(_ string) (driver.Stmt, error) {
return nil, nil
}
func (dc *Conn) Begin() (driver.Tx, error) {
return nil, nil
}
func (dc *Conn) Close() error {
return nil
}
type stubDriver struct {
}
func (d *stubDriver) Open(_ string) (driver.Conn, error) {
return &Conn{}, nil
}
refernece