Documentation ¶
Index ¶
- Constants
- Variables
- func Create(db dber, v interface{}) error
- func Delete(db dber, v interface{}) error
- func F(field string, params ...interface{}) types.F
- func Q(query string, params ...interface{}) types.Q
- func Scan(values ...interface{}) valuesModel
- func Select(db dber, model interface{}) error
- func Underscore(s string) string
- func Update(db dber, v interface{}) error
- type Collection
- type ColumnScanner
- type Discard
- type Field
- func (f *Field) AppendValue(b []byte, strct reflect.Value, quote int) []byte
- func (f *Field) Copy() *Field
- func (f *Field) Has(flag int8) bool
- func (f *Field) IsEmpty(strct reflect.Value) bool
- func (f *Field) OmitEmpty(strct reflect.Value) bool
- func (f *Field) ScanValue(strct reflect.Value, b []byte) error
- func (f *Field) Value(strct reflect.Value) reflect.Value
- type Formatter
- type Join
- type Method
- type Model
- type Query
- func (q *Query) Column(columns ...string) *Query
- func (q *Query) ColumnExpr(expr string, params ...interface{}) *Query
- func (q *Query) Count() (int, error)
- func (q *Query) CountEstimate(threshold int) (int, error)
- func (q *Query) Create(values ...interface{}) (*types.Result, error)
- func (q *Query) Delete() (*types.Result, error)
- func (q *Query) First() error
- func (q *Query) Join(join string, params ...interface{}) *Query
- func (q *Query) Last() error
- func (q *Query) Limit(n int) *Query
- func (q *Query) Offset(n int) *Query
- func (q *Query) OnConflict(s string, params ...interface{}) *Query
- func (q *Query) Order(order string, params ...interface{}) *Query
- func (q *Query) Returning(columns ...interface{}) *Query
- func (q *Query) Select(values ...interface{}) error
- func (q *Query) SelectAndCount(values ...interface{}) (count int, err error)
- func (q *Query) SelectAndCountEstimate(threshold int) (count int, err error)
- func (q *Query) SelectOrCreate(values ...interface{}) (created bool, err error)
- func (q *Query) Set(set string, params ...interface{}) *Query
- func (q *Query) Table(names ...string) *Query
- func (q *Query) Update() (*types.Result, error)
- func (q *Query) UpdateValues(values map[string]interface{}) (*types.Result, error)
- func (q *Query) Where(where string, params ...interface{}) *Query
- type QueryAppender
- type Relation
- type SliceModel
- type StructModel
- func (m *StructModel) AddJoin(j Join) *Join
- func (StructModel) AddModel(_ ColumnScanner) error
- func (m *StructModel) AppendParam(dst []byte, name string) ([]byte, bool)
- func (m *StructModel) Bind(bind reflect.Value)
- func (m *StructModel) GetJoin(name string) *Join
- func (m *StructModel) GetJoins() []Join
- func (m *StructModel) Join(name string) *Join
- func (m *StructModel) NewModel() ColumnScanner
- func (m *StructModel) Path() []string
- func (m *StructModel) Root() reflect.Value
- func (m *StructModel) ScanColumn(colIdx int, colName string, b []byte) error
- func (m *StructModel) Table() *Table
- func (m *StructModel) Value() reflect.Value
- type Table
- type TableModel
Constants ¶
const ( PrimaryKeyFlag = 1 << iota ForeignKeyFlag = 1 << iota NullFlag = 1 << iota FormatFlag = 1 << iota )
Variables ¶
var Tables = newTables()
Functions ¶
func Underscore ¶
Underscore converts "CamelCasedString" to "camel_cased_string".
Types ¶
type Collection ¶
type Collection interface { // NewModel returns ColumnScanner that is used to scan columns // from the current row. NewModel() ColumnScanner // AddModel adds ColumnScanner to the Collection. AddModel(ColumnScanner) error }
Collection is a set of models mapped to database rows.
type ColumnScanner ¶
type ColumnScanner interface { // Scan assigns a column value from a row. // // An error should be returned if the value can not be stored // without loss of information. ScanColumn(colIdx int, colName string, b []byte) error }
ColumnScanner is an interface used to scan column.
type Discard ¶
type Discard struct{}
func (Discard) AddModel ¶
func (Discard) AddModel(_ ColumnScanner) error
func (Discard) NewModel ¶
func (d Discard) NewModel() ColumnScanner
type Field ¶
type Field struct { GoName string // struct field name, e.g. Id SQLName string // SQL name, .e.g. id ColName types.Q // escaped column name, e.g. "id" Index []int // contains filtered or unexported fields }
func (*Field) AppendValue ¶
type Formatter ¶
type Formatter struct {
// contains filtered or unexported fields
}
func (Formatter) AppendBytes ¶
type Join ¶
type Join struct { BaseModel TableModel JoinModel TableModel Rel *Relation SelectAll bool Columns []string }
func (*Join) AppendColumns ¶
type Method ¶
type Method struct { Index int // contains filtered or unexported fields }
func (*Method) AppendValue ¶
type Model ¶
type Model interface { Collection ColumnScanner }
type Query ¶
type Query struct {
// contains filtered or unexported fields
}
func (*Query) ColumnExpr ¶
func (*Query) Count ¶
Count returns number of rows matching the query using count aggregate function.
func (*Query) CountEstimate ¶
CountEstimate uses EXPLAIN to get estimated number of rows matching the query. If that number is bigger than the threshold it returns the estimation. Otherwise it executes another query using count aggregate function and returns the result.
func (*Query) OnConflict ¶
func (*Query) SelectAndCount ¶
SelectAndCount runs Select and Count in two separate goroutines, waits for them to finish and returns the result.
func (*Query) SelectAndCountEstimate ¶
SelectAndCountEstimate runs Select and CountEstimate in two separate goroutines, waits for them to finish and returns the result.
func (*Query) SelectOrCreate ¶
SelectOrCreate selects the model creating one if it does not exist.
func (*Query) UpdateValues ¶
Update updates the model using provided values.
type QueryAppender ¶
type SliceModel ¶
type SliceModel struct { StructModel // contains filtered or unexported fields }
func (*SliceModel) Bind ¶
func (m *SliceModel) Bind(bind reflect.Value)
func (*SliceModel) Join ¶
func (m *SliceModel) Join(name string) *Join
func (*SliceModel) NewModel ¶
func (m *SliceModel) NewModel() ColumnScanner
func (*SliceModel) Value ¶
func (m *SliceModel) Value() reflect.Value
type StructModel ¶
type StructModel struct {
// contains filtered or unexported fields
}
TODO: extract AppendParam to separate struct and use it in Formatter
func NewStructModel ¶
func NewStructModel(v interface{}) (*StructModel, error)
func (*StructModel) AddJoin ¶
func (m *StructModel) AddJoin(j Join) *Join
func (StructModel) AddModel ¶
func (StructModel) AddModel(_ ColumnScanner) error
func (*StructModel) AppendParam ¶
func (m *StructModel) AppendParam(dst []byte, name string) ([]byte, bool)
func (*StructModel) Bind ¶
func (m *StructModel) Bind(bind reflect.Value)
func (*StructModel) GetJoin ¶
func (m *StructModel) GetJoin(name string) *Join
func (*StructModel) GetJoins ¶
func (m *StructModel) GetJoins() []Join
func (*StructModel) Join ¶
func (m *StructModel) Join(name string) *Join
func (*StructModel) NewModel ¶
func (m *StructModel) NewModel() ColumnScanner
func (*StructModel) Path ¶
func (m *StructModel) Path() []string
func (*StructModel) Root ¶
func (m *StructModel) Root() reflect.Value
func (*StructModel) ScanColumn ¶
func (m *StructModel) ScanColumn(colIdx int, colName string, b []byte) error
func (*StructModel) Table ¶
func (m *StructModel) Table() *Table
func (*StructModel) Value ¶
func (m *StructModel) Value() reflect.Value
type Table ¶
type TableModel ¶
type TableModel interface { Table() *Table Model Join(string) *Join GetJoin(string) *Join GetJoins() []Join AddJoin(Join) *Join Root() reflect.Value Path() []string Bind(reflect.Value) Value() reflect.Value // contains filtered or unexported methods }
func NewTableModel ¶
func NewTableModel(v interface{}) (TableModel, error)