orm

package
v4.0.7+incompatible Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2016 License: BSD-3-Clause Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PrimaryKeyFlag = 1 << iota
	ForeignKeyFlag = 1 << iota
	NullFlag       = 1 << iota
	FormatFlag     = 1 << iota
)

Variables

View Source
var Tables = newTables()

Functions

func Create

func Create(db dber, v interface{}) error

func Delete

func Delete(db dber, v interface{}) error

func F

func F(field string, params ...interface{}) types.F

func Q

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

func Scan

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

func Underscore

func Underscore(s string) string

Underscore converts "CamelCasedString" to "camel_cased_string".

func Update

func Update(db dber, v interface{}) error

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

func (Discard) ScanColumn

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

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

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

func (*Field) Copy

func (f *Field) Copy() *Field

func (*Field) Has

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

func (*Field) IsEmpty

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

func (*Field) OmitEmpty

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

func (*Field) ScanValue

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

func (*Field) Value

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

type Formatter

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

func (Formatter) Append

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

func (Formatter) AppendBytes

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

func (*Formatter) SetParam

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

type Join

type Join struct {
	BaseModel TableModel
	JoinModel TableModel
	Rel       *Relation

	SelectAll bool
	Columns   []string
}

func (*Join) AppendColumns

func (j *Join) AppendColumns(dst []byte) []byte

func (*Join) JoinOne

func (j *Join) JoinOne(q *Query)

func (*Join) Select

func (j *Join) Select(db dber) error

type Method

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

func (*Method) AppendValue

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

func (*Method) Has

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

func (*Method) Value

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

type Model

type Model interface {
	Collection
	ColumnScanner
}

func NewModel

func NewModel(vi interface{}) (Model, error)

type Query

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

func NewQuery

func NewQuery(db dber, v interface{}) *Query

func (*Query) Column

func (q *Query) Column(columns ...interface{}) *Query

func (*Query) Count

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

func (*Query) Create

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

Create inserts the model into database.

func (*Query) Delete

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

Delete deletes the model from database.

func (*Query) First

func (q *Query) First() error

func (*Query) Join

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

func (*Query) Last

func (q *Query) Last() error

func (*Query) Limit

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

func (*Query) Offset

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

func (*Query) OnConflict

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

func (*Query) Order

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

func (*Query) Returning

func (q *Query) Returning(columns ...interface{}) *Query

func (*Query) Select

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

Select selects the model from database.

func (*Query) SelectOrCreate

func (q *Query) SelectOrCreate(values ...interface{}) (created bool, err error)

SelectOrCreate selects the model from database creating one if necessary.

func (*Query) Table

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

func (*Query) Update

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

Update updates the model in database.

func (*Query) UpdateValues

func (q *Query) UpdateValues(values map[string]interface{}) (*types.Result, error)

Update updates the model using provided values.

func (*Query) Where

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

type QueryAppender

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

type Relation

type Relation struct {
	One         bool
	Polymorphic bool

	Field *Field
	Join  *Table
	FKs   []*Field

	M2MTableName types.Q
	BasePrefix   string
	JoinPrefix   string
}

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) Kind

func (m *SliceModel) Kind() reflect.Kind

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) Kind

func (m *StructModel) Kind() reflect.Kind

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 Table struct {
	Name      types.Q // escaped table name
	ModelName string
	Type      reflect.Type

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

	Methods   map[string]*Method
	Relations map[string]*Relation
}

func (*Table) AddField

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

func (*Table) GetField

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

type TableModel

type TableModel interface {
	Table() *Table

	Model

	Join(string) *Join
	GetJoin(string) *Join
	GetJoins() []Join
	AddJoin(Join) *Join

	Kind() reflect.Kind
	Root() reflect.Value
	Path() []string
	Bind(reflect.Value)
	Value() reflect.Value
	// contains filtered or unexported methods
}

func NewTableModel

func NewTableModel(v interface{}) (TableModel, error)

func NewTableModelPath

func NewTableModelPath(root reflect.Value, path []string, table *Table) (TableModel, error)

Jump to

Keyboard shortcuts

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