pg.v5: gopkg.in/pg.v5/orm Index | Files

package orm

import "gopkg.in/pg.v5/orm"

Index

Package 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 table_params.go tables.go tag.go update.go url_values.go util.go

Constants

const (
    PrimaryKeyFlag = 1 << iota
    ForeignKeyFlag
    NotNullFlag
    UniqueFlag
)
const (
    AfterQueryHookFlag = 1 << iota
    AfterSelectHookFlag
    BeforeInsertHookFlag
    AfterInsertHookFlag
    BeforeUpdateHookFlag
    AfterUpdateHookFlag
    BeforeDeleteHookFlag
    AfterDeleteHookFlag
)
const (
    HasOneRelation = 1 << iota
    BelongsToRelation
    HasManyRelation
    Many2ManyRelation
)

Variables

var Tables = newTables()

func CreateTable Uses

func CreateTable(db DB, model interface{}, opt *CreateTableOptions) (*types.Result, error)

func Delete Uses

func Delete(db DB, model interface{}) error

func Insert Uses

func Insert(db DB, v ...interface{}) error

func Pager Uses

func Pager(urlValues url.Values, defaultLimit int) func(*Query) (*Query, error)

Pager sets LIMIT and OFFSET from the URL values:

- ?limit=10 - sets q.Limit(10), max limit is 1000.
- ?page=5 - sets q.Offset((page - 1) * limit), max offset is 1000000.

func Scan Uses

func Scan(values ...interface{}) valuesModel

func Select Uses

func Select(db DB, model interface{}) error

func URLValues Uses

func URLValues(urlValues url.Values) func(*Query) (*Query, error)

func Update Uses

func Update(db DB, model interface{}) error

type ColumnScanner Uses

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 Uses

type CreateTableOptions struct {
    Temp bool
}

type DB Uses

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 Uses

type Discard struct {
    // contains filtered or unexported fields
}

func (Discard) AddModel Uses

func (Discard) AddModel(_ ColumnScanner) error

func (Discard) AfterDelete Uses

func (Discard) AfterDelete(_ DB) error

func (Discard) AfterInsert Uses

func (Discard) AfterInsert(_ DB) error

func (Discard) AfterQuery Uses

func (Discard) AfterQuery(_ DB) error

func (Discard) AfterSelect Uses

func (Discard) AfterSelect(_ DB) error

func (Discard) AfterUpdate Uses

func (Discard) AfterUpdate(_ DB) error

func (Discard) BeforeDelete Uses

func (Discard) BeforeDelete(_ DB) error

func (Discard) BeforeInsert Uses

func (Discard) BeforeInsert(_ DB) error

func (Discard) BeforeUpdate Uses

func (Discard) BeforeUpdate(_ DB) error

func (Discard) NewModel Uses

func (d Discard) NewModel() ColumnScanner

func (Discard) Reset Uses

func (Discard) Reset() error

func (Discard) ScanColumn Uses

func (Discard) ScanColumn(colIdx int, colName string, b []byte) error

type Field Uses

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 Uses

func (f *Field) AppendValue(b []byte, strct reflect.Value, quote int) []byte

func (*Field) Copy Uses

func (f *Field) Copy() *Field

func (*Field) Has Uses

func (f *Field) Has(flag uint8) bool

func (*Field) IsEmpty Uses

func (f *Field) IsEmpty(strct reflect.Value) bool

func (*Field) OmitEmpty Uses

func (f *Field) OmitEmpty(strct reflect.Value) bool

func (*Field) ScanValue Uses

func (f *Field) ScanValue(strct reflect.Value, b []byte) error

func (*Field) Value Uses

func (f *Field) Value(strct reflect.Value) reflect.Value

type FormatAppender Uses

type FormatAppender interface {
    AppendFormat([]byte, QueryFormatter) []byte
}

func Q Uses

func Q(query string, params ...interface{}) FormatAppender

type Formatter Uses

type Formatter struct {
    // contains filtered or unexported fields
}

func (Formatter) Append Uses

func (f Formatter) Append(dst []byte, src string, params ...interface{}) []byte

func (Formatter) AppendBytes Uses

func (f Formatter) AppendBytes(dst, src []byte, params ...interface{}) []byte

func (Formatter) Copy Uses

func (f Formatter) Copy() Formatter

func (Formatter) FormatQuery Uses

func (f Formatter) FormatQuery(dst []byte, query string, params ...interface{}) []byte

func (*Formatter) SetParam Uses

func (f *Formatter) SetParam(param string, value interface{})

func (Formatter) String Uses

func (f Formatter) String() string

func (*Formatter) WithParam Uses

func (f *Formatter) WithParam(param string, value interface{}) Formatter

type Method Uses

type Method struct {
    Index int
    // contains filtered or unexported fields
}

func (*Method) AppendValue Uses

func (m *Method) AppendValue(dst []byte, strct reflect.Value, quote int) []byte

func (*Method) Has Uses

func (m *Method) Has(flag int8) bool

func (*Method) Value Uses

func (m *Method) Value(strct reflect.Value) reflect.Value

type Model Uses

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
}

func NewModel Uses

func NewModel(values ...interface{}) (Model, error)

type Query Uses

type Query struct {
    // contains filtered or unexported fields
}

func NewQuery Uses

func NewQuery(db DB, model ...interface{}) *Query

func (*Query) Apply Uses

func (q *Query) Apply(fn func(*Query) (*Query, error)) *Query

Apply calls the fn passing the Query as an argument.

func (*Query) Column Uses

func (q *Query) Column(columns ...string) *Query

Column adds column to the Query quoting it according to PostgreSQL rules. ColumnExpr can be used to bypass quoting restriction.

func (*Query) ColumnExpr Uses

func (q *Query) ColumnExpr(expr string, params ...interface{}) *Query

ColumnExpr adds column expression to the Query.

func (*Query) Copy Uses

func (q *Query) Copy() *Query

Copy returns copy of the Query.

func (*Query) Count Uses

func (q *Query) Count() (int, error)

Count returns number of rows matching the query using count aggregate function.

func (*Query) CountEstimate Uses

func (q *Query) CountEstimate(threshold int) (int, error)

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.

Based on https://wiki.postgresql.org/wiki/Count_estimate

func (*Query) DB Uses

func (q *Query) DB(db DB) *Query

func (*Query) Delete Uses

func (q *Query) Delete() (*types.Result, error)

Delete deletes the model.

func (*Query) First Uses

func (q *Query) First() error

First selects the first row.

func (*Query) FormatQuery Uses

func (q *Query) FormatQuery(dst []byte, query string, params ...interface{}) []byte

func (*Query) Group Uses

func (q *Query) Group(columns ...string) *Query

func (*Query) GroupExpr Uses

func (q *Query) GroupExpr(group string, params ...interface{}) *Query

func (*Query) Having Uses

func (q *Query) Having(having string, params ...interface{}) *Query

func (*Query) Insert Uses

func (q *Query) Insert(values ...interface{}) (*types.Result, error)

Insert inserts the model.

func (*Query) Join Uses

func (q *Query) Join(join string, params ...interface{}) *Query

func (*Query) Last Uses

func (q *Query) Last() error

Last selects the last row.

func (*Query) Limit Uses

func (q *Query) Limit(n int) *Query

func (*Query) Model Uses

func (q *Query) Model(model ...interface{}) *Query

func (*Query) New Uses

func (q *Query) New() *Query

New returns new zero Query binded to the current db and model.

func (*Query) Offset Uses

func (q *Query) Offset(n int) *Query

func (*Query) OnConflict Uses

func (q *Query) OnConflict(s string, params ...interface{}) *Query

func (*Query) Order Uses

func (q *Query) Order(orders ...string) *Query

Order adds sort order to the Query quoting column name. OrderExpr can be used to bypass quoting restriction.

func (*Query) OrderExpr Uses

func (q *Query) OrderExpr(order string, params ...interface{}) *Query

Order adds sort order to the Query.

func (*Query) Relation Uses

func (q *Query) Relation(name string, apply func(*Query) (*Query, error)) *Query

func (*Query) Returning Uses

func (q *Query) Returning(s string, params ...interface{}) *Query

func (*Query) Select Uses

func (q *Query) Select(values ...interface{}) error

Select selects the model.

func (*Query) SelectAndCount Uses

func (q *Query) SelectAndCount(values ...interface{}) (count int, err error)

SelectAndCount runs Select and Count in two goroutines, waits for them to finish and returns the result.

func (*Query) SelectAndCountEstimate Uses

func (q *Query) SelectAndCountEstimate(threshold int, values ...interface{}) (count int, err error)

SelectAndCountEstimate runs Select and CountEstimate in two goroutines, waits for them to finish and returns the result.

func (*Query) SelectOrInsert Uses

func (q *Query) SelectOrInsert(values ...interface{}) (inserted bool, err error)

SelectOrInsert selects the model inserting one if it does not exist.

func (*Query) Set Uses

func (q *Query) Set(set string, params ...interface{}) *Query

func (*Query) Table Uses

func (q *Query) Table(tables ...string) *Query

func (*Query) TableExpr Uses

func (q *Query) TableExpr(expr string, params ...interface{}) *Query

func (*Query) Update Uses

func (q *Query) Update(values ...interface{}) (*types.Result, error)

Update updates the model.

func (*Query) Where Uses

func (q *Query) Where(where string, params ...interface{}) *Query

func (*Query) WhereIn Uses

func (q *Query) WhereIn(where string, params ...interface{}) *Query

WhereIn is a shortcut for Where and pg.In to work with IN operator:

WhereIn("id IN (?)", 1, 2, 3)

func (*Query) WhereOr Uses

func (q *Query) WhereOr(where string, params ...interface{}) *Query

func (*Query) With Uses

func (q *Query) With(name string, subq *Query) *Query

With adds subq as common table expression with the given name.

func (*Query) WrapWith Uses

func (q *Query) WrapWith(name string) *Query

WrapWith creates new Query and adds to it current query as common table expression with the given name.

type QueryAppender Uses

type QueryAppender interface {
    AppendQuery(dst []byte, params ...interface{}) ([]byte, error)
}

type QueryFormatter Uses

type QueryFormatter interface {
    FormatQuery(dst []byte, query string, params ...interface{}) []byte
}

type Relation Uses

type Relation struct {
    Type        int
    Polymorphic bool
    Field       *Field
    JoinTable   *Table
    FKs         []*Field

    M2MTableName types.Q
    BasePrefix   string
    JoinPrefix   string
}

type Table Uses

type Table struct {
    Type reflect.Type

    TypeName  string
    Name      types.Q
    Alias     types.Q
    ModelName string

    PKs       []*Field
    Fields    []*Field
    FieldsMap map[string]*Field

    Methods   map[string]*Method
    Relations map[string]*Relation
    // contains filtered or unexported fields
}

func (*Table) AddField Uses

func (t *Table) AddField(field *Field)

func (*Table) AppendParam Uses

func (t *Table) AppendParam(dst []byte, strct reflect.Value, name string) ([]byte, bool)

func (*Table) GetField Uses

func (t *Table) GetField(fieldName string) (*Field, error)

func (*Table) Has Uses

func (t *Table) Has(flag int16) bool

func (*Table) HasField Uses

func (t *Table) HasField(field string) bool

Package orm imports 15 packages (graph) and is imported by 5 packages. Updated 2018-02-27. Refresh now. Tools for package owners.