sql

package
v0.8.1 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2021 License: Apache-2.0 Imports: 4 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Connect added in v0.8.0

func Connect(db *sql.DB) error

Connect establishes a connection to the database. It will

func Open

func Open(config Config, opts ...Option) (*sql.DB, error)

Open opens a database specified by its config. The config will provide database driver name and a driver-specific data source name.

Types

type Config

type Config interface {
	// DriverName returns the name of the sql database driver.
	DriverName() string

	// DSN returns a connection string.
	DSN() string
}

Config contains the information to connect to an sql database.

type DB

type DB interface {
	Begin(ctx context.Context, opts *TxOptions) (Tx, error)

	Exec(ctx context.Context, query string, args ...interface{}) (Result, error)
	Prepare(ctx context.Context, query string) (Stmt, error)
	Query(ctx context.Context, query string, args ...interface{}) (*Rows, error)
	QueryRow(ctx context.Context, query string, args ...interface{}) *Row

	Close() error
	Ping(ctx context.Context) error
}

type Migration added in v0.8.0

type Migration func(*sql.DB) error

Migration defines a function type to validate and migrate the DB schema.

type Option

type Option interface {
	// contains filtered or unexported methods
}

Option sets options such as instumenting the DB with logging.

func WithMigration added in v0.8.0

func WithMigration(migration Migration) Option

WithMigration returns an Option that performs a migration against the DB.

type Result

type Result = sql.Result

type Row

type Row = sql.Row

type Rows

type Rows = sql.Rows

type Stmt

type Stmt interface {
	Exec(ctx context.Context, args ...interface{}) (Result, error)
	Query(ctx context.Context, args ...interface{}) (*Rows, error)
	QueryRow(ctx context.Context, args ...interface{}) *Row

	Close() error
}

type Tx

type Tx interface {
	Exec(ctx context.Context, query string, args ...interface{}) (Result, error)
	Prepare(ctx context.Context, query string) (Stmt, error)
	Query(ctx context.Context, query string, args ...interface{}) (*Rows, error)
	QueryRow(ctx context.Context, query string, args ...interface{}) *Row

	Commit() error
	Rollback() error

	Stmt(ctx context.Context, stmt Stmt) Stmt
}

type TxOptions

type TxOptions = sql.TxOptions

Directories

Path Synopsis
Package mocksql is a generated GoMock package.
Package mocksql is a generated GoMock package.

Jump to

Keyboard shortcuts

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