db

package
v0.0.0-...-60d3e54 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2019 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DSN

func DSN(ci MySQLInfo) string

DSN returns the Data Source Name

Types

type Binder

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

Binder interface defines database field bindings.

type Config

type Config struct {
	DatabaseURI string
}

Config ...

func InitConfig

func InitConfig() (*Config, error)

type DB

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

DB ...

func Connect

func Connect(driver string, datasource string, migrations ...Migration) (*DB, error)

Connect ...

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

func (db *DB) GetConn() *sqlx.DB

GetConn get underlying db connection

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
const (
	MySQL Driver = iota
	Postgres
	Sqlite
)

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

Locker ...

type Migration

type Migration struct {
	Driver   string
	Migrator Migrator
}

Migration needs a drvier name and its migration func

type Migrator

type Migrator interface {
	Migrate(*sql.DB) error
}

Migrator ...

type MigratorFunc

type MigratorFunc func(*sql.DB) error

MigratorFunc represnts a migration for a database

func (MigratorFunc) Migrate

func (m MigratorFunc) Migrate(db *sql.DB) error

Migrate ...

type MySQLInfo

type MySQLInfo struct {
	Username  string
	Password  string
	Name      string
	Hostname  string
	Port      int
	Parameter string
}

MySQLInfo is the details for the database connection

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