db

package
v1.10.2 Latest Latest
Warning

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

Go to latest
Published: May 23, 2021 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Sqlite = iota + 1
	Mysql
	Postgres
)

Database driver enums.

Variables

View Source
var ErrOptimisticLock = errors.New("Optimistic Lock Error")

ErrOptimisticLock is returned by if the struct being modified has a Version field and the value is not equal to the current value in the database

Functions

This section is empty.

Types

type Binder

type Binder interface {
	BindNamed(query string, arg interface{}) (string, []interface{}, error)
}

Binder interface defines database field bindings.

type DB

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

DB is a pool of zero or more underlying connections to the drone database.

func Connect

func Connect(driver, datasource string) (*DB, error)

Connect to a database and verify with a ping.

func (*DB) Close

func (db *DB) Close() error

Close closes the database connection.

func (*DB) Driver

func (db *DB) Driver() Driver

Driver returns the name of the SQL driver.

func (*DB) Lock

func (db *DB) Lock(fn func(Execer, Binder) error) error

Lock obtains a write lock to the database (sqlite only) and executes a function. Any error that is returned from the function is returned from the Lock() method.

func (*DB) Update

func (db *DB) Update(fn func(Execer, Binder) error) (err error)

Update executes a function within the context of a read-write managed transaction. If no error is returned from the function then the transaction is committed. If an error is returned then the entire transaction is rolled back. Any error that is returned from the function or returned from the commit is returned from the Update() method.

func (*DB) View

func (db *DB) View(fn func(Queryer, Binder) error) error

View executes a function within the context of a managed read-only transaction. Any error that is returned from the function is returned from the View() method.

type Driver

type Driver int

Driver defines the database driver.

type Execer

type Execer interface {
	Queryer
	Exec(query string, args ...interface{}) (sql.Result, error)
}

Execer interface defines a set of methods for executing read and write commands against the database.

type Locker

type Locker interface {
	Lock()
	Unlock()
	RLock()
	RUnlock()
}

A Locker represents an object that can be locked and unlocked.

type Queryer

type Queryer interface {
	Query(query string, args ...interface{}) (*sql.Rows, error)
	QueryRow(query string, args ...interface{}) *sql.Row
}

Queryer interface defines a set of methods for querying the database.

type Scanner

type Scanner interface {
	Scan(dest ...interface{}) error
}

A Scanner represents an object that can be scanned for values.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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