table

package
v0.0.0-...-1039f8e Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2017 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	OneToOne = iota + 1
	OneToMany
	ManyToOne
	ManyToMany
	ForeignKey = ManyToOne
)

Variables

View Source
var (
	TypeScanner = reflect.TypeOf((*sql.Scanner)(nil)).Elem()

	TypeString    = reflect.TypeOf("")
	TypeByteSlice = reflect.TypeOf(([]byte)(nil))
	TypeTime      = reflect.TypeOf(time.Time{})
)

Functions

This section is empty.

Types

type Column

type Column struct {
	Table              *Table
	Type               reflect.Type
	Index              int
	Field              string
	Name               string // many_to_many is table name
	Relation           int
	RelationType       reflect.Type
	RelationTable      *Table
	Valuer, Scanner    bool
	Getter, Setter     int
	GetType, SetType   reflect.Type
	GetError, SetError bool
	GetPointer         bool
	Encoding           string // json or gob
	// many_to_many only
	NameLeft, NameRight       string
	ThroughTable              *Table
	ThroughLeft, ThroughRight *Column
}

func (*Column) AutoIncrement

func (c *Column) AutoIncrement() bool

func (*Column) AutoNow

func (c *Column) AutoNow() bool

func (*Column) AutoNowAdd

func (c *Column) AutoNowAdd() bool

func (*Column) Decode

func (c *Column) Decode(p []byte) (interface{}, error)

func (*Column) FullName

func (c *Column) FullName() string

func (*Column) GetValue

func (c *Column) GetValue(v reflect.Value) (interface{}, error)

many relation get the field value

func (*Column) HasEncoding

func (c *Column) HasEncoding() bool

func (*Column) HasGetter

func (c *Column) HasGetter() bool

func (*Column) HasSetter

func (c *Column) HasSetter() bool

func (*Column) IsManyRelation

func (c *Column) IsManyRelation() bool

func (*Column) IsOneRelation

func (c *Column) IsOneRelation() bool

func (*Column) PrimaryKey

func (c *Column) PrimaryKey() bool

func (*Column) Scan

func (c *Column) Scan(v reflect.Value) interface{}

panic if v is not table's type

func (*Column) Set

func (c *Column) Set(v reflect.Value, i interface{}) error

func (*Column) SetValue

func (c *Column) SetValue(v reflect.Value, i interface{}) error

many relation set the field value

type Columner

type Columner interface {
	// field name
	// if relation's struct name, primary key field name, table name and primary key column name
	// return column name
	ColumnName(...string) string
}

type Table

type Table struct {
	Type          reflect.Type
	Value         reflect.Value
	Name          string
	Columns       []*Column
	FieldMap      map[string]*Column
	ColumnMap     map[string]*Column // no many relation columns
	PrimaryKey    *Column
	AutoIncrement *Column
	AutoNowAdd    *Column
	AutoNow       *Column
}

func NewTable

func NewTable(i interface{}) (*Table, error)

func TableOf

func TableOf(t reflect.Type) (*Table, error)

func (*Table) FindColumn

func (t *Table) FindColumn(s string) *Column

column name then field name

func (*Table) FindField

func (t *Table) FindField(s string) *Column

field name then column name

type Tabler

type Tabler interface {
	// return table name
	TableName() string
}

type Througher

type Througher interface {
	// field name
	// return through table, left field name, right field name
	ThroughTable(string) (interface{}, string, string)
}

Jump to

Keyboard shortcuts

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