gmq

package
Version: v0.0.0-...-e60e72f Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2015 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoPrimaryKeyDefined = errors.New("Cannot call this, because there is no primary key defined for the model.")
	ErrNotSupportedCall    = errors.New("Such api cannot be called on this query, e.g. SelectOne on an InsertQuery.")
	ErrNotEnoughColumns    = errors.New("Not enough columns data for Insert/Update.")
	ErrMultipleRowReturned = errors.New("Multiple row returned, but suppose there is only one row.")
	ErrNotDbTxObject       = errors.New("This is not a valid database/sql.Db or sql.Tx")
)
View Source
var Debug bool
View Source
var (
	ErrOptionIsNone = errors.New("Option is not valid.")
)

Functions

func AsBool

func AsBool(rb sql.RawBytes) bool

func AsFloat64

func AsFloat64(rb sql.RawBytes) float64

func AsInt

func AsInt(rb sql.RawBytes) int

func AsInt64

func AsInt64(rb sql.RawBytes) int64

func AsString

func AsString(rb sql.RawBytes) string

func AsTime

func AsTime(rb sql.RawBytes) time.Time

func WithinTx

func WithinTx(db *Db, functor WithinTxFunctor) error

Types

type Column

type Column struct {
	Name  string
	Value interface{}
}

type Db

type Db struct {
	*sql.DB
	// contains filtered or unexported fields
}

func NewDb

func NewDb(db *sql.DB, driverName string) *Db

func Open

func Open(driverName, dataSourceName string) (*Db, error)

func (*Db) Beginx

func (db *Db) Beginx() (*Tx, error)

func (*Db) DriverName

func (db *Db) DriverName() string

type DbTx

type DbTx interface {
	DriverName() string
	Exec(query string, args ...interface{}) (sql.Result, error)
	Prepare(query string) (*sql.Stmt, error)
	Query(query string, args ...interface{}) (*sql.Rows, error)
}

type Filter

type Filter interface {
	SqlString(alias string, driverName string) string
	Params() []interface{}
	And(Filter) Filter
	Or(Filter) Filter
}

func AndFilter

func AndFilter(left, right Filter, others ...Filter) Filter

func InFilter

func InFilter(name string, params []interface{}) Filter

func OrFilter

func OrFilter(left, right Filter, others ...Filter) Filter

func UnitFilter

func UnitFilter(name, op string, param interface{}) Filter

type Option

type Option interface {
	IsDefined() bool
}

type OptionFloat64

type OptionFloat64 interface {
	Option
	Get() (float64, error)
}

func NoneFloat64

func NoneFloat64() OptionFloat64

func SomeFloat64

func SomeFloat64(n float64) OptionFloat64

type OptionInt

type OptionInt interface {
	Option
	Get() (int, error)
}

func NoneInt

func NoneInt() OptionInt

func SomeInt

func SomeInt(n int) OptionInt

type OptionInt64

type OptionInt64 interface {
	Option
	Get() (int64, error)
}

func NoneInt64

func NoneInt64() OptionInt64

func SomeInt64

func SomeInt64(n int64) OptionInt64

type OptionString

type OptionString interface {
	Option
	Get() (string, error)
}

func NoneString

func NoneString() OptionString

func SomeString

func SomeString(n string) OptionString

type OptionTime

type OptionTime interface {
	Option
	Get() (time.Time, error)
}

func NoneTime

func NoneTime() OptionTime

func SomeTime

func SomeTime(n time.Time) OptionTime

type Query

type Query interface {
	String() string
	Exec(dbtx DbTx) (sql.Result, error)
	SelectOne(dbtx DbTx, functor QueryRowVisitor) error
	SelectList(dbtx DbTx, functor QueryRowVisitor) error
	Where(f Filter) Query
	OrderBy(by ...string) Query
	Limit(offsets ...int64) Query
	Page(number, size int) Query
	GroupBy(by ...string) Query
}

func Delete

func Delete(model TableModel) Query

func Insert

func Insert(model TableModel, columns []Column) Query

func Select

func Select(model TableModel, columns []Column) Query

func Update

func Update(model TableModel, columns []Column) Query

type QueryRowVisitor

type QueryRowVisitor func(columns []Column, rb []sql.RawBytes) bool

type TableModel

type TableModel interface {
	Names() (schema, tbl, alias string)
}

type Tx

type Tx struct {
	*sql.Tx
	// contains filtered or unexported fields
}

func (*Tx) DriverName

func (tx *Tx) DriverName() string

type WithinTxFunctor

type WithinTxFunctor func(tx *Tx) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL