Documentation ¶
Index ¶
- Constants
- Variables
- func CreateTable(db DB, model interface{}, opt *CreateTableOptions) (*types.Result, error)
- func Delete(db DB, model interface{}) error
- func Insert(db DB, v ...interface{}) error
- func Pager(urlValues url.Values) func(*Query) (*Query, error)
- func Scan(values ...interface{}) valuesModel
- func Select(db DB, model interface{}) error
- func URLValues(urlValues url.Values) func(*Query) (*Query, error)
- func Underscore(s string) string
- func Update(db DB, model interface{}) error
- type ColumnScanner
- type CreateTableOptions
- type DB
- type Discard
- func (Discard) AddModel(_ ColumnScanner) error
- func (Discard) AfterDelete(DB) error
- func (Discard) AfterInsert(DB) error
- func (Discard) AfterQuery(DB) error
- func (Discard) AfterSelect(DB) error
- func (Discard) AfterUpdate(DB) error
- func (Discard) BeforeDelete(DB) error
- func (Discard) BeforeInsert(DB) error
- func (Discard) BeforeUpdate(DB) error
- func (d Discard) NewModel() ColumnScanner
- func (Discard) Reset() error
- func (Discard) ScanColumn(colIdx int, colName string, b []byte) error
- type Field
- func (f *Field) AppendValue(b []byte, strct reflect.Value, quote int) []byte
- func (f *Field) Copy() *Field
- func (f *Field) Has(flag uint8) 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 FormatAppender
- type Formatter
- func (f Formatter) Append(dst []byte, src string, params ...interface{}) []byte
- func (f Formatter) AppendBytes(dst, src []byte, params ...interface{}) []byte
- func (f Formatter) FormatQuery(dst []byte, query string, params ...interface{}) []byte
- func (f *Formatter) SetParam(key string, value interface{})
- type Method
- type Model
- type Query
- func (q *Query) Alias(alias string) *Query
- func (q *Query) Apply(fn func(*Query) (*Query, error)) *Query
- func (q *Query) Column(columns ...string) *Query
- func (q *Query) ColumnExpr(expr string, params ...interface{}) *Query
- func (q *Query) Copy() *Query
- func (q *Query) Count() (int, error)
- func (q *Query) CountEstimate(threshold int) (int, error)
- func (q *Query) DB(db DB) *Query
- func (q *Query) Delete() (*types.Result, error)
- func (q *Query) First() error
- func (q *Query) FormatQuery(dst []byte, query string, params ...interface{}) []byte
- func (q *Query) Group(group string, params ...interface{}) *Query
- func (q *Query) Having(having string, params ...interface{}) *Query
- func (q *Query) Insert(values ...interface{}) (*types.Result, 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) Model(model ...interface{}) *Query
- func (q *Query) New() *Query
- func (q *Query) Offset(n int) *Query
- func (q *Query) OnConflict(s string, params ...interface{}) *Query
- func (q *Query) Order(orders ...string) *Query
- func (q *Query) OrderExpr(order string, params ...interface{}) *Query
- func (q *Query) Relation(name string, apply func(*Query) (*Query, error)) *Query
- func (q *Query) Returning(s string, params ...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) SelectOrInsert(values ...interface{}) (inserted bool, err error)
- func (q *Query) Set(set string, params ...interface{}) *Query
- func (q *Query) Table(tables ...string) *Query
- func (q *Query) TableExpr(expr string, params ...interface{}) *Query
- func (q *Query) Update(values ...interface{}) (*types.Result, error)
- func (q *Query) Where(where string, params ...interface{}) *Query
- func (q *Query) With(name string, subq *Query) *Query
- func (q *Query) WrapWith(name string) *Query
- type QueryAppender
- type QueryFormatter
- type Relation
- type Table
Constants ¶
const ( PrimaryKeyFlag = 1 << iota ForeignKeyFlag NotNullFlag )
const ( AfterQueryHookFlag = 1 << iota AfterSelectHookFlag BeforeInsertHookFlag AfterInsertHookFlag BeforeUpdateHookFlag AfterUpdateHookFlag BeforeDeleteHookFlag AfterDeleteHookFlag )
const ( HasOneRelation = 1 << iota BelongsToRelation HasManyRelation Many2ManyRelation )
Variables ¶
var Tables = newTables()
Functions ¶
func CreateTable ¶
func CreateTable(db DB, model interface{}, opt *CreateTableOptions) (*types.Result, error)
func Underscore ¶
Underscore converts "CamelCasedString" to "camel_cased_string".
Types ¶
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 used to scan column values.
type CreateTableOptions ¶
type CreateTableOptions struct{}
type DB ¶
type DB interface { Model(model ...interface{}) *Query Select(model interface{}) error Insert(model ...interface{}) error Update(model interface{}) error Delete(model interface{}) error Exec(query interface{}, params ...interface{}) (*types.Result, error) ExecOne(query interface{}, params ...interface{}) (*types.Result, error) Query(coll, query interface{}, params ...interface{}) (*types.Result, error) QueryOne(model, query interface{}, params ...interface{}) (*types.Result, error) QueryFormatter }
DB is a common interface for pg.DB and pg.Tx types.
type Discard ¶
type Discard struct{}
func (Discard) AddModel ¶
func (Discard) AddModel(_ ColumnScanner) error
func (Discard) AfterDelete ¶
func (Discard) AfterInsert ¶
func (Discard) AfterQuery ¶
func (Discard) AfterSelect ¶
func (Discard) AfterUpdate ¶
func (Discard) BeforeDelete ¶
func (Discard) BeforeInsert ¶
func (Discard) BeforeUpdate ¶
func (Discard) NewModel ¶
func (d Discard) NewModel() ColumnScanner
type Field ¶
type Field struct { Type reflect.Type GoName string // struct field name, e.g. Id ColName types.Q SQLName string // SQL name, .e.g. id SQLType string Index []int // contains filtered or unexported fields }
func (*Field) AppendValue ¶
type FormatAppender ¶
type FormatAppender interface {
AppendFormat([]byte, QueryFormatter) []byte
}
func Q ¶
func Q(query string, params ...interface{}) FormatAppender
type Formatter ¶
type Formatter struct {
// contains filtered or unexported fields
}
func (Formatter) AppendBytes ¶
func (Formatter) FormatQuery ¶
type Method ¶
type Method struct { Index int // contains filtered or unexported fields }
func (*Method) AppendValue ¶
type Model ¶
type Model interface { ColumnScanner // Reset resets model state. Reset() error // NewModel returns ColumnScanner that is used to scan columns // from the current row. NewModel() ColumnScanner // AddModel adds ColumnScanner to the Collection. AddModel(ColumnScanner) error AfterQuery(DB) error AfterSelect(DB) error BeforeInsert(DB) error AfterInsert(DB) error BeforeUpdate(DB) error AfterUpdate(DB) error BeforeDelete(DB) error AfterDelete(DB) error }
type Query ¶
type Query struct {
// contains filtered or unexported fields
}
func (*Query) Column ¶
Column adds column to the Query quoting it according to PostgreSQL rules. ColumnExpr can be used to bypass quoting restriction.
func (*Query) ColumnExpr ¶
ColumnExpr adds column expression to the Query.
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) FormatQuery ¶
func (*Query) OnConflict ¶
func (*Query) Order ¶
Order adds sort order to the Query quoting column name. OrderExpr can be used to bypass quoting restriction.
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) SelectOrInsert ¶
SelectOrInsert selects the model inserting one if it does not exist.
type QueryAppender ¶
type QueryFormatter ¶
Source Files ¶
- count_estimate.go
- create_table.go
- delete.go
- field.go
- format.go
- hook.go
- insert.go
- join.go
- kinds.go
- model.go
- model_discard.go
- model_scan.go
- model_slice.go
- model_table.go
- model_table_m2m.go
- model_table_many.go
- model_table_slice.go
- model_table_struct.go
- orm.go
- query.go
- relation.go
- select.go
- table.go
- tables.go
- tag.go
- underscore.go
- update.go
- url_values.go
- util.go