dbx

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2022 License: MIT Imports: 15 Imported by: 0

README

This pkg copied from github.com/drone/drone

Documentation

Index

Constants

View Source
const (
	Sqlite   = "sqlite3"
	Mysql    = "mysql"
	Postgres = "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

View Source
var ErrRecordNotFound = sql.ErrNoRows

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

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

func (db *DB) Migrate(dir string) (*migrate.Migrate, error)

https://github.com/golang-migrate/migrate dir is the ddl sql folder path

func (*DB) MigrateUp

func (db *DB) MigrateUp(dir string) error

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

Jump to

Keyboard shortcuts

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