Documentation ¶
Index ¶
- type AllUserEmployeesResult
- type AllUserEmployeesResultSlice
- func (slice *AllUserEmployeesResultSlice) DistinctEmpl() []*Employee
- func (slice *AllUserEmployeesResultSlice) DistinctUser() []*User
- func (slice *AllUserEmployeesResultSlice) GroupByEmpl() ([]*Employee, []AllUserEmployeesResultSlice)
- func (slice *AllUserEmployeesResultSlice) GroupByUser() ([]*User, []AllUserEmployeesResultSlice)
- func (slice *AllUserEmployeesResultSlice) One() *AllUserEmployeesResult
- type ColumnScanner
- type Employee
- func EmployeeByEmployeeSn(ctx context.Context, q Queryer, nxEmployeeSn string, lock bool) (*Employee, error)
- func EmployeeByPrimary(ctx context.Context, q Queryer, nxId int32, lock bool) (*Employee, error)
- func EmployeeByUserId(ctx context.Context, q Queryer, nxUserId int32, lock bool) (*Employee, error)
- func (tr *Employee) ColumnPointer(i int) interface{}
- func (tr *Employee) ColumnValue(i int) interface{}
- func (tr *Employee) Copy() *Employee
- func (tr *Employee) Delete(ctx context.Context, e Execer) error
- func (tr *Employee) EmployeeByFkSuperior(ctx context.Context, q Queryer, lock bool) (*Employee, error)
- func (tr *Employee) Insert(ctx context.Context, e Execer) error
- func (tr *Employee) InsertEx(ctx context.Context, e Execer, modifier string) error
- func (tr *Employee) PrimaryValue() interface{}
- func (tr *Employee) Reload(ctx context.Context, q Queryer) error
- func (tr *Employee) ReloadWithLock(ctx context.Context, q Queryer) error
- func (tr *Employee) TableMeta() *TableMeta
- func (tr *Employee) Update(ctx context.Context, e Execer, newTr *Employee) error
- func (tr *Employee) UserByFkUser(ctx context.Context, q Queryer, lock bool) (*User, error)
- func (tr *Employee) Valid() bool
- type EmployeeSlice
- type ExecQueryer
- type Execer
- type Queryer
- type Slicer
- type SubordinatesBySuperiorsResult
- type SubordinatesBySuperiorsResultSlice
- func (slice *SubordinatesBySuperiorsResultSlice) DistinctSubordinate() []*Employee
- func (slice *SubordinatesBySuperiorsResultSlice) DistinctSuperior() []*Employee
- func (slice *SubordinatesBySuperiorsResultSlice) GroupBySubordinate() ([]*Employee, []SubordinatesBySuperiorsResultSlice)
- func (slice *SubordinatesBySuperiorsResultSlice) GroupBySuperior() ([]*Employee, []SubordinatesBySuperiorsResultSlice)
- func (slice *SubordinatesBySuperiorsResultSlice) One() *SubordinatesBySuperiorsResult
- type TableMeta
- type TableMetaOption
- type TableRow
- type TableRowWithPrimary
- type User
- func (tr *User) ColumnPointer(i int) interface{}
- func (tr *User) ColumnValue(i int) interface{}
- func (tr *User) Copy() *User
- func (tr *User) Delete(ctx context.Context, e Execer) error
- func (tr *User) Insert(ctx context.Context, e Execer) error
- func (tr *User) InsertEx(ctx context.Context, e Execer, modifier string) error
- func (tr *User) PrimaryValue() interface{}
- func (tr *User) Reload(ctx context.Context, q Queryer) error
- func (tr *User) ReloadWithLock(ctx context.Context, q Queryer) error
- func (tr *User) TableMeta() *TableMeta
- func (tr *User) Update(ctx context.Context, e Execer, newTr *User) error
- func (tr *User) Valid() bool
- type UserSlice
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AllUserEmployeesResult ¶
type AllUserEmployeesResult struct { User *User Age null.Uint64 Empl *Employee // contains filtered or unexported fields }
AllUserEmployeesResult is the result of `AllUserEmployees`.
type AllUserEmployeesResultSlice ¶
type AllUserEmployeesResultSlice []*AllUserEmployeesResult
AllUserEmployeesResultSlice is slice of AllUserEmployeesResult.
func AllUserEmployees ¶
func AllUserEmployees(ctx context.Context, q Queryer) (AllUserEmployeesResultSlice, error)
AllUserEmployees is created from:
<stmt name="AllUserEmployees"> SELECT <wc table="user"/>, CAST(DATEDIFF(NOW(), birthday)/365 AS UNSIGNED) AS age, <wc table="employee" as="empl"/> FROM user LEFT JOIN employee AS empl ON user.id=empl.user_id </stmt>
func (*AllUserEmployeesResultSlice) DistinctEmpl ¶
func (slice *AllUserEmployeesResultSlice) DistinctEmpl() []*Employee
DistinctEmpl returns distinct (by primary value) Empl in the slice.
func (*AllUserEmployeesResultSlice) DistinctUser ¶
func (slice *AllUserEmployeesResultSlice) DistinctUser() []*User
DistinctUser returns distinct (by primary value) User in the slice.
func (*AllUserEmployeesResultSlice) GroupByEmpl ¶
func (slice *AllUserEmployeesResultSlice) GroupByEmpl() ([]*Employee, []AllUserEmployeesResultSlice)
GroupByEmpl groups by Empl and returns distinct (by primary value) Empl with their associated sub group of slices.
func (*AllUserEmployeesResultSlice) GroupByUser ¶
func (slice *AllUserEmployeesResultSlice) GroupByUser() ([]*User, []AllUserEmployeesResultSlice)
GroupByUser groups by User and returns distinct (by primary value) User with their associated sub group of slices.
func (*AllUserEmployeesResultSlice) One ¶
func (slice *AllUserEmployeesResultSlice) One() *AllUserEmployeesResult
One returns a single AllUserEmployeesResult. It panics if the length of slice is not 1.
type ColumnScanner ¶
type ColumnScanner interface {
// contains filtered or unexported methods
}
ColumnScanner represents a collection of columns that can be scanned into from a row.
type Employee ¶
type Employee struct { Id int32 `json:"id" db:"id"` EmployeeSn string `json:"employee_sn" db:"employee_sn"` UserId int32 `json:"user_id" db:"user_id"` SuperiorId null.Int32 `json:"superior_id" db:"superior_id"` }
Employee represents a row of table `employee`.
func EmployeeByEmployeeSn ¶
func EmployeeByEmployeeSn(ctx context.Context, q Queryer, nxEmployeeSn string, lock bool) (*Employee, error)
EmployeeByEmployeeSn is used to select Employee by `employee_sn` index. It returns nil if no row is found.
func EmployeeByPrimary ¶
EmployeeByPrimary is used to select Employee by `PRIMARY` index. It returns nil if no row is found.
func EmployeeByUserId ¶
EmployeeByUserId is used to select Employee by `user_id` index. It returns nil if no row is found.
func (*Employee) ColumnPointer ¶
ColumnPointer returns the i-th column's pointer. Implements TableRow interface.
func (*Employee) ColumnValue ¶
ColumnValue returns the i-th column's value. Implements TableRow interface.
func (*Employee) EmployeeByFkSuperior ¶
func (tr *Employee) EmployeeByFkSuperior(ctx context.Context, q Queryer, lock bool) (*Employee, error)
EmployeeByFkSuperior returns the associated Employee by `fk_superior` foreign key: (`superior_id`).
func (*Employee) Insert ¶
Insert is used to insert the row into table. This method will also update the value in auto increment column (if exists).
func (*Employee) InsertEx ¶
InsertEx is the same as Insert with extra modifier specified. modifier can be one of:
- "ignore": "INSERT IGNORE INTO ..."
- "replace": "REPLACE INTO ..."
- "": Normal "INSERT INTO ..."
func (*Employee) PrimaryValue ¶
func (tr *Employee) PrimaryValue() interface{}
PrimaryValue returns the primary key value of this row. Implements TableRowWithPrimary interface.
func (*Employee) Reload ¶
Reload is used to reload the row from table. It returns error if no row is found.
func (*Employee) ReloadWithLock ¶
ReloadWithLock is used to reload this row with lock from table. It returns error if no row is found.
func (*Employee) TableMeta ¶
TableMeta returns the table meta information of table `employee`. Implements TableRow interface.
func (*Employee) Update ¶
Update is used to update the row in table. Only columns with different values will be updated. NOTE: This method does not modify content in `tr`/`newTr`. Use Reload to load fresh data from database.
func (*Employee) UserByFkUser ¶
UserByFkUser returns the associated User by `fk_user` foreign key: (`user_id`).
type Execer ¶
type Execer interface {
ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
}
Execer is the common interface to execute a query without returning any row.
type Queryer ¶
type Queryer interface { QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error) QueryRowContext(ctx context.Context, query string, args ...interface{}) *sql.Row }
Queryer is the common interface to execute a query returning row(s).
type Slicer ¶
type Slicer interface {
// contains filtered or unexported methods
}
Slicer represents an appendable slice.
type SubordinatesBySuperiorsResult ¶
type SubordinatesBySuperiorsResult struct { Superior *Employee Subordinate *Employee // contains filtered or unexported fields }
SubordinatesBySuperiorsResult is the result of `SubordinatesBySuperiors`.
type SubordinatesBySuperiorsResultSlice ¶
type SubordinatesBySuperiorsResultSlice []*SubordinatesBySuperiorsResult
SubordinatesBySuperiorsResultSlice is slice of SubordinatesBySuperiorsResult.
func SubordinatesBySuperiors ¶
func SubordinatesBySuperiors(ctx context.Context, q Queryer, id ...int) (SubordinatesBySuperiorsResultSlice, error)
SubordinatesBySuperiors is created from:
<stmt name="SubordinatesBySuperiors"> <a name="id" type="...int"/> <v in_query="1"/> SELECT <wc table="employee" as="superior"/>, <wc table="employee" as="subordinate"/> FROM employee AS superior LEFT JOIN employee AS subordinate ON subordinate.superior_id=superior.id WHERE superior.id IN (<b name="id"/>) </stmt>
func (*SubordinatesBySuperiorsResultSlice) DistinctSubordinate ¶
func (slice *SubordinatesBySuperiorsResultSlice) DistinctSubordinate() []*Employee
DistinctSubordinate returns distinct (by primary value) Subordinate in the slice.
func (*SubordinatesBySuperiorsResultSlice) DistinctSuperior ¶
func (slice *SubordinatesBySuperiorsResultSlice) DistinctSuperior() []*Employee
DistinctSuperior returns distinct (by primary value) Superior in the slice.
func (*SubordinatesBySuperiorsResultSlice) GroupBySubordinate ¶
func (slice *SubordinatesBySuperiorsResultSlice) GroupBySubordinate() ([]*Employee, []SubordinatesBySuperiorsResultSlice)
GroupBySubordinate groups by Subordinate and returns distinct (by primary value) Subordinate with their associated sub group of slices.
func (*SubordinatesBySuperiorsResultSlice) GroupBySuperior ¶
func (slice *SubordinatesBySuperiorsResultSlice) GroupBySuperior() ([]*Employee, []SubordinatesBySuperiorsResultSlice)
GroupBySuperior groups by Superior and returns distinct (by primary value) Superior with their associated sub group of slices.
func (*SubordinatesBySuperiorsResultSlice) One ¶
func (slice *SubordinatesBySuperiorsResultSlice) One() *SubordinatesBySuperiorsResult
One returns a single SubordinatesBySuperiorsResult. It panics if the length of slice is not 1.
type TableMeta ¶
type TableMeta struct {
// contains filtered or unexported fields
}
TableMeta contains meta information of a database table.
func NewTableMeta ¶
func NewTableMeta(tableName string, columnNames []string, opts ...TableMetaOption) *TableMeta
NewTableMeta creates a new TableMeta.
type TableMetaOption ¶
type TableMetaOption func(*TableMeta)
TableMetaOption is used in creating TableMeta.
func OptAutoIncColumn ¶
func OptAutoIncColumn(columnName string) TableMetaOption
OptAutoIncColumn sets the auto increment column.
func OptColumnsWithDefault ¶
func OptColumnsWithDefault(columnNames ...string) TableMetaOption
OptColumnsWithDefault sets the columns that have not NULL server side default, including:
- AUTO_INCREMENT
- NOW()
- Other not NULL constant defaults.
func OptPrimaryColumns ¶
func OptPrimaryColumns(columnNames ...string) TableMetaOption
OptPrimaryColumns sets the primary key columns.
type TableRow ¶
type TableRow interface { ColumnScanner // TableMeta returns the table's meta information. TableMeta() *TableMeta // Valid returns true if this is a valid table row (e.g. not NULL). Valid() bool // ColumnValue returns the i-th column value. ColumnValue(i int) interface{} // ColumnPointer returns the i-th column's pointer. ColumnPointer(i int) interface{} }
TableRow represents a table's row.
type TableRowWithPrimary ¶
type TableRowWithPrimary interface { TableRow // PrimaryValue returns the primary key value of this row. // The returned value is comparable by values. PrimaryValue() interface{} }
TableRowWithPrimary represents row of table with primary key.
type User ¶
type User struct { Id int32 `json:"id" db:"id"` Name string `json:"name" db:"name"` Female null.Bool `json:"female" db:"female"` Birthday null.Time `json:"birthday" db:"birthday"` }
User represents a row of table `user`.
func UserByPrimary ¶
UserByPrimary is used to select User by `PRIMARY` index. It returns nil if no row is found.
func (*User) ColumnPointer ¶
ColumnPointer returns the i-th column's pointer. Implements TableRow interface.
func (*User) ColumnValue ¶
ColumnValue returns the i-th column's value. Implements TableRow interface.
func (*User) Insert ¶
Insert is used to insert the row into table. This method will also update the value in auto increment column (if exists).
func (*User) InsertEx ¶
InsertEx is the same as Insert with extra modifier specified. modifier can be one of:
- "ignore": "INSERT IGNORE INTO ..."
- "replace": "REPLACE INTO ..."
- "": Normal "INSERT INTO ..."
func (*User) PrimaryValue ¶
func (tr *User) PrimaryValue() interface{}
PrimaryValue returns the primary key value of this row. Implements TableRowWithPrimary interface.
func (*User) Reload ¶
Reload is used to reload the row from table. It returns error if no row is found.
func (*User) ReloadWithLock ¶
ReloadWithLock is used to reload this row with lock from table. It returns error if no row is found.
func (*User) TableMeta ¶
TableMeta returns the table meta information of table `user`. Implements TableRow interface.
type UserSlice ¶
type UserSlice []*User
UserSlice is slice of User.
func UsersByCond ¶
func UsersByCond(ctx context.Context, q Queryer, id int, name string, birthday time.Time, limit int) (UserSlice, error)
UsersByCond is created from:
<stmt name="UsersByCond"> <v use_template="1"/> <a name="id" type="int"/> <a name="name" type="string"/> <a name="birthday" type="time.Time"/> <a name="limit" type="int"/> SELECT <wc table="user"/> FROM user WHERE <t>{{ if ne .id 0 }}</t> id=<b name="id"/> AND <t>{{ end }}</t> <t>{{ if ne (len .name) 0 }}</t> name=<b name="name"/> AND <t>{{ end }}</t> <t>{{ if not .birthday.IsZero }}</t> birthday=<b name="birthday"/> AND <t>{{ end }}</t> 1 LIMIT <b name="limit">10</b> </stmt>