0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

db driver 作成方法

Posted at

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

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?