dummy

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 5, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrConnClosed = fmt.Errorf("%w connection is closed", ErrDummy)
)
View Source
var ErrDummy = errors.New("dummy")
View Source
var (
	ErrInvalidDSN = fmt.Errorf("%w invalid dsn", ErrDummy)
)
View Source
var (
	ErrRowsClosed = errors.New("rows closed")
)
View Source
var (
	ErrStmtClosed = fmt.Errorf("%w statement is closed", ErrDummy)
)
View Source
var (
	ErrTxDone = fmt.Errorf("%w transaction is done", ErrDummy)
)

Functions

This section is empty.

Types

type Conn

type Conn struct {
	Closed bool
	Result *Result
	Rows   *Rows
	Stmt   *Stmt
	Tx     *Tx
}

Conn - connection to dummydb.

func (*Conn) Begin deprecated

func (c *Conn) Begin() (driver.Tx, error)

Begin starts and returns a new transaction.

Deprecated: Drivers should implement BeginTx instead (or additionally).

func (*Conn) BeginTx

func (c *Conn) BeginTx(ctx context.Context, opts driver.TxOptions) (driver.Tx, error)

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

func (c *Conn) Close() error

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) Exec

func (c *Conn) Exec(query string, args []driver.Value) (driver.Result, error)

Exec executes a query that doesn't return rows, such as an INSERT or UPDATE.

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) Ping

func (c *Conn) Ping(ctx context.Context) error

Ping - check database connection alive.

func (*Conn) Prepare

func (c *Conn) Prepare(query string) (driver.Stmt, error)

Prepare returns a prepared statement, bound to this connection.

func (*Conn) PrepareContext

func (c *Conn) PrepareContext(ctx context.Context, query string) (driver.Stmt, error)

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.

func (*Conn) Query

func (c *Conn) Query(query string, args []driver.Value) (driver.Rows, error)

Query executes a query that may return rows, such as a SELECT.

func (*Conn) QueryContext

func (c *Conn) QueryContext(ctx context.Context, query string, args []driver.NamedValue) (driver.Rows, error)

QueryContext executes a query that may return rows, such as a SELECT.

type Connector

type Connector struct {
	DSN  string
	Conn *Conn
}

func (*Connector) Connect

func (c *Connector) Connect(ctx context.Context) (driver.Conn, error)

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.

func (*Connector) Driver

func (v *Connector) Driver() driver.Driver

Driver returns the underlying Driver of the Connector, mainly to maintain compatibility with the Driver method on sql.DB.

type Driver

type Driver struct{}

Driver of dummy db.

func (Driver) Open

func (d Driver) Open(dsn string) (driver.Conn, error)

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.

func (Driver) OpenConnector

func (d Driver) OpenConnector(dsn string) (driver.Connector, error)

OpenConnector must parse the name in the same format that Driver.Open parses the name parameter.

type Result

type Result struct {
	InsertID int64
	Affected int64
}

func (*Result) LastInsertId

func (r *Result) LastInsertId() (int64, error)

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

func (r *Result) RowsAffected() (int64, error)

RowsAffected returns the number of rows affected by the query. A dummy implementation is returned.

type Rows

type Rows struct {
	Closed bool
}

func (*Rows) Close

func (r *Rows) Close() error

Close closes the rows iterator.

func (*Rows) Columns

func (r *Rows) Columns() []string

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

func (r *Rows) Next(dest []driver.Value) error

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

type Stmt struct {
	Closed bool
	Result *Result
	Rows   *Rows
}

func (*Stmt) Close

func (s *Stmt) Close() error

Close closes the statement.

Drivers must ensure all network calls made by Close do not block indefinitely (e.g. apply a timeout).

func (*Stmt) Exec deprecated

func (s *Stmt) Exec(args []driver.Value) (driver.Result, error)

Exec executes a query that doesn't return rows, such as an INSERT or UPDATE.

Deprecated: Drivers should implement ExecContext instead (or additionally).

func (*Stmt) ExecContext

func (s *Stmt) ExecContext(ctx context.Context, args []driver.Value) (driver.Result, error)

ExecContext executes a query that doesn't return rows, such as an INSERT or UPDATE.

func (*Stmt) NumInput

func (s *Stmt) NumInput() int

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) Query deprecated

func (s *Stmt) Query(args []driver.Value) (driver.Rows, error)

Query executes a query that may return rows, such as a SELECT.

Deprecated: Drivers should implement QueryContext instead (or additionally).

func (*Stmt) QueryContext

func (s *Stmt) QueryContext(ctx context.Context, args []driver.Value) (driver.Rows, error)

QueryContext executes a query that may return rows, such as a SELECT.

type Tx

type Tx struct {
	Closed bool
}

Tx implements transaction.

func (*Tx) Commit

func (tx *Tx) Commit() error

Begin implements the DB interface. Commit implements the Tx interface.

func (*Tx) Rollback

func (tx *Tx) Rollback() error

Rollback implements the Tx interface.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL