dbm

package
v0.12.17 Latest Latest
Warning

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

Go to latest
Published: May 28, 2020 License: MIT Imports: 18 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Config

func Config()

Config read configuration from viper

func Count

func Count(tx *Tx, table string, where interface{}) (count uint64, err error)

Count returns a row count for query

func Fetch

func Fetch(tx *Tx, table string, cols []string, where interface{}, limit, offset uint64, order []string, fn FetchMap) (err error)

Fetch fetch rows and pass through supplied function

func Insert

func Insert(tx *Tx, table string) sq.InsertBuilder

Insert begin new insert statement.

func Migrate

func Migrate(a asset) (err error)

Migrate runs SQL DDL to update tables.

func Ping

func Ping() bool

Ping attempt a connection to database

func QueryContext

func QueryContext(ctx context.Context, txFunc func(*Tx) error) (err error)

QueryContext starts a new database tranaction and executes the supplied func with context.

func Replace

func Replace(
	tx *Tx,
	d DbInfo,
	o interface{},
	where interface{},
	update sq.UpdateBuilder,
	insert sq.InsertBuilder,
) (found bool, err error)

Replace begin new replace statement.

func Transaction

func Transaction(txFunc func(*Tx) error) (err error)

Transaction starts a new database tranaction and executes the supplied func.

func TransactionContext

func TransactionContext(ctx context.Context, txFunc func(*Tx) error) (err error)

TransactionContext starts a new database tranaction and executes the supplied func with context.

func TransactionContinue

func TransactionContinue(TxID string, txFunc func(*Tx, string) error) (err error)

TransactionContinue returns a transaction that can be continued by suppling the TxID that gets passed into the txFunc.

func Transactionx

func Transactionx(txFunc func(*sqlx.Tx) error) (err error)

Transactionx starts a new database tranaction and executes the supplied func.

func Update

func Update(tx *Tx, table string) sq.UpdateBuilder

Update begin new update statement.

Types

type DB

type DB struct {
	Conn             *sql.DB
	DbType           string
	Placeholder      sq.PlaceholderFormat
	Returns          bool
	TxOptionsDisable bool
}

DB database connection and settings

func GetDB

func GetDB(pfx string) (db DB, err error)

GetDB returns a database connection.

func (DB) NewTx

func (db DB) NewTx(ctx context.Context, readonly bool) (tx *Tx, err error)

NewTx create new transaction

func (DB) QueryContext

func (db DB) QueryContext(ctx context.Context, txFunc func(*Tx) error) (err error)

QueryContext starts a new database transction with context and executes the supplied func.

func (DB) Transaction

func (db DB) Transaction(fn func(*Tx) error) error

Transaction starts a new database transction and executes the supplied func.

func (DB) TransactionContext

func (db DB) TransactionContext(ctx context.Context, txFunc func(*Tx) error) (err error)

TransactionContext starts a new database transction with context and executes the supplied func.

func (DB) TransactionContinue

func (db DB) TransactionContinue(TxID string, txFunc func(*Tx, string) error) (err error)

TransactionContinue returns a transaction that can be continued by suppling the TxID that gets passed into the txFunc.

func (DB) Transactionx

func (db DB) Transactionx(txFunc func(*sqlx.Tx) error) (err error)

Transactionx starts a new database tranaction and executes the supplied func.

type DbInfo

type DbInfo struct {
	Table string
	View  string
	Cols  []string
	SCols []string
	GCols []string

	Auto      []string
	Primary   []string
	Secondary []string
	// contains filtered or unexported fields
}

DbInfo database model metadata

func GetDbInfo

func GetDbInfo(o interface{}) DbInfo

GetDbInfo builds a metadata struct

func (DbInfo) Col

func (d DbInfo) Col(column string) (s string, err error)

Col returns the mapped column names

func (DbInfo) ColPanic

func (d DbInfo) ColPanic(column string) string

ColPanic returns the mapped column names will panic if col does not exist

func (DbInfo) GCol

func (d DbInfo) GCol(column string) (s string, err error)

GCol returns the graphql column names

func (DbInfo) Index

func (d DbInfo) Index(column string) (idx int, ok bool)

Index returns the column number

func (*DbInfo) PrimaryEq added in v0.12.13

func (d *DbInfo) PrimaryEq(args ...interface{}) (sq.Eq, error)

func (*DbInfo) PrimaryPanicEq added in v0.12.13

func (d *DbInfo) PrimaryPanicEq(args ...interface{}) sq.Eq

func (DbInfo) SCol

func (d DbInfo) SCol(column string) (s string, err error)

SCol returns the struct column names

func (*DbInfo) SecondaryEq added in v0.12.13

func (d *DbInfo) SecondaryEq(args ...interface{}) (sq.Eq, error)

func (*DbInfo) SecondaryPanicEq added in v0.12.13

func (d *DbInfo) SecondaryPanicEq(args ...interface{}) sq.Eq

func (DbInfo) StructMap

func (d DbInfo) StructMap(o interface{}, cols []string) (fields []string, targets []interface{}, err error)

StructMap accepts a struct and the columns to be set and returns a []interface{} that can be passed to a query scan

type FetchMap

type FetchMap func(row *sql.Rows) error

FetchMap is passed to fetch for assigning to objects.

type Tx

type Tx struct {
	*sql.Tx
	context.Context
	DbType      string
	Placeholder sq.PlaceholderFormat
	Returns     bool
}

Tx database transaction

func (*Tx) Count

func (tx *Tx) Count(table string, where interface{}) (count uint64, err error)

Count returns a row count for query

func (*Tx) Delete

func (tx *Tx) Delete(table string) sq.DeleteBuilder

Delete begin new delete statement.

func (*Tx) Fetch

func (tx *Tx) Fetch(table string, cols []string, where interface{}, limit, offset uint64, order []string, fn FetchMap) (err error)

Fetch fetch rows and pass through supplied function

func (*Tx) Insert

func (tx *Tx) Insert(table string) sq.InsertBuilder

Insert begin new insert statement.

func (*Tx) Replace

func (tx *Tx) Replace(
	d DbInfo,
	o interface{},
	where interface{},
	update sq.UpdateBuilder,
	insert sq.InsertBuilder,
) (found bool, err error)

Replace begin new replace statement.

func (*Tx) Select

func (tx *Tx) Select(cols []string, table string) sq.SelectBuilder

Select begin new select statement.

func (*Tx) Update

func (tx *Tx) Update(table string) sq.UpdateBuilder

Update begin new update statement.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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