database

package module
v0.0.0-...-0e62f4e Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2017 License: MIT Imports: 11 Imported by: 0

README

database is a package which provides database modelling and mapping. It's a fork
of Jason Moiron's modl pkg. 

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNoRows = sql.ErrNoRows

Functions

func BindVar

func BindVar(i int) string

Returns "?"

func Delete

func Delete(exec Conn, list ...interface{}) (int64, error)

func Exec

func Exec(conn Conn, query string, args ...interface{}) (sql.Result, error)

func FullMatch

func FullMatch(v interface{}) string

func Insert

func Insert(exec Conn, list ...interface{}) error

func MultiExec

func MultiExec(e sqlx.Execer, query string) error

func MultiExecFromFile

func MultiExecFromFile(e sqlx.Execer, filename string) error

func PreMatch

func PreMatch(v interface{}) string

func Prepare

func Prepare(conn Conn, query string) (*sqlx.Stmt, error)

func PrepareIN

func PrepareIN(n int) string

func PrepareIntIN

func PrepareIntIN(args *[]interface{}, w *[]string, value interface{}, table, field string) error

func PrepareWhere

func PrepareWhere(w []string) string

func Put

func Put(exec Conn, isNew bool, list ...interface{}) error

func QueryRowx

func QueryRowx(conn Conn, query string, args ...interface{}) (*sqlx.Row, error)

func Queryx

func Queryx(conn Conn, query string, args ...interface{}) (*sqlx.Rows, error)

func QuoteField

func QuoteField(f string) string

func Scalar

func Scalar(conn Conn, query string, args ...interface{}) (int64, error)

func Select

func Select(exec Conn, dest interface{}, query string, args ...interface{}) error

func SnakeCaseConverter

func SnakeCaseConverter(col string) string

func StmtClose

func StmtClose(conn Conn, stmt *sqlx.Stmt) error

func SuffixMatch

func SuffixMatch(v interface{}) string

func Update

func Update(exec Conn, list ...interface{}) (int64, error)

Types

type Args

type Args map[string]interface{}

func GetFilter

func GetFilter(filters []map[string]interface{}) (filter Args)

func (*Args) Has

func (a *Args) Has(k string) bool

func (*Args) IsTrue

func (a *Args) IsTrue(k string) bool

type ColumnMap

type ColumnMap struct {
	// Column name in db table
	ColumnName string

	// If true, this column is skipped in generated SQL statements
	Transient bool

	// If true, " unique" is added to create table statements.
	Unique bool

	// Passed to Dialect.ToSqlType() to assist in informing the
	// correct column type to map to in CreateTables()
	MaxSize int
	// contains filtered or unexported fields
}

ColumnMap represents a mapping between a Go struct field and a single column in a table. Unique and MaxSize only inform the CreateTables() function and are not used for validation by Insert/Update/Delete/Get.

func (*ColumnMap) SetTransient

func (c *ColumnMap) SetTransient(b bool) *ColumnMap

SetTransient allows you to mark the column as transient. If true this column will be skipped when SQL statements are generated

type Conn

type Conn interface {
	sqlx.Queryer
	sqlx.Execer
	sqlx.Preparer
	Preparex(string) (*sqlx.Stmt, error)
}

type DB

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

func NewDB

func NewDB(dsn string) *DB

type DbMap

type DbMap struct {
	// contains filtered or unexported fields
}
var DefaultDBMap *DbMap

func (*DbMap) AddTable

func (m *DbMap) AddTable(i interface{}, name ...string) *TableMap

AddTable registers the given interface type with modl. The table name will be given the name of the TypeOf(i), lowercased.

This operation is idempotent. If i's type is already mapped, the existing *TableMap is returned

func (*DbMap) AddTableWithName

func (m *DbMap) AddTableWithName(i interface{}, name string) *TableMap

func (*DbMap) TableFor

func (m *DbMap) TableFor(i interface{}) *TableMap

Returns any matching tables for the interface i or nil if not found If i is a slice, then the table is given for the base slice type

func (*DbMap) TableForType

func (m *DbMap) TableForType(t reflect.Type) *TableMap

Returns any matching tables for the type t or nil if not found

type NoKeysErr

type NoKeysErr struct {
	Table *TableMap
}

func (NoKeysErr) Error

func (n NoKeysErr) Error() string

type NullTime

type NullTime struct {
	mysql.NullTime
}

type TableMap

type TableMap struct {
	// Name of database table.
	TableName string
	// contains filtered or unexported fields
}

TableMap represents a mapping between a Go struct and a database table Use dbmap.AddTable() or dbmap.AddTableWithName() to create these

func (*TableMap) ColMap

func (t *TableMap) ColMap(field string) *ColumnMap

ColMap returns the ColumnMap pointer matching the given struct field name. It panics if the struct does not contain a field matching this name.

func (*TableMap) ColumnsStr

func (t *TableMap) ColumnsStr() string

func (*TableMap) ResetSql

func (t *TableMap) ResetSql()

ResetSql removes cached insert/update/select/delete SQL strings associated with this TableMap. Call this if you've modified any column names or the table name itself.

func (*TableMap) SetKeys

func (t *TableMap) SetKeys(isAutoIncr bool, fieldNames ...string) *TableMap

SetKeys lets you specify the fields on a struct that map to primary key columns on the table. If isAutoIncr is set, result.LastInsertId() will be used after INSERT to bind the generated id to the Go struct.

Automatically calls ResetSql() to ensure SQL statements are regenerated.

Jump to

Keyboard shortcuts

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