driver

package
v0.0.0-...-f5d25ad Latest Latest
Warning

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

Go to latest
Published: Aug 7, 2020 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package driver implements an SQL driver for an add database.

Index

Constants

View Source
const (
	ErrConnectionClosed = Error("connection is closed")
)

Constant errors

Variables

This section is empty.

Functions

This section is empty.

Types

type Conn

type Conn struct {
}

Conn represents a connection to the database. It can be used to prepare and execute statements.

func (*Conn) Begin

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

Begin is deprecated. Use BeginTx instead.

func (*Conn) BeginTx

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

BeginTx creates a transaction that can be either committed or rolled back.

func (*Conn) Close

func (c *Conn) Close() error

Close closes this connection. If a connection is closed, it cannot be used as idle connection in the connection pool and a new connection needs to be established.

func (*Conn) ExecContext

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

ExecContext executes the given query with the given arguments under the given context and returns an exec result. The statement must contain placeholders, one for each element of the given arguments.

func (*Conn) Ping

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

Ping pings the database, failing if the connection is closed or the database failed.

func (*Conn) Prepare

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

Prepare prepares a statement. The returned Stmt is an SQL prepared statement, that has placeholders for parameters that need to be set. Do NOT set parameters directly when creating the statement with this method.

stmt, err := conn.Prepare(`INSERT INTO users VALUES ("jdoe")`) // WRONG

stmt, err := conn.Prepare(`INSERT INTO users VALUES (?)`) // CORRECT
result, err := stmt.Exec("jdoe")

func (*Conn) QueryContext

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

QueryContext executes the given query with the given arguments under the given context and returns a query result. The query must contain placeholders, one for each element of the given arguments.

type Connector

type Connector struct {
	// contains filtered or unexported fields
}

Connector implements a component that is able to open a connection to the database that is remembered by the connector. This connection can then be used to prepare and execute statements.

func (*Connector) Connect

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

Connect opens a connection to the database that the connector is configured to connect to. The opening of the connection pays respect to deadlines or timeouts configured in the context.

func (*Connector) Driver

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

Driver returns the underlying driver, that the connector has been created from.

type Driver

type Driver struct {
}

Driver is the database driver that can communicate with an add database. It will be registered with the name "add".

func (*Driver) Open

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

Open creates a new connector and uses that connector to open a new connection. The context that is used to open the new connection is context.Background().

func (*Driver) OpenConnector

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

OpenConnector creates a connector that can be used to open a connection to a data source. The data source is specified by the given name. A connector can only open connections to his data source.

type Error

type Error string

Error provides constant errors to the driver package.

func (Error) Error

func (e Error) Error() string

type Stmt

type Stmt struct {
}

Stmt is a prepared statement that can be executed. It does not remember values that were passed in.

func (*Stmt) Close

func (s *Stmt) Close() error

Close closes this statement, making it impossible to execute it again.

func (*Stmt) Exec

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

Exec is discouraged. Don't use this, use ExecContext instead.

func (*Stmt) ExecContext

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

ExecContext executes this statement with the given arguments as arguments, with respect to the given context. This should be used for update statements only (alter, update, drop, delete etc.).

func (*Stmt) NumInput

func (s *Stmt) NumInput() int

NumInput returns the amount of argument placeholders that the statement has.

func (*Stmt) Query

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

Query is discouraged. Don't use this, use QueryContext instead.

func (*Stmt) QueryContext

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

QueryContext executes this statement with the given arguments as arguments, with respect to the given context. This should be used for query statements only (select etc.).

Directories

Path Synopsis
Package test contains all integration tests that were created as regression tests for issues that were fixed.
Package test contains all integration tests that were created as regression tests for issues that were fixed.

Jump to

Keyboard shortcuts

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