driver

package
v0.10.1-0...-0d403c5 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2021 License: Apache-2.0 Imports: 16 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) Catalog

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

Catalog returns the SQL catalog.

func (*Conn) Close

func (c *Conn) Close() error

Close does nothing.

func (*Conn) Prepare

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

Prepare validates the query and returns a statement.

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

func (c *Connector) Catalog() *sql.Catalog

Catalog returns the SQL catalog.

func (*Connector) Connect

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

Connect returns a connection to the database.

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(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.NewSession.

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) 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(name string, options *Options) (string, *sql.Catalog, error)
}

A Provider resolves SQL catalogs.

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 database's auto-generated ID after, for example, an INSERT into a table with primary key.

NOT IMPLEMENTED

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