driver

package
v0.14.7 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2023 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

Package driver implements a driver for Go's database/sql support.

Caveats

Transactions have no effect.

sql.Result.LastInsertID is not implemented.

Index

Constants

This section is empty.

Variables

View Source
var ErrUnsupportedType = errors.New("unsupported type")

ErrUnsupportedType is returned when a query argument of an unsupported type is passed to a statement

Functions

This section is empty.

Types

type Conn

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

Conn is a connection to a database.

func (*Conn) Begin

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

Begin returns a fake transaction.

func (*Conn) Close

func (c *Conn) Close() error

Close does nothing.

func (*Conn) DSN

func (c *Conn) DSN() string

DSN returns the driver connection string.

func (*Conn) Exec

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

Exec executes a query that doesn't return rows.

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.

func (*Conn) Prepare

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

Prepare validates the query and returns a statement.

func (*Conn) Query

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

Query executes a query that may return rows.

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.

func (*Conn) Session

func (c *Conn) Session() sql.Session

Session returns the SQL session.

type Connector

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

A Connector represents a driver in a fixed configuration and can create any number of equivalent Conns for use by multiple goroutines.

func (*Connector) Connect

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

Connect returns a connection to the database.

func (*Connector) DSN

func (c *Connector) DSN() string

DSN returns the original DSN passed by the client.

func (*Connector) Driver

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

Driver returns the driver.

func (*Connector) Server

func (c *Connector) Server() string

Server returns the server name.

type ContextBuilder

type ContextBuilder interface {
	// NewContext constructs a sql.Context with the given conn and options set.
	NewContext(context.Context, *Conn, ...sql.ContextOption) (*sql.Context, error)
}

A ContextBuilder creates SQL contexts.

type DefaultContextBuilder

type DefaultContextBuilder struct{}

DefaultContextBuilder creates basic SQL contexts.

func (DefaultContextBuilder) NewContext

func (DefaultContextBuilder) NewContext(ctx context.Context, conn *Conn, opts ...sql.ContextOption) (*sql.Context, error)

NewContext calls sql.NewContext.

type DefaultSessionBuilder

type DefaultSessionBuilder struct{}

DefaultSessionBuilder creates basic SQL sessions.

func (DefaultSessionBuilder) NewSession

func (DefaultSessionBuilder) NewSession(ctx context.Context, id uint32, conn *Connector) (sql.Session, error)

NewSession calls sql.NewBaseSessionWithClientServer.

type Driver

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

A Driver exposes an engine as a stdlib SQL driver.

func New

func New(provider Provider, options *Options) *Driver

New returns a driver using the specified provider.

func (*Driver) Close

func (d *Driver) Close() error

func (*Driver) Open

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

Open returns a new connection to the database.

func (*Driver) OpenConnector

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

OpenConnector calls the driver factory and returns a new connector.

type Options

type Options struct {
	// JSON indicates how JSON row values should be scanned
	JSON ScanKind
}

Options for the driver.

type Provider

type Provider interface {
	// Resolve determines the server name and DatabaseProvider for the given dsn.
	// The will create a separate sql.Engine for each "server name" value.
	Resolve(dsn string, options *Options) (string, sql.DatabaseProvider, error)
}

Provider resolves SQL catalogs from DSNs.

Provider can optionally implement ProviderWithSessionBuilder and ProviderWithSessionBuilder.

type ProviderWithContextBuilder

type ProviderWithContextBuilder interface {
	Provider
	ContextBuilder
}

ProviderWithContextBuilder is a Provider that also provides a base sql.Context. Provider should parse the DSN and use it to adjust the context in NewContext.

type ProviderWithSessionBuilder

type ProviderWithSessionBuilder interface {
	Provider
	SessionBuilder
}

ProviderWithSessionBuilder is a Provider that also constructs sessions.

type Result

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

Result is the result of a query execution.

func (*Result) LastInsertId

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

LastInsertId returns the row auto-generated ID.

For example: after an INSERT into a table with primary key.

func (*Result) RowsAffected

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

RowsAffected returns the number of rows affected by the query.

type ResultNotFound

type ResultNotFound struct{}

ResultNotFound is returned when a row iterator does not return a result.

func (*ResultNotFound) LastInsertId

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

LastInsertId returns an error

func (*ResultNotFound) RowsAffected

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

RowsAffected returns an error

type Rows

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

Rows is an iterator over an executed query's results.

func (*Rows) Close

func (r *Rows) Close() error

Close closes the rows iterator.

func (*Rows) ColumnTypeDatabaseTypeName added in v0.14.7

func (r *Rows) ColumnTypeDatabaseTypeName(i int) string

func (*Rows) ColumnTypeLength added in v0.14.7

func (r *Rows) ColumnTypeLength(i int) (int64, bool)

func (*Rows) ColumnTypeNullable added in v0.14.7

func (r *Rows) ColumnTypeNullable(i int) (nullable, ok bool)

func (*Rows) ColumnTypeScanType added in v0.14.7

func (r *Rows) ColumnTypeScanType(i int) reflect.Type

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 ScanKind

type ScanKind int

ScanKind indicates how values should be scanned.

const (
	// ScanAsString indicates values should be scanned as strings.
	//
	// Applies to JSON columns.
	ScanAsString ScanKind = iota

	// ScanAsBytes indicates values should be scanned as byte arrays.
	//
	// Applies to JSON columns.
	ScanAsBytes

	// ScanAsObject indicates values should be scanned as objects.
	//
	// Applies to JSON columns.
	ScanAsObject

	// ScanAsStored indicates values should not be modified during scanning.
	//
	// Applies to JSON columns.
	ScanAsStored
)

type SessionBuilder

type SessionBuilder interface {
	NewSession(ctx context.Context, id uint32, conn *Connector) (sql.Session, error)
}

A SessionBuilder creates SQL sessions.

type Stmt

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

Stmt is a prepared statement.

func (*Stmt) Close

func (s *Stmt) Close() error

Close does nothing.

func (*Stmt) Exec

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.

func (*Stmt) ExecContext

func (s *Stmt) ExecContext(ctx context.Context, args []driver.NamedValue) (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

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

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

func (*Stmt) QueryContext

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

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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