mirror of
https://github.com/tiger1103/gfast.git
synced 2026-09-21 10:12:59 +00:00
升级gf与gtoken到最新版本,更新gf生成的model为最新版本
This commit is contained in:
@@ -11,22 +11,24 @@ import (
|
||||
|
||||
// Entity is the golang structure for table auth_rule.
|
||||
type Entity struct {
|
||||
Id uint `orm:"id,primary" json:"id"` //
|
||||
Pid uint `orm:"pid" json:"pid"` // 父ID
|
||||
Name string `orm:"name,unique" json:"name"` // 规则名称
|
||||
Title string `orm:"title" json:"title"` // 规则名称
|
||||
Icon string `orm:"icon" json:"icon"` // 图标
|
||||
Condition string `orm:"condition" json:"condition"` // 条件
|
||||
Remark string `orm:"remark" json:"remark"` // 备注
|
||||
MenuType uint `orm:"menu_type" json:"menu_type"` // 类型 0目录 1菜单 2按钮
|
||||
Createtime uint `orm:"createtime" json:"createtime"` // 创建时间
|
||||
Updatetime uint `orm:"updatetime" json:"updatetime"` // 更新时间
|
||||
Weigh int `orm:"weigh" json:"weigh"` // 权重
|
||||
Status uint `orm:"status" json:"status"` // 状态
|
||||
AlwaysShow uint `orm:"always_show" json:"alwaysShow"` //显示状态 0隐藏 1显示
|
||||
Path string `orm:"path" json:"path"` //路由地址
|
||||
Component string `orm:"component" json:"component"` //组件路径
|
||||
IsFrame uint `orm:"is_frame" json:"isFrame"` //是否外链 1是 0否
|
||||
Id uint `orm:"id,primary" json:"id"` //
|
||||
Pid uint `orm:"pid" json:"pid"` // 父ID
|
||||
Name string `orm:"name,unique" json:"name"` // 规则名称
|
||||
Title string `orm:"title" json:"title"` // 规则名称
|
||||
Icon string `orm:"icon" json:"icon"` // 图标
|
||||
Condition string `orm:"condition" json:"condition"` // 条件
|
||||
Remark string `orm:"remark" json:"remark"` // 备注
|
||||
MenuType uint `orm:"menu_type" json:"menu_type"` // 类型 0目录 1菜单 2按钮
|
||||
Createtime uint `orm:"createtime" json:"createtime"` // 创建时间
|
||||
Updatetime uint `orm:"updatetime" json:"updatetime"` // 更新时间
|
||||
Weigh int `orm:"weigh" json:"weigh"` // 权重
|
||||
Status uint `orm:"status" json:"status"` // 状态
|
||||
AlwaysShow uint `orm:"always_show" json:"always_show"` // 显示状态
|
||||
Path string `orm:"path" json:"path"` // 路由地址
|
||||
Component string `orm:"component" json:"component"` // 组件路径
|
||||
IsFrame uint `orm:"is_frame" json:"is_frame"` // 是否外链 1是 0否
|
||||
ModuleType string `orm:"module_type" json:"module_type"` // 所属模块
|
||||
ModelId uint `orm:"model_id" json:"model_id"` // 模型ID
|
||||
}
|
||||
|
||||
// OmitEmpty sets OPTION_OMITEMPTY option for the model, which automatically filers
|
||||
@@ -40,6 +42,11 @@ func (r *Entity) Insert() (result sql.Result, err error) {
|
||||
return Model.Data(r).Insert()
|
||||
}
|
||||
|
||||
// InsertIgnore does "INSERT IGNORE INTO ..." statement for inserting current object into table.
|
||||
func (r *Entity) InsertIgnore() (result sql.Result, err error) {
|
||||
return Model.Data(r).InsertIgnore()
|
||||
}
|
||||
|
||||
// Replace does "REPLACE...INTO..." statement for inserting current object into table.
|
||||
// If there's already another same record in the table (it checks using primary key or unique index),
|
||||
// it deletes it and insert this one.
|
||||
|
||||
@@ -8,12 +8,13 @@ import (
|
||||
"database/sql"
|
||||
"github.com/gogf/gf/database/gdb"
|
||||
"github.com/gogf/gf/frame/g"
|
||||
"github.com/gogf/gf/frame/gmvc"
|
||||
"time"
|
||||
)
|
||||
|
||||
// arModel is a active record design model for table auth_rule operations.
|
||||
type arModel struct {
|
||||
M *gdb.Model
|
||||
gmvc.M
|
||||
}
|
||||
|
||||
var (
|
||||
@@ -21,6 +22,46 @@ var (
|
||||
Table = "auth_rule"
|
||||
// Model is the model object of auth_rule.
|
||||
Model = &arModel{g.DB("default").Table(Table).Safe()}
|
||||
// Columns defines and stores column names for table auth_rule.
|
||||
Columns = struct {
|
||||
Id string //
|
||||
Pid string // 父ID
|
||||
Name string // 规则名称
|
||||
Title string // 规则名称
|
||||
Icon string // 图标
|
||||
Condition string // 条件
|
||||
Remark string // 备注
|
||||
MenuType string // 类型 0目录 1菜单 2按钮
|
||||
Createtime string // 创建时间
|
||||
Updatetime string // 更新时间
|
||||
Weigh string // 权重
|
||||
Status string // 状态
|
||||
AlwaysShow string // 显示状态
|
||||
Path string // 路由地址
|
||||
Component string // 组件路径
|
||||
IsFrame string // 是否外链 1是 0否
|
||||
ModuleType string // 所属模块
|
||||
ModelId string // 模型ID
|
||||
}{
|
||||
Id: "id",
|
||||
Pid: "pid",
|
||||
Name: "name",
|
||||
Title: "title",
|
||||
Icon: "icon",
|
||||
Condition: "condition",
|
||||
Remark: "remark",
|
||||
MenuType: "menu_type",
|
||||
Createtime: "createtime",
|
||||
Updatetime: "updatetime",
|
||||
Weigh: "weigh",
|
||||
Status: "status",
|
||||
AlwaysShow: "always_show",
|
||||
Path: "path",
|
||||
Component: "component",
|
||||
IsFrame: "is_frame",
|
||||
ModuleType: "module_type",
|
||||
ModelId: "model_id",
|
||||
}
|
||||
)
|
||||
|
||||
// FindOne is a convenience method for Model.FindOne.
|
||||
@@ -41,6 +82,12 @@ func FindValue(fieldsAndWhere ...interface{}) (gdb.Value, error) {
|
||||
return Model.FindValue(fieldsAndWhere...)
|
||||
}
|
||||
|
||||
// FindArray is a convenience method for Model.FindArray.
|
||||
// See Model.FindArray.
|
||||
func FindArray(fieldsAndWhere ...interface{}) ([]gdb.Value, error) {
|
||||
return Model.FindArray(fieldsAndWhere...)
|
||||
}
|
||||
|
||||
// FindCount is a convenience method for Model.FindCount.
|
||||
// See Model.FindCount.
|
||||
func FindCount(where ...interface{}) (int, error) {
|
||||
@@ -52,6 +99,11 @@ func Insert(data ...interface{}) (result sql.Result, err error) {
|
||||
return Model.Insert(data...)
|
||||
}
|
||||
|
||||
// InsertIgnore is a convenience method for Model.InsertIgnore.
|
||||
func InsertIgnore(data ...interface{}) (result sql.Result, err error) {
|
||||
return Model.InsertIgnore(data...)
|
||||
}
|
||||
|
||||
// Replace is a convenience method for Model.Replace.
|
||||
func Replace(data ...interface{}) (result sql.Result, err error) {
|
||||
return Model.Replace(data...)
|
||||
@@ -94,18 +146,30 @@ func (m *arModel) Slave() *arModel {
|
||||
}
|
||||
|
||||
// LeftJoin does "LEFT JOIN ... ON ..." statement on the model.
|
||||
func (m *arModel) LeftJoin(joinTable string, on string) *arModel {
|
||||
return &arModel{m.M.LeftJoin(joinTable, on)}
|
||||
// The parameter <table> can be joined table and its joined condition,
|
||||
// and also with its alias name, like:
|
||||
// Table("user").LeftJoin("user_detail", "user_detail.uid=user.uid")
|
||||
// Table("user", "u").LeftJoin("user_detail", "ud", "ud.uid=u.uid")
|
||||
func (m *arModel) LeftJoin(table ...string) *arModel {
|
||||
return &arModel{m.M.LeftJoin(table...)}
|
||||
}
|
||||
|
||||
// RightJoin does "RIGHT JOIN ... ON ..." statement on the model.
|
||||
func (m *arModel) RightJoin(joinTable string, on string) *arModel {
|
||||
return &arModel{m.M.RightJoin(joinTable, on)}
|
||||
// The parameter <table> can be joined table and its joined condition,
|
||||
// and also with its alias name, like:
|
||||
// Table("user").RightJoin("user_detail", "user_detail.uid=user.uid")
|
||||
// Table("user", "u").RightJoin("user_detail", "ud", "ud.uid=u.uid")
|
||||
func (m *arModel) RightJoin(table ...string) *arModel {
|
||||
return &arModel{m.M.RightJoin(table...)}
|
||||
}
|
||||
|
||||
// InnerJoin does "INNER JOIN ... ON ..." statement on the model.
|
||||
func (m *arModel) InnerJoin(joinTable string, on string) *arModel {
|
||||
return &arModel{m.M.InnerJoin(joinTable, on)}
|
||||
// The parameter <table> can be joined table and its joined condition,
|
||||
// and also with its alias name, like:
|
||||
// Table("user").InnerJoin("user_detail", "user_detail.uid=user.uid")
|
||||
// Table("user", "u").InnerJoin("user_detail", "ud", "ud.uid=u.uid")
|
||||
func (m *arModel) InnerJoin(table ...string) *arModel {
|
||||
return &arModel{m.M.InnerJoin(table...)}
|
||||
}
|
||||
|
||||
// Fields sets the operation fields of the model, multiple fields joined using char ','.
|
||||
@@ -165,8 +229,8 @@ func (m *arModel) Group(groupBy string) *arModel {
|
||||
}
|
||||
|
||||
// Order sets the "ORDER BY" statement for the model.
|
||||
func (m *arModel) Order(orderBy string) *arModel {
|
||||
return &arModel{m.M.Order(orderBy)}
|
||||
func (m *arModel) Order(orderBy ...string) *arModel {
|
||||
return &arModel{m.M.Order(orderBy...)}
|
||||
}
|
||||
|
||||
// Limit sets the "LIMIT" statement for the model.
|
||||
@@ -207,8 +271,8 @@ func (m *arModel) Batch(batch int) *arModel {
|
||||
// control the cache like changing the <duration> or clearing the cache with specified <name>.
|
||||
//
|
||||
// Note that, the cache feature is disabled if the model is operating on a transaction.
|
||||
func (m *arModel) Cache(expire time.Duration, name ...string) *arModel {
|
||||
return &arModel{m.M.Cache(expire, name...)}
|
||||
func (m *arModel) Cache(duration time.Duration, name ...string) *arModel {
|
||||
return &arModel{m.M.Cache(duration, name...)}
|
||||
}
|
||||
|
||||
// Data sets the operation data for the model.
|
||||
@@ -222,53 +286,6 @@ func (m *arModel) Data(data ...interface{}) *arModel {
|
||||
return &arModel{m.M.Data(data...)}
|
||||
}
|
||||
|
||||
// Insert does "INSERT INTO ..." statement for the model.
|
||||
// The optional parameter <data> is the same as the parameter of Model.Data function,
|
||||
// see Model.Data.
|
||||
func (m *arModel) Insert(data ...interface{}) (result sql.Result, err error) {
|
||||
return m.M.Insert(data...)
|
||||
}
|
||||
|
||||
// Replace does "REPLACE INTO ..." statement for the model.
|
||||
// The optional parameter <data> is the same as the parameter of Model.Data function,
|
||||
// see Model.Data.
|
||||
func (m *arModel) Replace(data ...interface{}) (result sql.Result, err error) {
|
||||
return m.M.Replace(data...)
|
||||
}
|
||||
|
||||
// Save does "INSERT INTO ... ON DUPLICATE KEY UPDATE..." statement for the model.
|
||||
// It updates the record if there's primary or unique index in the saving data,
|
||||
// or else it inserts a new record into the table.
|
||||
//
|
||||
// The optional parameter <data> is the same as the parameter of Model.Data function,
|
||||
// see Model.Data.
|
||||
func (m *arModel) Save(data ...interface{}) (result sql.Result, err error) {
|
||||
return m.M.Save(data...)
|
||||
}
|
||||
|
||||
// Update does "UPDATE ... " statement for the model.
|
||||
//
|
||||
// If the optional parameter <dataAndWhere> is given, the dataAndWhere[0] is the updated
|
||||
// data field, and dataAndWhere[1:] is treated as where condition fields.
|
||||
// Also see Model.Data and Model.Where functions.
|
||||
func (m *arModel) Update(dataAndWhere ...interface{}) (result sql.Result, err error) {
|
||||
return m.M.Update(dataAndWhere...)
|
||||
}
|
||||
|
||||
// Delete does "DELETE FROM ... " statement for the model.
|
||||
// The optional parameter <where> is the same as the parameter of Model.Where function,
|
||||
// see Model.Where.
|
||||
func (m *arModel) Delete(where ...interface{}) (result sql.Result, err error) {
|
||||
return m.M.Delete(where...)
|
||||
}
|
||||
|
||||
// Count does "SELECT COUNT(x) FROM ..." statement for the model.
|
||||
// The optional parameter <where> is the same as the parameter of Model.Where function,
|
||||
// see Model.Where.
|
||||
func (m *arModel) Count(where ...interface{}) (int, error) {
|
||||
return m.M.Count(where...)
|
||||
}
|
||||
|
||||
// All does "SELECT FROM ..." statement for the model.
|
||||
// It retrieves the records from table and returns the result as []*Entity.
|
||||
// It returns nil if there's no record retrieved with the given conditions from table.
|
||||
@@ -304,16 +321,6 @@ func (m *arModel) One(where ...interface{}) (*Entity, error) {
|
||||
return entity, nil
|
||||
}
|
||||
|
||||
// Value retrieves a specified record value from table and returns the result as interface type.
|
||||
// It returns nil if there's no record found with the given conditions from table.
|
||||
//
|
||||
// If the optional parameter <fieldsAndWhere> is given, the fieldsAndWhere[0] is the selected fields
|
||||
// and fieldsAndWhere[1:] is treated as where condition fields.
|
||||
// Also see Model.Fields and Model.Where functions.
|
||||
func (m *arModel) Value(fieldsAndWhere ...interface{}) (gdb.Value, error) {
|
||||
return m.M.Value(fieldsAndWhere...)
|
||||
}
|
||||
|
||||
// FindOne retrieves and returns a single Record by Model.WherePri and Model.One.
|
||||
// Also see Model.WherePri and Model.One.
|
||||
func (m *arModel) FindOne(where ...interface{}) (*Entity, error) {
|
||||
@@ -342,18 +349,6 @@ func (m *arModel) FindAll(where ...interface{}) ([]*Entity, error) {
|
||||
return entities, nil
|
||||
}
|
||||
|
||||
// FindValue retrieves and returns single field value by Model.WherePri and Model.Value.
|
||||
// Also see Model.WherePri and Model.Value.
|
||||
func (m *arModel) FindValue(fieldsAndWhere ...interface{}) (gdb.Value, error) {
|
||||
return m.M.FindValue(fieldsAndWhere...)
|
||||
}
|
||||
|
||||
// FindCount retrieves and returns the record number by Model.WherePri and Model.Count.
|
||||
// Also see Model.WherePri and Model.Count.
|
||||
func (m *arModel) FindCount(where ...interface{}) (int, error) {
|
||||
return m.M.FindCount(where...)
|
||||
}
|
||||
|
||||
// Chunk iterates the table with given size and callback function.
|
||||
func (m *arModel) Chunk(limit int, callback func(entities []*Entity, err error) bool) {
|
||||
m.M.Chunk(limit, func(result gdb.Result, err error) bool {
|
||||
@@ -365,3 +360,18 @@ func (m *arModel) Chunk(limit int, callback func(entities []*Entity, err error)
|
||||
return callback(entities, err)
|
||||
})
|
||||
}
|
||||
|
||||
// LockUpdate sets the lock for update for current operation.
|
||||
func (m *arModel) LockUpdate() *arModel {
|
||||
return &arModel{m.M.LockUpdate()}
|
||||
}
|
||||
|
||||
// LockShared sets the lock in share mode for current operation.
|
||||
func (m *arModel) LockShared() *arModel {
|
||||
return &arModel{m.M.LockShared()}
|
||||
}
|
||||
|
||||
// Unscoped enables/disables the soft deleting feature.
|
||||
func (m *arModel) Unscoped() *arModel {
|
||||
return &arModel{m.M.Unscoped()}
|
||||
}
|
||||
|
||||
@@ -31,6 +31,11 @@ func (r *Entity) Insert() (result sql.Result, err error) {
|
||||
return Model.Data(r).Insert()
|
||||
}
|
||||
|
||||
// InsertIgnore does "INSERT IGNORE INTO ..." statement for inserting current object into table.
|
||||
func (r *Entity) InsertIgnore() (result sql.Result, err error) {
|
||||
return Model.Data(r).InsertIgnore()
|
||||
}
|
||||
|
||||
// Replace does "REPLACE...INTO..." statement for inserting current object into table.
|
||||
// If there's already another same record in the table (it checks using primary key or unique index),
|
||||
// it deletes it and insert this one.
|
||||
|
||||
@@ -8,12 +8,13 @@ import (
|
||||
"database/sql"
|
||||
"github.com/gogf/gf/database/gdb"
|
||||
"github.com/gogf/gf/frame/g"
|
||||
"github.com/gogf/gf/frame/gmvc"
|
||||
"time"
|
||||
)
|
||||
|
||||
// arModel is a active record design model for table casbin_rule operations.
|
||||
type arModel struct {
|
||||
M *gdb.Model
|
||||
gmvc.M
|
||||
}
|
||||
|
||||
var (
|
||||
@@ -21,6 +22,24 @@ var (
|
||||
Table = "casbin_rule"
|
||||
// Model is the model object of casbin_rule.
|
||||
Model = &arModel{g.DB("default").Table(Table).Safe()}
|
||||
// Columns defines and stores column names for table casbin_rule.
|
||||
Columns = struct {
|
||||
Ptype string //
|
||||
V0 string //
|
||||
V1 string //
|
||||
V2 string //
|
||||
V3 string //
|
||||
V4 string //
|
||||
V5 string //
|
||||
}{
|
||||
Ptype: "ptype",
|
||||
V0: "v0",
|
||||
V1: "v1",
|
||||
V2: "v2",
|
||||
V3: "v3",
|
||||
V4: "v4",
|
||||
V5: "v5",
|
||||
}
|
||||
)
|
||||
|
||||
// FindOne is a convenience method for Model.FindOne.
|
||||
@@ -41,6 +60,12 @@ func FindValue(fieldsAndWhere ...interface{}) (gdb.Value, error) {
|
||||
return Model.FindValue(fieldsAndWhere...)
|
||||
}
|
||||
|
||||
// FindArray is a convenience method for Model.FindArray.
|
||||
// See Model.FindArray.
|
||||
func FindArray(fieldsAndWhere ...interface{}) ([]gdb.Value, error) {
|
||||
return Model.FindArray(fieldsAndWhere...)
|
||||
}
|
||||
|
||||
// FindCount is a convenience method for Model.FindCount.
|
||||
// See Model.FindCount.
|
||||
func FindCount(where ...interface{}) (int, error) {
|
||||
@@ -52,6 +77,11 @@ func Insert(data ...interface{}) (result sql.Result, err error) {
|
||||
return Model.Insert(data...)
|
||||
}
|
||||
|
||||
// InsertIgnore is a convenience method for Model.InsertIgnore.
|
||||
func InsertIgnore(data ...interface{}) (result sql.Result, err error) {
|
||||
return Model.InsertIgnore(data...)
|
||||
}
|
||||
|
||||
// Replace is a convenience method for Model.Replace.
|
||||
func Replace(data ...interface{}) (result sql.Result, err error) {
|
||||
return Model.Replace(data...)
|
||||
@@ -94,18 +124,30 @@ func (m *arModel) Slave() *arModel {
|
||||
}
|
||||
|
||||
// LeftJoin does "LEFT JOIN ... ON ..." statement on the model.
|
||||
func (m *arModel) LeftJoin(joinTable string, on string) *arModel {
|
||||
return &arModel{m.M.LeftJoin(joinTable, on)}
|
||||
// The parameter <table> can be joined table and its joined condition,
|
||||
// and also with its alias name, like:
|
||||
// Table("user").LeftJoin("user_detail", "user_detail.uid=user.uid")
|
||||
// Table("user", "u").LeftJoin("user_detail", "ud", "ud.uid=u.uid")
|
||||
func (m *arModel) LeftJoin(table ...string) *arModel {
|
||||
return &arModel{m.M.LeftJoin(table...)}
|
||||
}
|
||||
|
||||
// RightJoin does "RIGHT JOIN ... ON ..." statement on the model.
|
||||
func (m *arModel) RightJoin(joinTable string, on string) *arModel {
|
||||
return &arModel{m.M.RightJoin(joinTable, on)}
|
||||
// The parameter <table> can be joined table and its joined condition,
|
||||
// and also with its alias name, like:
|
||||
// Table("user").RightJoin("user_detail", "user_detail.uid=user.uid")
|
||||
// Table("user", "u").RightJoin("user_detail", "ud", "ud.uid=u.uid")
|
||||
func (m *arModel) RightJoin(table ...string) *arModel {
|
||||
return &arModel{m.M.RightJoin(table...)}
|
||||
}
|
||||
|
||||
// InnerJoin does "INNER JOIN ... ON ..." statement on the model.
|
||||
func (m *arModel) InnerJoin(joinTable string, on string) *arModel {
|
||||
return &arModel{m.M.InnerJoin(joinTable, on)}
|
||||
// The parameter <table> can be joined table and its joined condition,
|
||||
// and also with its alias name, like:
|
||||
// Table("user").InnerJoin("user_detail", "user_detail.uid=user.uid")
|
||||
// Table("user", "u").InnerJoin("user_detail", "ud", "ud.uid=u.uid")
|
||||
func (m *arModel) InnerJoin(table ...string) *arModel {
|
||||
return &arModel{m.M.InnerJoin(table...)}
|
||||
}
|
||||
|
||||
// Fields sets the operation fields of the model, multiple fields joined using char ','.
|
||||
@@ -165,8 +207,8 @@ func (m *arModel) Group(groupBy string) *arModel {
|
||||
}
|
||||
|
||||
// Order sets the "ORDER BY" statement for the model.
|
||||
func (m *arModel) Order(orderBy string) *arModel {
|
||||
return &arModel{m.M.Order(orderBy)}
|
||||
func (m *arModel) Order(orderBy ...string) *arModel {
|
||||
return &arModel{m.M.Order(orderBy...)}
|
||||
}
|
||||
|
||||
// Limit sets the "LIMIT" statement for the model.
|
||||
@@ -207,8 +249,8 @@ func (m *arModel) Batch(batch int) *arModel {
|
||||
// control the cache like changing the <duration> or clearing the cache with specified <name>.
|
||||
//
|
||||
// Note that, the cache feature is disabled if the model is operating on a transaction.
|
||||
func (m *arModel) Cache(expire time.Duration, name ...string) *arModel {
|
||||
return &arModel{m.M.Cache(expire, name...)}
|
||||
func (m *arModel) Cache(duration time.Duration, name ...string) *arModel {
|
||||
return &arModel{m.M.Cache(duration, name...)}
|
||||
}
|
||||
|
||||
// Data sets the operation data for the model.
|
||||
@@ -222,53 +264,6 @@ func (m *arModel) Data(data ...interface{}) *arModel {
|
||||
return &arModel{m.M.Data(data...)}
|
||||
}
|
||||
|
||||
// Insert does "INSERT INTO ..." statement for the model.
|
||||
// The optional parameter <data> is the same as the parameter of Model.Data function,
|
||||
// see Model.Data.
|
||||
func (m *arModel) Insert(data ...interface{}) (result sql.Result, err error) {
|
||||
return m.M.Insert(data...)
|
||||
}
|
||||
|
||||
// Replace does "REPLACE INTO ..." statement for the model.
|
||||
// The optional parameter <data> is the same as the parameter of Model.Data function,
|
||||
// see Model.Data.
|
||||
func (m *arModel) Replace(data ...interface{}) (result sql.Result, err error) {
|
||||
return m.M.Replace(data...)
|
||||
}
|
||||
|
||||
// Save does "INSERT INTO ... ON DUPLICATE KEY UPDATE..." statement for the model.
|
||||
// It updates the record if there's primary or unique index in the saving data,
|
||||
// or else it inserts a new record into the table.
|
||||
//
|
||||
// The optional parameter <data> is the same as the parameter of Model.Data function,
|
||||
// see Model.Data.
|
||||
func (m *arModel) Save(data ...interface{}) (result sql.Result, err error) {
|
||||
return m.M.Save(data...)
|
||||
}
|
||||
|
||||
// Update does "UPDATE ... " statement for the model.
|
||||
//
|
||||
// If the optional parameter <dataAndWhere> is given, the dataAndWhere[0] is the updated
|
||||
// data field, and dataAndWhere[1:] is treated as where condition fields.
|
||||
// Also see Model.Data and Model.Where functions.
|
||||
func (m *arModel) Update(dataAndWhere ...interface{}) (result sql.Result, err error) {
|
||||
return m.M.Update(dataAndWhere...)
|
||||
}
|
||||
|
||||
// Delete does "DELETE FROM ... " statement for the model.
|
||||
// The optional parameter <where> is the same as the parameter of Model.Where function,
|
||||
// see Model.Where.
|
||||
func (m *arModel) Delete(where ...interface{}) (result sql.Result, err error) {
|
||||
return m.M.Delete(where...)
|
||||
}
|
||||
|
||||
// Count does "SELECT COUNT(x) FROM ..." statement for the model.
|
||||
// The optional parameter <where> is the same as the parameter of Model.Where function,
|
||||
// see Model.Where.
|
||||
func (m *arModel) Count(where ...interface{}) (int, error) {
|
||||
return m.M.Count(where...)
|
||||
}
|
||||
|
||||
// All does "SELECT FROM ..." statement for the model.
|
||||
// It retrieves the records from table and returns the result as []*Entity.
|
||||
// It returns nil if there's no record retrieved with the given conditions from table.
|
||||
@@ -304,16 +299,6 @@ func (m *arModel) One(where ...interface{}) (*Entity, error) {
|
||||
return entity, nil
|
||||
}
|
||||
|
||||
// Value retrieves a specified record value from table and returns the result as interface type.
|
||||
// It returns nil if there's no record found with the given conditions from table.
|
||||
//
|
||||
// If the optional parameter <fieldsAndWhere> is given, the fieldsAndWhere[0] is the selected fields
|
||||
// and fieldsAndWhere[1:] is treated as where condition fields.
|
||||
// Also see Model.Fields and Model.Where functions.
|
||||
func (m *arModel) Value(fieldsAndWhere ...interface{}) (gdb.Value, error) {
|
||||
return m.M.Value(fieldsAndWhere...)
|
||||
}
|
||||
|
||||
// FindOne retrieves and returns a single Record by Model.WherePri and Model.One.
|
||||
// Also see Model.WherePri and Model.One.
|
||||
func (m *arModel) FindOne(where ...interface{}) (*Entity, error) {
|
||||
@@ -342,18 +327,6 @@ func (m *arModel) FindAll(where ...interface{}) ([]*Entity, error) {
|
||||
return entities, nil
|
||||
}
|
||||
|
||||
// FindValue retrieves and returns single field value by Model.WherePri and Model.Value.
|
||||
// Also see Model.WherePri and Model.Value.
|
||||
func (m *arModel) FindValue(fieldsAndWhere ...interface{}) (gdb.Value, error) {
|
||||
return m.M.FindValue(fieldsAndWhere...)
|
||||
}
|
||||
|
||||
// FindCount retrieves and returns the record number by Model.WherePri and Model.Count.
|
||||
// Also see Model.WherePri and Model.Count.
|
||||
func (m *arModel) FindCount(where ...interface{}) (int, error) {
|
||||
return m.M.FindCount(where...)
|
||||
}
|
||||
|
||||
// Chunk iterates the table with given size and callback function.
|
||||
func (m *arModel) Chunk(limit int, callback func(entities []*Entity, err error) bool) {
|
||||
m.M.Chunk(limit, func(result gdb.Result, err error) bool {
|
||||
@@ -365,3 +338,18 @@ func (m *arModel) Chunk(limit int, callback func(entities []*Entity, err error)
|
||||
return callback(entities, err)
|
||||
})
|
||||
}
|
||||
|
||||
// LockUpdate sets the lock for update for current operation.
|
||||
func (m *arModel) LockUpdate() *arModel {
|
||||
return &arModel{m.M.LockUpdate()}
|
||||
}
|
||||
|
||||
// LockShared sets the lock in share mode for current operation.
|
||||
func (m *arModel) LockShared() *arModel {
|
||||
return &arModel{m.M.LockShared()}
|
||||
}
|
||||
|
||||
// Unscoped enables/disables the soft deleting feature.
|
||||
func (m *arModel) Unscoped() *arModel {
|
||||
return &arModel{m.M.Unscoped()}
|
||||
}
|
||||
|
||||
@@ -13,12 +13,12 @@ import (
|
||||
type Entity struct {
|
||||
Id uint64 `orm:"id,primary" json:"id"` // 分类id
|
||||
ParentId int64 `orm:"parent_id" json:"parent_id"` // 分类父id
|
||||
ModelId uint `orm:"model_id" json:"model_id"` // 模型id
|
||||
ModelId uint `orm:"model_id" json:"model_id"` // 模型ID
|
||||
Status uint `orm:"status" json:"status"` // 状态,1:发布,0:不发布
|
||||
DeleteTime uint `orm:"delete_time" json:"delete_time"` // 删除时间
|
||||
ListOrder float64 `orm:"list_order" json:"list_order"` // 排序
|
||||
Name string `orm:"name" json:"name"` // 分类名称
|
||||
Alias string `orm:"alias" json:"alias"` // 分类别名
|
||||
Alias string `orm:"alias" json:"alias"` // 栏目别名
|
||||
Description string `orm:"description" json:"description"` // 分类描述
|
||||
SeoTitle string `orm:"seo_title" json:"seo_title"` //
|
||||
SeoKeywords string `orm:"seo_keywords" json:"seo_keywords"` //
|
||||
@@ -42,6 +42,11 @@ func (r *Entity) Insert() (result sql.Result, err error) {
|
||||
return Model.Data(r).Insert()
|
||||
}
|
||||
|
||||
// InsertIgnore does "INSERT IGNORE INTO ..." statement for inserting current object into table.
|
||||
func (r *Entity) InsertIgnore() (result sql.Result, err error) {
|
||||
return Model.Data(r).InsertIgnore()
|
||||
}
|
||||
|
||||
// Replace does "REPLACE...INTO..." statement for inserting current object into table.
|
||||
// If there's already another same record in the table (it checks using primary key or unique index),
|
||||
// it deletes it and insert this one.
|
||||
|
||||
@@ -8,12 +8,13 @@ import (
|
||||
"database/sql"
|
||||
"github.com/gogf/gf/database/gdb"
|
||||
"github.com/gogf/gf/frame/g"
|
||||
"github.com/gogf/gf/frame/gmvc"
|
||||
"time"
|
||||
)
|
||||
|
||||
// arModel is a active record design model for table cms_category operations.
|
||||
type arModel struct {
|
||||
M *gdb.Model
|
||||
gmvc.M
|
||||
}
|
||||
|
||||
var (
|
||||
@@ -21,6 +22,46 @@ var (
|
||||
Table = "cms_category"
|
||||
// Model is the model object of cms_category.
|
||||
Model = &arModel{g.DB("default").Table(Table).Safe()}
|
||||
// Columns defines and stores column names for table cms_category.
|
||||
Columns = struct {
|
||||
Id string // 分类id
|
||||
ParentId string // 分类父id
|
||||
ModelId string // 模型ID
|
||||
Status string // 状态,1:发布,0:不发布
|
||||
DeleteTime string // 删除时间
|
||||
ListOrder string // 排序
|
||||
Name string // 分类名称
|
||||
Alias string // 栏目别名
|
||||
Description string // 分类描述
|
||||
SeoTitle string //
|
||||
SeoKeywords string //
|
||||
SeoDescription string //
|
||||
ListTpl string // 分类列表模板
|
||||
OneTpl string // 分类文章页模板
|
||||
More string // 扩展属性
|
||||
CateType string // 分类类型
|
||||
CateAddress string // 跳转地址
|
||||
CateContent string // 单页内容
|
||||
}{
|
||||
Id: "id",
|
||||
ParentId: "parent_id",
|
||||
ModelId: "model_id",
|
||||
Status: "status",
|
||||
DeleteTime: "delete_time",
|
||||
ListOrder: "list_order",
|
||||
Name: "name",
|
||||
Alias: "alias",
|
||||
Description: "description",
|
||||
SeoTitle: "seo_title",
|
||||
SeoKeywords: "seo_keywords",
|
||||
SeoDescription: "seo_description",
|
||||
ListTpl: "list_tpl",
|
||||
OneTpl: "one_tpl",
|
||||
More: "more",
|
||||
CateType: "cate_type",
|
||||
CateAddress: "cate_address",
|
||||
CateContent: "cate_content",
|
||||
}
|
||||
)
|
||||
|
||||
// FindOne is a convenience method for Model.FindOne.
|
||||
@@ -41,6 +82,12 @@ func FindValue(fieldsAndWhere ...interface{}) (gdb.Value, error) {
|
||||
return Model.FindValue(fieldsAndWhere...)
|
||||
}
|
||||
|
||||
// FindArray is a convenience method for Model.FindArray.
|
||||
// See Model.FindArray.
|
||||
func FindArray(fieldsAndWhere ...interface{}) ([]gdb.Value, error) {
|
||||
return Model.FindArray(fieldsAndWhere...)
|
||||
}
|
||||
|
||||
// FindCount is a convenience method for Model.FindCount.
|
||||
// See Model.FindCount.
|
||||
func FindCount(where ...interface{}) (int, error) {
|
||||
@@ -52,6 +99,11 @@ func Insert(data ...interface{}) (result sql.Result, err error) {
|
||||
return Model.Insert(data...)
|
||||
}
|
||||
|
||||
// InsertIgnore is a convenience method for Model.InsertIgnore.
|
||||
func InsertIgnore(data ...interface{}) (result sql.Result, err error) {
|
||||
return Model.InsertIgnore(data...)
|
||||
}
|
||||
|
||||
// Replace is a convenience method for Model.Replace.
|
||||
func Replace(data ...interface{}) (result sql.Result, err error) {
|
||||
return Model.Replace(data...)
|
||||
@@ -94,18 +146,30 @@ func (m *arModel) Slave() *arModel {
|
||||
}
|
||||
|
||||
// LeftJoin does "LEFT JOIN ... ON ..." statement on the model.
|
||||
func (m *arModel) LeftJoin(joinTable string, on string) *arModel {
|
||||
return &arModel{m.M.LeftJoin(joinTable, on)}
|
||||
// The parameter <table> can be joined table and its joined condition,
|
||||
// and also with its alias name, like:
|
||||
// Table("user").LeftJoin("user_detail", "user_detail.uid=user.uid")
|
||||
// Table("user", "u").LeftJoin("user_detail", "ud", "ud.uid=u.uid")
|
||||
func (m *arModel) LeftJoin(table ...string) *arModel {
|
||||
return &arModel{m.M.LeftJoin(table...)}
|
||||
}
|
||||
|
||||
// RightJoin does "RIGHT JOIN ... ON ..." statement on the model.
|
||||
func (m *arModel) RightJoin(joinTable string, on string) *arModel {
|
||||
return &arModel{m.M.RightJoin(joinTable, on)}
|
||||
// The parameter <table> can be joined table and its joined condition,
|
||||
// and also with its alias name, like:
|
||||
// Table("user").RightJoin("user_detail", "user_detail.uid=user.uid")
|
||||
// Table("user", "u").RightJoin("user_detail", "ud", "ud.uid=u.uid")
|
||||
func (m *arModel) RightJoin(table ...string) *arModel {
|
||||
return &arModel{m.M.RightJoin(table...)}
|
||||
}
|
||||
|
||||
// InnerJoin does "INNER JOIN ... ON ..." statement on the model.
|
||||
func (m *arModel) InnerJoin(joinTable string, on string) *arModel {
|
||||
return &arModel{m.M.InnerJoin(joinTable, on)}
|
||||
// The parameter <table> can be joined table and its joined condition,
|
||||
// and also with its alias name, like:
|
||||
// Table("user").InnerJoin("user_detail", "user_detail.uid=user.uid")
|
||||
// Table("user", "u").InnerJoin("user_detail", "ud", "ud.uid=u.uid")
|
||||
func (m *arModel) InnerJoin(table ...string) *arModel {
|
||||
return &arModel{m.M.InnerJoin(table...)}
|
||||
}
|
||||
|
||||
// Fields sets the operation fields of the model, multiple fields joined using char ','.
|
||||
@@ -165,8 +229,8 @@ func (m *arModel) Group(groupBy string) *arModel {
|
||||
}
|
||||
|
||||
// Order sets the "ORDER BY" statement for the model.
|
||||
func (m *arModel) Order(orderBy string) *arModel {
|
||||
return &arModel{m.M.Order(orderBy)}
|
||||
func (m *arModel) Order(orderBy ...string) *arModel {
|
||||
return &arModel{m.M.Order(orderBy...)}
|
||||
}
|
||||
|
||||
// Limit sets the "LIMIT" statement for the model.
|
||||
@@ -207,8 +271,8 @@ func (m *arModel) Batch(batch int) *arModel {
|
||||
// control the cache like changing the <duration> or clearing the cache with specified <name>.
|
||||
//
|
||||
// Note that, the cache feature is disabled if the model is operating on a transaction.
|
||||
func (m *arModel) Cache(expire time.Duration, name ...string) *arModel {
|
||||
return &arModel{m.M.Cache(expire, name...)}
|
||||
func (m *arModel) Cache(duration time.Duration, name ...string) *arModel {
|
||||
return &arModel{m.M.Cache(duration, name...)}
|
||||
}
|
||||
|
||||
// Data sets the operation data for the model.
|
||||
@@ -222,53 +286,6 @@ func (m *arModel) Data(data ...interface{}) *arModel {
|
||||
return &arModel{m.M.Data(data...)}
|
||||
}
|
||||
|
||||
// Insert does "INSERT INTO ..." statement for the model.
|
||||
// The optional parameter <data> is the same as the parameter of Model.Data function,
|
||||
// see Model.Data.
|
||||
func (m *arModel) Insert(data ...interface{}) (result sql.Result, err error) {
|
||||
return m.M.Insert(data...)
|
||||
}
|
||||
|
||||
// Replace does "REPLACE INTO ..." statement for the model.
|
||||
// The optional parameter <data> is the same as the parameter of Model.Data function,
|
||||
// see Model.Data.
|
||||
func (m *arModel) Replace(data ...interface{}) (result sql.Result, err error) {
|
||||
return m.M.Replace(data...)
|
||||
}
|
||||
|
||||
// Save does "INSERT INTO ... ON DUPLICATE KEY UPDATE..." statement for the model.
|
||||
// It updates the record if there's primary or unique index in the saving data,
|
||||
// or else it inserts a new record into the table.
|
||||
//
|
||||
// The optional parameter <data> is the same as the parameter of Model.Data function,
|
||||
// see Model.Data.
|
||||
func (m *arModel) Save(data ...interface{}) (result sql.Result, err error) {
|
||||
return m.M.Save(data...)
|
||||
}
|
||||
|
||||
// Update does "UPDATE ... " statement for the model.
|
||||
//
|
||||
// If the optional parameter <dataAndWhere> is given, the dataAndWhere[0] is the updated
|
||||
// data field, and dataAndWhere[1:] is treated as where condition fields.
|
||||
// Also see Model.Data and Model.Where functions.
|
||||
func (m *arModel) Update(dataAndWhere ...interface{}) (result sql.Result, err error) {
|
||||
return m.M.Update(dataAndWhere...)
|
||||
}
|
||||
|
||||
// Delete does "DELETE FROM ... " statement for the model.
|
||||
// The optional parameter <where> is the same as the parameter of Model.Where function,
|
||||
// see Model.Where.
|
||||
func (m *arModel) Delete(where ...interface{}) (result sql.Result, err error) {
|
||||
return m.M.Delete(where...)
|
||||
}
|
||||
|
||||
// Count does "SELECT COUNT(x) FROM ..." statement for the model.
|
||||
// The optional parameter <where> is the same as the parameter of Model.Where function,
|
||||
// see Model.Where.
|
||||
func (m *arModel) Count(where ...interface{}) (int, error) {
|
||||
return m.M.Count(where...)
|
||||
}
|
||||
|
||||
// All does "SELECT FROM ..." statement for the model.
|
||||
// It retrieves the records from table and returns the result as []*Entity.
|
||||
// It returns nil if there's no record retrieved with the given conditions from table.
|
||||
@@ -304,16 +321,6 @@ func (m *arModel) One(where ...interface{}) (*Entity, error) {
|
||||
return entity, nil
|
||||
}
|
||||
|
||||
// Value retrieves a specified record value from table and returns the result as interface type.
|
||||
// It returns nil if there's no record found with the given conditions from table.
|
||||
//
|
||||
// If the optional parameter <fieldsAndWhere> is given, the fieldsAndWhere[0] is the selected fields
|
||||
// and fieldsAndWhere[1:] is treated as where condition fields.
|
||||
// Also see Model.Fields and Model.Where functions.
|
||||
func (m *arModel) Value(fieldsAndWhere ...interface{}) (gdb.Value, error) {
|
||||
return m.M.Value(fieldsAndWhere...)
|
||||
}
|
||||
|
||||
// FindOne retrieves and returns a single Record by Model.WherePri and Model.One.
|
||||
// Also see Model.WherePri and Model.One.
|
||||
func (m *arModel) FindOne(where ...interface{}) (*Entity, error) {
|
||||
@@ -342,18 +349,6 @@ func (m *arModel) FindAll(where ...interface{}) ([]*Entity, error) {
|
||||
return entities, nil
|
||||
}
|
||||
|
||||
// FindValue retrieves and returns single field value by Model.WherePri and Model.Value.
|
||||
// Also see Model.WherePri and Model.Value.
|
||||
func (m *arModel) FindValue(fieldsAndWhere ...interface{}) (gdb.Value, error) {
|
||||
return m.M.FindValue(fieldsAndWhere...)
|
||||
}
|
||||
|
||||
// FindCount retrieves and returns the record number by Model.WherePri and Model.Count.
|
||||
// Also see Model.WherePri and Model.Count.
|
||||
func (m *arModel) FindCount(where ...interface{}) (int, error) {
|
||||
return m.M.FindCount(where...)
|
||||
}
|
||||
|
||||
// Chunk iterates the table with given size and callback function.
|
||||
func (m *arModel) Chunk(limit int, callback func(entities []*Entity, err error) bool) {
|
||||
m.M.Chunk(limit, func(result gdb.Result, err error) bool {
|
||||
@@ -365,3 +360,18 @@ func (m *arModel) Chunk(limit int, callback func(entities []*Entity, err error)
|
||||
return callback(entities, err)
|
||||
})
|
||||
}
|
||||
|
||||
// LockUpdate sets the lock for update for current operation.
|
||||
func (m *arModel) LockUpdate() *arModel {
|
||||
return &arModel{m.M.LockUpdate()}
|
||||
}
|
||||
|
||||
// LockShared sets the lock in share mode for current operation.
|
||||
func (m *arModel) LockShared() *arModel {
|
||||
return &arModel{m.M.LockShared()}
|
||||
}
|
||||
|
||||
// Unscoped enables/disables the soft deleting feature.
|
||||
func (m *arModel) Unscoped() *arModel {
|
||||
return &arModel{m.M.Unscoped()}
|
||||
}
|
||||
|
||||
@@ -27,6 +27,11 @@ func (r *Entity) Insert() (result sql.Result, err error) {
|
||||
return Model.Data(r).Insert()
|
||||
}
|
||||
|
||||
// InsertIgnore does "INSERT IGNORE INTO ..." statement for inserting current object into table.
|
||||
func (r *Entity) InsertIgnore() (result sql.Result, err error) {
|
||||
return Model.Data(r).InsertIgnore()
|
||||
}
|
||||
|
||||
// Replace does "REPLACE...INTO..." statement for inserting current object into table.
|
||||
// If there's already another same record in the table (it checks using primary key or unique index),
|
||||
// it deletes it and insert this one.
|
||||
|
||||
@@ -8,12 +8,13 @@ import (
|
||||
"database/sql"
|
||||
"github.com/gogf/gf/database/gdb"
|
||||
"github.com/gogf/gf/frame/g"
|
||||
"github.com/gogf/gf/frame/gmvc"
|
||||
"time"
|
||||
)
|
||||
|
||||
// arModel is a active record design model for table cms_category_news operations.
|
||||
type arModel struct {
|
||||
M *gdb.Model
|
||||
gmvc.M
|
||||
}
|
||||
|
||||
var (
|
||||
@@ -21,6 +22,16 @@ var (
|
||||
Table = "cms_category_news"
|
||||
// Model is the model object of cms_category_news.
|
||||
Model = &arModel{g.DB("default").Table(Table).Safe()}
|
||||
// Columns defines and stores column names for table cms_category_news.
|
||||
Columns = struct {
|
||||
Id string //
|
||||
NewsId string // 文章id
|
||||
CategoryId string // 分类id
|
||||
}{
|
||||
Id: "id",
|
||||
NewsId: "news_id",
|
||||
CategoryId: "category_id",
|
||||
}
|
||||
)
|
||||
|
||||
// FindOne is a convenience method for Model.FindOne.
|
||||
@@ -41,6 +52,12 @@ func FindValue(fieldsAndWhere ...interface{}) (gdb.Value, error) {
|
||||
return Model.FindValue(fieldsAndWhere...)
|
||||
}
|
||||
|
||||
// FindArray is a convenience method for Model.FindArray.
|
||||
// See Model.FindArray.
|
||||
func FindArray(fieldsAndWhere ...interface{}) ([]gdb.Value, error) {
|
||||
return Model.FindArray(fieldsAndWhere...)
|
||||
}
|
||||
|
||||
// FindCount is a convenience method for Model.FindCount.
|
||||
// See Model.FindCount.
|
||||
func FindCount(where ...interface{}) (int, error) {
|
||||
@@ -52,6 +69,11 @@ func Insert(data ...interface{}) (result sql.Result, err error) {
|
||||
return Model.Insert(data...)
|
||||
}
|
||||
|
||||
// InsertIgnore is a convenience method for Model.InsertIgnore.
|
||||
func InsertIgnore(data ...interface{}) (result sql.Result, err error) {
|
||||
return Model.InsertIgnore(data...)
|
||||
}
|
||||
|
||||
// Replace is a convenience method for Model.Replace.
|
||||
func Replace(data ...interface{}) (result sql.Result, err error) {
|
||||
return Model.Replace(data...)
|
||||
@@ -94,18 +116,30 @@ func (m *arModel) Slave() *arModel {
|
||||
}
|
||||
|
||||
// LeftJoin does "LEFT JOIN ... ON ..." statement on the model.
|
||||
func (m *arModel) LeftJoin(joinTable string, on string) *arModel {
|
||||
return &arModel{m.M.LeftJoin(joinTable, on)}
|
||||
// The parameter <table> can be joined table and its joined condition,
|
||||
// and also with its alias name, like:
|
||||
// Table("user").LeftJoin("user_detail", "user_detail.uid=user.uid")
|
||||
// Table("user", "u").LeftJoin("user_detail", "ud", "ud.uid=u.uid")
|
||||
func (m *arModel) LeftJoin(table ...string) *arModel {
|
||||
return &arModel{m.M.LeftJoin(table...)}
|
||||
}
|
||||
|
||||
// RightJoin does "RIGHT JOIN ... ON ..." statement on the model.
|
||||
func (m *arModel) RightJoin(joinTable string, on string) *arModel {
|
||||
return &arModel{m.M.RightJoin(joinTable, on)}
|
||||
// The parameter <table> can be joined table and its joined condition,
|
||||
// and also with its alias name, like:
|
||||
// Table("user").RightJoin("user_detail", "user_detail.uid=user.uid")
|
||||
// Table("user", "u").RightJoin("user_detail", "ud", "ud.uid=u.uid")
|
||||
func (m *arModel) RightJoin(table ...string) *arModel {
|
||||
return &arModel{m.M.RightJoin(table...)}
|
||||
}
|
||||
|
||||
// InnerJoin does "INNER JOIN ... ON ..." statement on the model.
|
||||
func (m *arModel) InnerJoin(joinTable string, on string) *arModel {
|
||||
return &arModel{m.M.InnerJoin(joinTable, on)}
|
||||
// The parameter <table> can be joined table and its joined condition,
|
||||
// and also with its alias name, like:
|
||||
// Table("user").InnerJoin("user_detail", "user_detail.uid=user.uid")
|
||||
// Table("user", "u").InnerJoin("user_detail", "ud", "ud.uid=u.uid")
|
||||
func (m *arModel) InnerJoin(table ...string) *arModel {
|
||||
return &arModel{m.M.InnerJoin(table...)}
|
||||
}
|
||||
|
||||
// Fields sets the operation fields of the model, multiple fields joined using char ','.
|
||||
@@ -165,8 +199,8 @@ func (m *arModel) Group(groupBy string) *arModel {
|
||||
}
|
||||
|
||||
// Order sets the "ORDER BY" statement for the model.
|
||||
func (m *arModel) Order(orderBy string) *arModel {
|
||||
return &arModel{m.M.Order(orderBy)}
|
||||
func (m *arModel) Order(orderBy ...string) *arModel {
|
||||
return &arModel{m.M.Order(orderBy...)}
|
||||
}
|
||||
|
||||
// Limit sets the "LIMIT" statement for the model.
|
||||
@@ -207,8 +241,8 @@ func (m *arModel) Batch(batch int) *arModel {
|
||||
// control the cache like changing the <duration> or clearing the cache with specified <name>.
|
||||
//
|
||||
// Note that, the cache feature is disabled if the model is operating on a transaction.
|
||||
func (m *arModel) Cache(expire time.Duration, name ...string) *arModel {
|
||||
return &arModel{m.M.Cache(expire, name...)}
|
||||
func (m *arModel) Cache(duration time.Duration, name ...string) *arModel {
|
||||
return &arModel{m.M.Cache(duration, name...)}
|
||||
}
|
||||
|
||||
// Data sets the operation data for the model.
|
||||
@@ -222,53 +256,6 @@ func (m *arModel) Data(data ...interface{}) *arModel {
|
||||
return &arModel{m.M.Data(data...)}
|
||||
}
|
||||
|
||||
// Insert does "INSERT INTO ..." statement for the model.
|
||||
// The optional parameter <data> is the same as the parameter of Model.Data function,
|
||||
// see Model.Data.
|
||||
func (m *arModel) Insert(data ...interface{}) (result sql.Result, err error) {
|
||||
return m.M.Insert(data...)
|
||||
}
|
||||
|
||||
// Replace does "REPLACE INTO ..." statement for the model.
|
||||
// The optional parameter <data> is the same as the parameter of Model.Data function,
|
||||
// see Model.Data.
|
||||
func (m *arModel) Replace(data ...interface{}) (result sql.Result, err error) {
|
||||
return m.M.Replace(data...)
|
||||
}
|
||||
|
||||
// Save does "INSERT INTO ... ON DUPLICATE KEY UPDATE..." statement for the model.
|
||||
// It updates the record if there's primary or unique index in the saving data,
|
||||
// or else it inserts a new record into the table.
|
||||
//
|
||||
// The optional parameter <data> is the same as the parameter of Model.Data function,
|
||||
// see Model.Data.
|
||||
func (m *arModel) Save(data ...interface{}) (result sql.Result, err error) {
|
||||
return m.M.Save(data...)
|
||||
}
|
||||
|
||||
// Update does "UPDATE ... " statement for the model.
|
||||
//
|
||||
// If the optional parameter <dataAndWhere> is given, the dataAndWhere[0] is the updated
|
||||
// data field, and dataAndWhere[1:] is treated as where condition fields.
|
||||
// Also see Model.Data and Model.Where functions.
|
||||
func (m *arModel) Update(dataAndWhere ...interface{}) (result sql.Result, err error) {
|
||||
return m.M.Update(dataAndWhere...)
|
||||
}
|
||||
|
||||
// Delete does "DELETE FROM ... " statement for the model.
|
||||
// The optional parameter <where> is the same as the parameter of Model.Where function,
|
||||
// see Model.Where.
|
||||
func (m *arModel) Delete(where ...interface{}) (result sql.Result, err error) {
|
||||
return m.M.Delete(where...)
|
||||
}
|
||||
|
||||
// Count does "SELECT COUNT(x) FROM ..." statement for the model.
|
||||
// The optional parameter <where> is the same as the parameter of Model.Where function,
|
||||
// see Model.Where.
|
||||
func (m *arModel) Count(where ...interface{}) (int, error) {
|
||||
return m.M.Count(where...)
|
||||
}
|
||||
|
||||
// All does "SELECT FROM ..." statement for the model.
|
||||
// It retrieves the records from table and returns the result as []*Entity.
|
||||
// It returns nil if there's no record retrieved with the given conditions from table.
|
||||
@@ -304,16 +291,6 @@ func (m *arModel) One(where ...interface{}) (*Entity, error) {
|
||||
return entity, nil
|
||||
}
|
||||
|
||||
// Value retrieves a specified record value from table and returns the result as interface type.
|
||||
// It returns nil if there's no record found with the given conditions from table.
|
||||
//
|
||||
// If the optional parameter <fieldsAndWhere> is given, the fieldsAndWhere[0] is the selected fields
|
||||
// and fieldsAndWhere[1:] is treated as where condition fields.
|
||||
// Also see Model.Fields and Model.Where functions.
|
||||
func (m *arModel) Value(fieldsAndWhere ...interface{}) (gdb.Value, error) {
|
||||
return m.M.Value(fieldsAndWhere...)
|
||||
}
|
||||
|
||||
// FindOne retrieves and returns a single Record by Model.WherePri and Model.One.
|
||||
// Also see Model.WherePri and Model.One.
|
||||
func (m *arModel) FindOne(where ...interface{}) (*Entity, error) {
|
||||
@@ -342,18 +319,6 @@ func (m *arModel) FindAll(where ...interface{}) ([]*Entity, error) {
|
||||
return entities, nil
|
||||
}
|
||||
|
||||
// FindValue retrieves and returns single field value by Model.WherePri and Model.Value.
|
||||
// Also see Model.WherePri and Model.Value.
|
||||
func (m *arModel) FindValue(fieldsAndWhere ...interface{}) (gdb.Value, error) {
|
||||
return m.M.FindValue(fieldsAndWhere...)
|
||||
}
|
||||
|
||||
// FindCount retrieves and returns the record number by Model.WherePri and Model.Count.
|
||||
// Also see Model.WherePri and Model.Count.
|
||||
func (m *arModel) FindCount(where ...interface{}) (int, error) {
|
||||
return m.M.FindCount(where...)
|
||||
}
|
||||
|
||||
// Chunk iterates the table with given size and callback function.
|
||||
func (m *arModel) Chunk(limit int, callback func(entities []*Entity, err error) bool) {
|
||||
m.M.Chunk(limit, func(result gdb.Result, err error) bool {
|
||||
@@ -365,3 +330,18 @@ func (m *arModel) Chunk(limit int, callback func(entities []*Entity, err error)
|
||||
return callback(entities, err)
|
||||
})
|
||||
}
|
||||
|
||||
// LockUpdate sets the lock for update for current operation.
|
||||
func (m *arModel) LockUpdate() *arModel {
|
||||
return &arModel{m.M.LockUpdate()}
|
||||
}
|
||||
|
||||
// LockShared sets the lock in share mode for current operation.
|
||||
func (m *arModel) LockShared() *arModel {
|
||||
return &arModel{m.M.LockShared()}
|
||||
}
|
||||
|
||||
// Unscoped enables/disables the soft deleting feature.
|
||||
func (m *arModel) Unscoped() *arModel {
|
||||
return &arModel{m.M.Unscoped()}
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ type ReqEditParams struct {
|
||||
}
|
||||
|
||||
//添加文章操作
|
||||
func AddNews(req *ReqAddParams, cateIds []int, userId int, tx *gdb.TX) (insId int64, err error) {
|
||||
func AddNews(req *ReqAddParams, cateIds []int, userId uint64, tx *gdb.TX) (insId int64, err error) {
|
||||
if len(cateIds) == 0 {
|
||||
err = gerror.New("栏目不能为空")
|
||||
return
|
||||
|
||||
@@ -21,7 +21,7 @@ type AddReq struct {
|
||||
ModelTitle string `p:"modelTitle" v:"required#模型名称不能为空"`
|
||||
ModelStatus uint `p:"modelStatus" v:"required#状态不能为空"`
|
||||
ModelEngine string `p:"modelEngine" `
|
||||
CreateBy int //添加人
|
||||
CreateBy uint64 //添加人
|
||||
}
|
||||
|
||||
// EditReq 用于存储修改请求参数
|
||||
@@ -32,7 +32,7 @@ type EditReq struct {
|
||||
ModelTitle string `p:"modelTitle" `
|
||||
ModelStatus int `p:"modelStatus" v:"required#状态不能为空"`
|
||||
ModelEngine string `p:"modelEngine" `
|
||||
UpdateBy int
|
||||
UpdateBy uint64
|
||||
}
|
||||
|
||||
//模型字段属性修改请求参数
|
||||
|
||||
@@ -30,7 +30,7 @@ type SelectPageReq struct {
|
||||
//修改状态参数
|
||||
type StatusSetReq struct {
|
||||
RoleId uint `p:"roleId" v:"required#角色ID不能为空"`
|
||||
Status int `p:"status" v:"required#状态不能为空"`
|
||||
Status uint `p:"status" v:"required#状态不能为空"`
|
||||
}
|
||||
|
||||
//角色数据授权参数
|
||||
@@ -90,7 +90,7 @@ func GetList() (list []*Entity, err error) {
|
||||
return
|
||||
}
|
||||
//从数据库获取
|
||||
list, err = Model.OrderBy("list_order asc,id asc").All()
|
||||
list, err = Model.Order("list_order asc,id asc").All()
|
||||
//缓存数据
|
||||
cache.Set(cache_service.AdminAuthRole, list, 0, cache_service.AdminAuthTag)
|
||||
return
|
||||
|
||||
@@ -9,21 +9,18 @@ import (
|
||||
"github.com/gogf/gf/database/gdb"
|
||||
)
|
||||
|
||||
// Entity is the golang structure for table _role.
|
||||
// Entity is the golang structure for table role.
|
||||
type Entity struct {
|
||||
Id int `orm:"id,primary" json:"id"` //
|
||||
Status int `orm:"status" json:"status"` // 状态;0:禁用;1:正常
|
||||
CreateTime int `orm:"create_time" json:"create_time"` // 创建时间
|
||||
UpdateTime int `orm:"update_time" json:"update_time"` // 更新时间
|
||||
ListOrder float64 `orm:"list_order" json:"list_order"` // 排序
|
||||
Name string `orm:"name" json:"name"` // 角色名称
|
||||
Remark string `orm:"remark" json:"remark"` // 备注
|
||||
DataScope int `orm:"data_scope" json:"data_scope"` // 数据范围(1:全部数据权限 2:自定数据权限 3:本部门数据权限 4:本部门及以下数据权限)
|
||||
Id uint `orm:"id,primary" json:"id"` //
|
||||
Status uint `orm:"status" json:"status"` // 状态;0:禁用;1:正常
|
||||
CreateTime uint `orm:"create_time" json:"create_time"` // 创建时间
|
||||
UpdateTime uint `orm:"update_time" json:"update_time"` // 更新时间
|
||||
ListOrder float64 `orm:"list_order" json:"list_order"` // 排序
|
||||
Name string `orm:"name" json:"name"` // 角色名称
|
||||
Remark string `orm:"remark" json:"remark"` // 备注
|
||||
DataScope uint `orm:"data_scope" json:"data_scope"` // 数据范围(1:全部数据权限 2:自定数据权限 3:本部门数据权限 4:本部门及以下数据权限)
|
||||
}
|
||||
|
||||
// Role is alias of Entity, which some developers say they just want.
|
||||
type Role = Entity
|
||||
|
||||
// OmitEmpty sets OPTION_OMITEMPTY option for the model, which automatically filers
|
||||
// the data and where attributes for empty values.
|
||||
func (r *Entity) OmitEmpty() *arModel {
|
||||
@@ -35,6 +32,11 @@ func (r *Entity) Insert() (result sql.Result, err error) {
|
||||
return Model.Data(r).Insert()
|
||||
}
|
||||
|
||||
// InsertIgnore does "INSERT IGNORE INTO ..." statement for inserting current object into table.
|
||||
func (r *Entity) InsertIgnore() (result sql.Result, err error) {
|
||||
return Model.Data(r).InsertIgnore()
|
||||
}
|
||||
|
||||
// Replace does "REPLACE...INTO..." statement for inserting current object into table.
|
||||
// If there's already another same record in the table (it checks using primary key or unique index),
|
||||
// it deletes it and insert this one.
|
||||
|
||||
@@ -8,21 +8,107 @@ import (
|
||||
"database/sql"
|
||||
"github.com/gogf/gf/database/gdb"
|
||||
"github.com/gogf/gf/frame/g"
|
||||
"github.com/gogf/gf/frame/gmvc"
|
||||
"time"
|
||||
)
|
||||
|
||||
// arModel is a active record design model for table _role operations.
|
||||
// arModel is a active record design model for table role operations.
|
||||
type arModel struct {
|
||||
M *gdb.Model
|
||||
gmvc.M
|
||||
}
|
||||
|
||||
var (
|
||||
// Table is the table name of _role.
|
||||
// Table is the table name of role.
|
||||
Table = "role"
|
||||
// Model is the model object of _role.
|
||||
// Model is the model object of role.
|
||||
Model = &arModel{g.DB("default").Table(Table).Safe()}
|
||||
// Columns defines and stores column names for table role.
|
||||
Columns = struct {
|
||||
Id string //
|
||||
Status string // 状态;0:禁用;1:正常
|
||||
CreateTime string // 创建时间
|
||||
UpdateTime string // 更新时间
|
||||
ListOrder string // 排序
|
||||
Name string // 角色名称
|
||||
Remark string // 备注
|
||||
DataScope string // 数据范围(1:全部数据权限 2:自定数据权限 3:本部门数据权限 4:本部门及以下数据权限)
|
||||
}{
|
||||
Id: "id",
|
||||
Status: "status",
|
||||
CreateTime: "create_time",
|
||||
UpdateTime: "update_time",
|
||||
ListOrder: "list_order",
|
||||
Name: "name",
|
||||
Remark: "remark",
|
||||
DataScope: "data_scope",
|
||||
}
|
||||
)
|
||||
|
||||
// FindOne is a convenience method for Model.FindOne.
|
||||
// See Model.FindOne.
|
||||
func FindOne(where ...interface{}) (*Entity, error) {
|
||||
return Model.FindOne(where...)
|
||||
}
|
||||
|
||||
// FindAll is a convenience method for Model.FindAll.
|
||||
// See Model.FindAll.
|
||||
func FindAll(where ...interface{}) ([]*Entity, error) {
|
||||
return Model.FindAll(where...)
|
||||
}
|
||||
|
||||
// FindValue is a convenience method for Model.FindValue.
|
||||
// See Model.FindValue.
|
||||
func FindValue(fieldsAndWhere ...interface{}) (gdb.Value, error) {
|
||||
return Model.FindValue(fieldsAndWhere...)
|
||||
}
|
||||
|
||||
// FindArray is a convenience method for Model.FindArray.
|
||||
// See Model.FindArray.
|
||||
func FindArray(fieldsAndWhere ...interface{}) ([]gdb.Value, error) {
|
||||
return Model.FindArray(fieldsAndWhere...)
|
||||
}
|
||||
|
||||
// FindCount is a convenience method for Model.FindCount.
|
||||
// See Model.FindCount.
|
||||
func FindCount(where ...interface{}) (int, error) {
|
||||
return Model.FindCount(where...)
|
||||
}
|
||||
|
||||
// Insert is a convenience method for Model.Insert.
|
||||
func Insert(data ...interface{}) (result sql.Result, err error) {
|
||||
return Model.Insert(data...)
|
||||
}
|
||||
|
||||
// InsertIgnore is a convenience method for Model.InsertIgnore.
|
||||
func InsertIgnore(data ...interface{}) (result sql.Result, err error) {
|
||||
return Model.InsertIgnore(data...)
|
||||
}
|
||||
|
||||
// Replace is a convenience method for Model.Replace.
|
||||
func Replace(data ...interface{}) (result sql.Result, err error) {
|
||||
return Model.Replace(data...)
|
||||
}
|
||||
|
||||
// Save is a convenience method for Model.Save.
|
||||
func Save(data ...interface{}) (result sql.Result, err error) {
|
||||
return Model.Save(data...)
|
||||
}
|
||||
|
||||
// Update is a convenience method for Model.Update.
|
||||
func Update(dataAndWhere ...interface{}) (result sql.Result, err error) {
|
||||
return Model.Update(dataAndWhere...)
|
||||
}
|
||||
|
||||
// Delete is a convenience method for Model.Delete.
|
||||
func Delete(where ...interface{}) (result sql.Result, err error) {
|
||||
return Model.Delete(where...)
|
||||
}
|
||||
|
||||
// As sets an alias name for current table.
|
||||
func (m *arModel) As(as string) *arModel {
|
||||
return &arModel{m.M.As(as)}
|
||||
}
|
||||
|
||||
// TX sets the transaction for current operation.
|
||||
func (m *arModel) TX(tx *gdb.TX) *arModel {
|
||||
return &arModel{m.M.TX(tx)}
|
||||
@@ -40,18 +126,30 @@ func (m *arModel) Slave() *arModel {
|
||||
}
|
||||
|
||||
// LeftJoin does "LEFT JOIN ... ON ..." statement on the model.
|
||||
func (m *arModel) LeftJoin(joinTable string, on string) *arModel {
|
||||
return &arModel{m.M.LeftJoin(joinTable, on)}
|
||||
// The parameter <table> can be joined table and its joined condition,
|
||||
// and also with its alias name, like:
|
||||
// Table("user").LeftJoin("user_detail", "user_detail.uid=user.uid")
|
||||
// Table("user", "u").LeftJoin("user_detail", "ud", "ud.uid=u.uid")
|
||||
func (m *arModel) LeftJoin(table ...string) *arModel {
|
||||
return &arModel{m.M.LeftJoin(table...)}
|
||||
}
|
||||
|
||||
// RightJoin does "RIGHT JOIN ... ON ..." statement on the model.
|
||||
func (m *arModel) RightJoin(joinTable string, on string) *arModel {
|
||||
return &arModel{m.M.RightJoin(joinTable, on)}
|
||||
// The parameter <table> can be joined table and its joined condition,
|
||||
// and also with its alias name, like:
|
||||
// Table("user").RightJoin("user_detail", "user_detail.uid=user.uid")
|
||||
// Table("user", "u").RightJoin("user_detail", "ud", "ud.uid=u.uid")
|
||||
func (m *arModel) RightJoin(table ...string) *arModel {
|
||||
return &arModel{m.M.RightJoin(table...)}
|
||||
}
|
||||
|
||||
// InnerJoin does "INNER JOIN ... ON ..." statement on the model.
|
||||
func (m *arModel) InnerJoin(joinTable string, on string) *arModel {
|
||||
return &arModel{m.M.InnerJoin(joinTable, on)}
|
||||
// The parameter <table> can be joined table and its joined condition,
|
||||
// and also with its alias name, like:
|
||||
// Table("user").InnerJoin("user_detail", "user_detail.uid=user.uid")
|
||||
// Table("user", "u").InnerJoin("user_detail", "ud", "ud.uid=u.uid")
|
||||
func (m *arModel) InnerJoin(table ...string) *arModel {
|
||||
return &arModel{m.M.InnerJoin(table...)}
|
||||
}
|
||||
|
||||
// Fields sets the operation fields of the model, multiple fields joined using char ','.
|
||||
@@ -105,14 +203,14 @@ func (m *arModel) Or(where interface{}, args ...interface{}) *arModel {
|
||||
return &arModel{m.M.Or(where, args...)}
|
||||
}
|
||||
|
||||
// GroupBy sets the "GROUP BY" statement for the model.
|
||||
func (m *arModel) GroupBy(groupBy string) *arModel {
|
||||
return &arModel{m.M.GroupBy(groupBy)}
|
||||
// Group sets the "GROUP BY" statement for the model.
|
||||
func (m *arModel) Group(groupBy string) *arModel {
|
||||
return &arModel{m.M.Group(groupBy)}
|
||||
}
|
||||
|
||||
// OrderBy sets the "ORDER BY" statement for the model.
|
||||
func (m *arModel) OrderBy(orderBy string) *arModel {
|
||||
return &arModel{m.M.OrderBy(orderBy)}
|
||||
// Order sets the "ORDER BY" statement for the model.
|
||||
func (m *arModel) Order(orderBy ...string) *arModel {
|
||||
return &arModel{m.M.Order(orderBy...)}
|
||||
}
|
||||
|
||||
// Limit sets the "LIMIT" statement for the model.
|
||||
@@ -129,11 +227,11 @@ func (m *arModel) Offset(offset int) *arModel {
|
||||
return &arModel{m.M.Offset(offset)}
|
||||
}
|
||||
|
||||
// ForPage sets the paging number for the model.
|
||||
// Page sets the paging number for the model.
|
||||
// The parameter <page> is started from 1 for paging.
|
||||
// Note that, it differs that the Limit function start from 0 for "LIMIT" statement.
|
||||
func (m *arModel) ForPage(page, limit int) *arModel {
|
||||
return &arModel{m.M.ForPage(page, limit)}
|
||||
func (m *arModel) Page(page, limit int) *arModel {
|
||||
return &arModel{m.M.Page(page, limit)}
|
||||
}
|
||||
|
||||
// Batch sets the batch operation number for the model.
|
||||
@@ -153,8 +251,8 @@ func (m *arModel) Batch(batch int) *arModel {
|
||||
// control the cache like changing the <duration> or clearing the cache with specified <name>.
|
||||
//
|
||||
// Note that, the cache feature is disabled if the model is operating on a transaction.
|
||||
func (m *arModel) Cache(expire time.Duration, name ...string) *arModel {
|
||||
return &arModel{m.M.Cache(expire, name...)}
|
||||
func (m *arModel) Cache(duration time.Duration, name ...string) *arModel {
|
||||
return &arModel{m.M.Cache(duration, name...)}
|
||||
}
|
||||
|
||||
// Data sets the operation data for the model.
|
||||
@@ -168,43 +266,14 @@ func (m *arModel) Data(data ...interface{}) *arModel {
|
||||
return &arModel{m.M.Data(data...)}
|
||||
}
|
||||
|
||||
// Insert does "INSERT INTO ..." statement for the model.
|
||||
func (m *arModel) Insert() (result sql.Result, err error) {
|
||||
return m.M.Insert()
|
||||
}
|
||||
|
||||
// Replace does "REPLACE INTO ..." statement for the model.
|
||||
func (m *arModel) Replace() (result sql.Result, err error) {
|
||||
return m.M.Replace()
|
||||
}
|
||||
|
||||
// Save does "INSERT INTO ... ON DUPLICATE KEY UPDATE..." statement for the model.
|
||||
// It updates the record if there's primary or unique index in the saving data,
|
||||
// or else it inserts a new record into the table.
|
||||
func (m *arModel) Save() (result sql.Result, err error) {
|
||||
return m.M.Save()
|
||||
}
|
||||
|
||||
// Update does "UPDATE ... " statement for the model.
|
||||
func (m *arModel) Update() (result sql.Result, err error) {
|
||||
return m.M.Update()
|
||||
}
|
||||
|
||||
// Delete does "DELETE FROM ... " statement for the model.
|
||||
func (m *arModel) Delete() (result sql.Result, err error) {
|
||||
return m.M.Delete()
|
||||
}
|
||||
|
||||
// Count does "SELECT COUNT(x) FROM ..." statement for the model.
|
||||
func (m *arModel) Count() (int, error) {
|
||||
return m.M.Count()
|
||||
}
|
||||
|
||||
// All does "SELECT FROM ..." statement for the model.
|
||||
// It retrieves the records from table and returns the result as []*Entity.
|
||||
// It returns nil if there's no record retrieved with the given conditions from table.
|
||||
func (m *arModel) All() ([]*Entity, error) {
|
||||
all, err := m.M.All()
|
||||
//
|
||||
// The optional parameter <where> is the same as the parameter of Model.Where function,
|
||||
// see Model.Where.
|
||||
func (m *arModel) All(where ...interface{}) ([]*Entity, error) {
|
||||
all, err := m.M.All(where...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -217,8 +286,11 @@ func (m *arModel) All() ([]*Entity, error) {
|
||||
|
||||
// One retrieves one record from table and returns the result as *Entity.
|
||||
// It returns nil if there's no record retrieved with the given conditions from table.
|
||||
func (m *arModel) One() (*Entity, error) {
|
||||
one, err := m.M.One()
|
||||
//
|
||||
// The optional parameter <where> is the same as the parameter of Model.Where function,
|
||||
// see Model.Where.
|
||||
func (m *arModel) One(where ...interface{}) (*Entity, error) {
|
||||
one, err := m.M.One(where...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -229,10 +301,32 @@ func (m *arModel) One() (*Entity, error) {
|
||||
return entity, nil
|
||||
}
|
||||
|
||||
// Value retrieves a specified record value from table and returns the result as interface type.
|
||||
// It returns nil if there's no record found with the given conditions from table.
|
||||
func (m *arModel) Value() (gdb.Value, error) {
|
||||
return m.M.Value()
|
||||
// FindOne retrieves and returns a single Record by Model.WherePri and Model.One.
|
||||
// Also see Model.WherePri and Model.One.
|
||||
func (m *arModel) FindOne(where ...interface{}) (*Entity, error) {
|
||||
one, err := m.M.FindOne(where...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var entity *Entity
|
||||
if err = one.Struct(&entity); err != nil && err != sql.ErrNoRows {
|
||||
return nil, err
|
||||
}
|
||||
return entity, nil
|
||||
}
|
||||
|
||||
// FindAll retrieves and returns Result by by Model.WherePri and Model.All.
|
||||
// Also see Model.WherePri and Model.All.
|
||||
func (m *arModel) FindAll(where ...interface{}) ([]*Entity, error) {
|
||||
all, err := m.M.FindAll(where...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var entities []*Entity
|
||||
if err = all.Structs(&entities); err != nil && err != sql.ErrNoRows {
|
||||
return nil, err
|
||||
}
|
||||
return entities, nil
|
||||
}
|
||||
|
||||
// Chunk iterates the table with given size and callback function.
|
||||
@@ -247,14 +341,17 @@ func (m *arModel) Chunk(limit int, callback func(entities []*Entity, err error)
|
||||
})
|
||||
}
|
||||
|
||||
// Page sets the paging number for the model.
|
||||
// The parameter <page> is started from 1 for paging.
|
||||
// Note that, it differs that the Limit function start from 0 for "LIMIT" statement.
|
||||
func (m *arModel) Page(page, limit int) *arModel {
|
||||
return &arModel{m.M.Page(page, limit)}
|
||||
// LockUpdate sets the lock for update for current operation.
|
||||
func (m *arModel) LockUpdate() *arModel {
|
||||
return &arModel{m.M.LockUpdate()}
|
||||
}
|
||||
|
||||
// Order sets the "ORDER BY" statement for the model.
|
||||
func (m *arModel) Order(orderBy string) *arModel {
|
||||
return &arModel{m.M.Order(orderBy)}
|
||||
// LockShared sets the lock in share mode for current operation.
|
||||
func (m *arModel) LockShared() *arModel {
|
||||
return &arModel{m.M.LockShared()}
|
||||
}
|
||||
|
||||
// Unscoped enables/disables the soft deleting feature.
|
||||
func (m *arModel) Unscoped() *arModel {
|
||||
return &arModel{m.M.Unscoped()}
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ type SelectPageReq struct {
|
||||
}
|
||||
|
||||
//保存参数
|
||||
func AddSave(req *AddReq, userId int) (id int64, err error) {
|
||||
func AddSave(req *AddReq, userId uint64) (id int64, err error) {
|
||||
var entity Entity
|
||||
entity.ConfigName = req.ConfigName
|
||||
entity.ConfigKey = req.ConfigKey
|
||||
@@ -62,7 +62,7 @@ func AddSave(req *AddReq, userId int) (id int64, err error) {
|
||||
}
|
||||
|
||||
//修改保存
|
||||
func EditSave(req *EditReq, userId int) (int64, error) {
|
||||
func EditSave(req *EditReq, userId uint64) (int64, error) {
|
||||
entity, err := GetParamsById(gconv.Int(req.ConfigId))
|
||||
if err != nil {
|
||||
return 0, err
|
||||
|
||||
@@ -13,7 +13,7 @@ import (
|
||||
type Entity struct {
|
||||
ConfigId uint `orm:"config_id,primary" json:"config_id"` // 参数主键
|
||||
ConfigName string `orm:"config_name" json:"config_name"` // 参数名称
|
||||
ConfigKey string `orm:"config_key" json:"config_key"` // 参数键名
|
||||
ConfigKey string `orm:"config_key,unique" json:"config_key"` // 参数键名
|
||||
ConfigValue string `orm:"config_value" json:"config_value"` // 参数键值
|
||||
ConfigType int `orm:"config_type" json:"config_type"` // 系统内置(Y是 N否)
|
||||
CreateBy uint `orm:"create_by" json:"create_by"` // 创建者
|
||||
@@ -34,6 +34,11 @@ func (r *Entity) Insert() (result sql.Result, err error) {
|
||||
return Model.Data(r).Insert()
|
||||
}
|
||||
|
||||
// InsertIgnore does "INSERT IGNORE INTO ..." statement for inserting current object into table.
|
||||
func (r *Entity) InsertIgnore() (result sql.Result, err error) {
|
||||
return Model.Data(r).InsertIgnore()
|
||||
}
|
||||
|
||||
// Replace does "REPLACE...INTO..." statement for inserting current object into table.
|
||||
// If there's already another same record in the table (it checks using primary key or unique index),
|
||||
// it deletes it and insert this one.
|
||||
|
||||
@@ -8,12 +8,13 @@ import (
|
||||
"database/sql"
|
||||
"github.com/gogf/gf/database/gdb"
|
||||
"github.com/gogf/gf/frame/g"
|
||||
"github.com/gogf/gf/frame/gmvc"
|
||||
"time"
|
||||
)
|
||||
|
||||
// arModel is a active record design model for table sys_config operations.
|
||||
type arModel struct {
|
||||
M *gdb.Model
|
||||
gmvc.M
|
||||
}
|
||||
|
||||
var (
|
||||
@@ -21,6 +22,30 @@ var (
|
||||
Table = "sys_config"
|
||||
// Model is the model object of sys_config.
|
||||
Model = &arModel{g.DB("default").Table(Table).Safe()}
|
||||
// Columns defines and stores column names for table sys_config.
|
||||
Columns = struct {
|
||||
ConfigId string // 参数主键
|
||||
ConfigName string // 参数名称
|
||||
ConfigKey string // 参数键名
|
||||
ConfigValue string // 参数键值
|
||||
ConfigType string // 系统内置(Y是 N否)
|
||||
CreateBy string // 创建者
|
||||
CreateTime string // 创建时间
|
||||
UpdateBy string // 更新者
|
||||
UpdateTime string // 更新时间
|
||||
Remark string // 备注
|
||||
}{
|
||||
ConfigId: "config_id",
|
||||
ConfigName: "config_name",
|
||||
ConfigKey: "config_key",
|
||||
ConfigValue: "config_value",
|
||||
ConfigType: "config_type",
|
||||
CreateBy: "create_by",
|
||||
CreateTime: "create_time",
|
||||
UpdateBy: "update_by",
|
||||
UpdateTime: "update_time",
|
||||
Remark: "remark",
|
||||
}
|
||||
)
|
||||
|
||||
// FindOne is a convenience method for Model.FindOne.
|
||||
@@ -41,6 +66,12 @@ func FindValue(fieldsAndWhere ...interface{}) (gdb.Value, error) {
|
||||
return Model.FindValue(fieldsAndWhere...)
|
||||
}
|
||||
|
||||
// FindArray is a convenience method for Model.FindArray.
|
||||
// See Model.FindArray.
|
||||
func FindArray(fieldsAndWhere ...interface{}) ([]gdb.Value, error) {
|
||||
return Model.FindArray(fieldsAndWhere...)
|
||||
}
|
||||
|
||||
// FindCount is a convenience method for Model.FindCount.
|
||||
// See Model.FindCount.
|
||||
func FindCount(where ...interface{}) (int, error) {
|
||||
@@ -52,6 +83,11 @@ func Insert(data ...interface{}) (result sql.Result, err error) {
|
||||
return Model.Insert(data...)
|
||||
}
|
||||
|
||||
// InsertIgnore is a convenience method for Model.InsertIgnore.
|
||||
func InsertIgnore(data ...interface{}) (result sql.Result, err error) {
|
||||
return Model.InsertIgnore(data...)
|
||||
}
|
||||
|
||||
// Replace is a convenience method for Model.Replace.
|
||||
func Replace(data ...interface{}) (result sql.Result, err error) {
|
||||
return Model.Replace(data...)
|
||||
@@ -94,18 +130,30 @@ func (m *arModel) Slave() *arModel {
|
||||
}
|
||||
|
||||
// LeftJoin does "LEFT JOIN ... ON ..." statement on the model.
|
||||
func (m *arModel) LeftJoin(joinTable string, on string) *arModel {
|
||||
return &arModel{m.M.LeftJoin(joinTable, on)}
|
||||
// The parameter <table> can be joined table and its joined condition,
|
||||
// and also with its alias name, like:
|
||||
// Table("user").LeftJoin("user_detail", "user_detail.uid=user.uid")
|
||||
// Table("user", "u").LeftJoin("user_detail", "ud", "ud.uid=u.uid")
|
||||
func (m *arModel) LeftJoin(table ...string) *arModel {
|
||||
return &arModel{m.M.LeftJoin(table...)}
|
||||
}
|
||||
|
||||
// RightJoin does "RIGHT JOIN ... ON ..." statement on the model.
|
||||
func (m *arModel) RightJoin(joinTable string, on string) *arModel {
|
||||
return &arModel{m.M.RightJoin(joinTable, on)}
|
||||
// The parameter <table> can be joined table and its joined condition,
|
||||
// and also with its alias name, like:
|
||||
// Table("user").RightJoin("user_detail", "user_detail.uid=user.uid")
|
||||
// Table("user", "u").RightJoin("user_detail", "ud", "ud.uid=u.uid")
|
||||
func (m *arModel) RightJoin(table ...string) *arModel {
|
||||
return &arModel{m.M.RightJoin(table...)}
|
||||
}
|
||||
|
||||
// InnerJoin does "INNER JOIN ... ON ..." statement on the model.
|
||||
func (m *arModel) InnerJoin(joinTable string, on string) *arModel {
|
||||
return &arModel{m.M.InnerJoin(joinTable, on)}
|
||||
// The parameter <table> can be joined table and its joined condition,
|
||||
// and also with its alias name, like:
|
||||
// Table("user").InnerJoin("user_detail", "user_detail.uid=user.uid")
|
||||
// Table("user", "u").InnerJoin("user_detail", "ud", "ud.uid=u.uid")
|
||||
func (m *arModel) InnerJoin(table ...string) *arModel {
|
||||
return &arModel{m.M.InnerJoin(table...)}
|
||||
}
|
||||
|
||||
// Fields sets the operation fields of the model, multiple fields joined using char ','.
|
||||
@@ -165,8 +213,8 @@ func (m *arModel) Group(groupBy string) *arModel {
|
||||
}
|
||||
|
||||
// Order sets the "ORDER BY" statement for the model.
|
||||
func (m *arModel) Order(orderBy string) *arModel {
|
||||
return &arModel{m.M.Order(orderBy)}
|
||||
func (m *arModel) Order(orderBy ...string) *arModel {
|
||||
return &arModel{m.M.Order(orderBy...)}
|
||||
}
|
||||
|
||||
// Limit sets the "LIMIT" statement for the model.
|
||||
@@ -207,8 +255,8 @@ func (m *arModel) Batch(batch int) *arModel {
|
||||
// control the cache like changing the <duration> or clearing the cache with specified <name>.
|
||||
//
|
||||
// Note that, the cache feature is disabled if the model is operating on a transaction.
|
||||
func (m *arModel) Cache(expire time.Duration, name ...string) *arModel {
|
||||
return &arModel{m.M.Cache(expire, name...)}
|
||||
func (m *arModel) Cache(duration time.Duration, name ...string) *arModel {
|
||||
return &arModel{m.M.Cache(duration, name...)}
|
||||
}
|
||||
|
||||
// Data sets the operation data for the model.
|
||||
@@ -222,53 +270,6 @@ func (m *arModel) Data(data ...interface{}) *arModel {
|
||||
return &arModel{m.M.Data(data...)}
|
||||
}
|
||||
|
||||
// Insert does "INSERT INTO ..." statement for the model.
|
||||
// The optional parameter <data> is the same as the parameter of Model.Data function,
|
||||
// see Model.Data.
|
||||
func (m *arModel) Insert(data ...interface{}) (result sql.Result, err error) {
|
||||
return m.M.Insert(data...)
|
||||
}
|
||||
|
||||
// Replace does "REPLACE INTO ..." statement for the model.
|
||||
// The optional parameter <data> is the same as the parameter of Model.Data function,
|
||||
// see Model.Data.
|
||||
func (m *arModel) Replace(data ...interface{}) (result sql.Result, err error) {
|
||||
return m.M.Replace(data...)
|
||||
}
|
||||
|
||||
// Save does "INSERT INTO ... ON DUPLICATE KEY UPDATE..." statement for the model.
|
||||
// It updates the record if there's primary or unique index in the saving data,
|
||||
// or else it inserts a new record into the table.
|
||||
//
|
||||
// The optional parameter <data> is the same as the parameter of Model.Data function,
|
||||
// see Model.Data.
|
||||
func (m *arModel) Save(data ...interface{}) (result sql.Result, err error) {
|
||||
return m.M.Save(data...)
|
||||
}
|
||||
|
||||
// Update does "UPDATE ... " statement for the model.
|
||||
//
|
||||
// If the optional parameter <dataAndWhere> is given, the dataAndWhere[0] is the updated
|
||||
// data field, and dataAndWhere[1:] is treated as where condition fields.
|
||||
// Also see Model.Data and Model.Where functions.
|
||||
func (m *arModel) Update(dataAndWhere ...interface{}) (result sql.Result, err error) {
|
||||
return m.M.Update(dataAndWhere...)
|
||||
}
|
||||
|
||||
// Delete does "DELETE FROM ... " statement for the model.
|
||||
// The optional parameter <where> is the same as the parameter of Model.Where function,
|
||||
// see Model.Where.
|
||||
func (m *arModel) Delete(where ...interface{}) (result sql.Result, err error) {
|
||||
return m.M.Delete(where...)
|
||||
}
|
||||
|
||||
// Count does "SELECT COUNT(x) FROM ..." statement for the model.
|
||||
// The optional parameter <where> is the same as the parameter of Model.Where function,
|
||||
// see Model.Where.
|
||||
func (m *arModel) Count(where ...interface{}) (int, error) {
|
||||
return m.M.Count(where...)
|
||||
}
|
||||
|
||||
// All does "SELECT FROM ..." statement for the model.
|
||||
// It retrieves the records from table and returns the result as []*Entity.
|
||||
// It returns nil if there's no record retrieved with the given conditions from table.
|
||||
@@ -304,16 +305,6 @@ func (m *arModel) One(where ...interface{}) (*Entity, error) {
|
||||
return entity, nil
|
||||
}
|
||||
|
||||
// Value retrieves a specified record value from table and returns the result as interface type.
|
||||
// It returns nil if there's no record found with the given conditions from table.
|
||||
//
|
||||
// If the optional parameter <fieldsAndWhere> is given, the fieldsAndWhere[0] is the selected fields
|
||||
// and fieldsAndWhere[1:] is treated as where condition fields.
|
||||
// Also see Model.Fields and Model.Where functions.
|
||||
func (m *arModel) Value(fieldsAndWhere ...interface{}) (gdb.Value, error) {
|
||||
return m.M.Value(fieldsAndWhere...)
|
||||
}
|
||||
|
||||
// FindOne retrieves and returns a single Record by Model.WherePri and Model.One.
|
||||
// Also see Model.WherePri and Model.One.
|
||||
func (m *arModel) FindOne(where ...interface{}) (*Entity, error) {
|
||||
@@ -342,18 +333,6 @@ func (m *arModel) FindAll(where ...interface{}) ([]*Entity, error) {
|
||||
return entities, nil
|
||||
}
|
||||
|
||||
// FindValue retrieves and returns single field value by Model.WherePri and Model.Value.
|
||||
// Also see Model.WherePri and Model.Value.
|
||||
func (m *arModel) FindValue(fieldsAndWhere ...interface{}) (gdb.Value, error) {
|
||||
return m.M.FindValue(fieldsAndWhere...)
|
||||
}
|
||||
|
||||
// FindCount retrieves and returns the record number by Model.WherePri and Model.Count.
|
||||
// Also see Model.WherePri and Model.Count.
|
||||
func (m *arModel) FindCount(where ...interface{}) (int, error) {
|
||||
return m.M.FindCount(where...)
|
||||
}
|
||||
|
||||
// Chunk iterates the table with given size and callback function.
|
||||
func (m *arModel) Chunk(limit int, callback func(entities []*Entity, err error) bool) {
|
||||
m.M.Chunk(limit, func(result gdb.Result, err error) bool {
|
||||
@@ -365,3 +344,18 @@ func (m *arModel) Chunk(limit int, callback func(entities []*Entity, err error)
|
||||
return callback(entities, err)
|
||||
})
|
||||
}
|
||||
|
||||
// LockUpdate sets the lock for update for current operation.
|
||||
func (m *arModel) LockUpdate() *arModel {
|
||||
return &arModel{m.M.LockUpdate()}
|
||||
}
|
||||
|
||||
// LockShared sets the lock in share mode for current operation.
|
||||
func (m *arModel) LockShared() *arModel {
|
||||
return &arModel{m.M.LockShared()}
|
||||
}
|
||||
|
||||
// Unscoped enables/disables the soft deleting feature.
|
||||
func (m *arModel) Unscoped() *arModel {
|
||||
return &arModel{m.M.Unscoped()}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ type Dept struct {
|
||||
Remark string `json:"remark"`
|
||||
DataScope interface{} `json:"dataScope"`
|
||||
Params map[string]interface{} `json:"params"`
|
||||
DeptID int64 `json:"deptId" orm:"dept_id"`
|
||||
DeptID uint64 `json:"deptId" orm:"dept_id"`
|
||||
ParentID int64 `json:"parentId" orm:"parent_id"`
|
||||
Ancestors string `json:"ancestors" orm:"ancestors"`
|
||||
DeptName string `json:"deptName" orm:"dept_name"`
|
||||
@@ -120,7 +120,7 @@ func DelDept(id int64) error {
|
||||
}
|
||||
|
||||
//根据部门id获取部门信息
|
||||
func GetDeptById(id int64) (*Dept, error) {
|
||||
func GetDeptById(id uint64) (*Dept, error) {
|
||||
|
||||
dept := (*Dept)(nil)
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ type SelectDataPageReq struct {
|
||||
}
|
||||
|
||||
//添加字典数据操作
|
||||
func AddSaveData(req *AddDataReq, userId int) (int64, error) {
|
||||
func AddSaveData(req *AddDataReq, userId uint64) (int64, error) {
|
||||
var entity Entity
|
||||
entity.DictType = req.DictType
|
||||
entity.Status = req.Status
|
||||
@@ -80,7 +80,7 @@ func GetById(dictCode int) (*Entity, error) {
|
||||
}
|
||||
|
||||
//修改字典数据操作
|
||||
func EditSaveData(req *EditDataReq, userId int) (int64, error) {
|
||||
func EditSaveData(req *EditDataReq, userId uint64) (int64, error) {
|
||||
entity, err := GetById(req.DictCode)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
|
||||
@@ -20,9 +20,9 @@ type Entity struct {
|
||||
ListClass string `orm:"list_class" json:"list_class"` // 表格回显样式
|
||||
IsDefault int `orm:"is_default" json:"is_default"` // 是否默认(1是 0否)
|
||||
Status int `orm:"status" json:"status"` // 状态(0正常 1停用)
|
||||
CreateBy int `orm:"create_by" json:"create_by"` // 创建者
|
||||
CreateBy uint64 `orm:"create_by" json:"create_by"` // 创建者
|
||||
CreateTime uint64 `orm:"create_time" json:"create_time"` // 创建时间
|
||||
UpdateBy int `orm:"update_by" json:"update_by"` // 更新者
|
||||
UpdateBy uint64 `orm:"update_by" json:"update_by"` // 更新者
|
||||
UpdateTime uint64 `orm:"update_time" json:"update_time"` // 更新时间
|
||||
Remark string `orm:"remark" json:"remark"` // 备注
|
||||
}
|
||||
@@ -38,6 +38,11 @@ func (r *Entity) Insert() (result sql.Result, err error) {
|
||||
return Model.Data(r).Insert()
|
||||
}
|
||||
|
||||
// InsertIgnore does "INSERT IGNORE INTO ..." statement for inserting current object into table.
|
||||
func (r *Entity) InsertIgnore() (result sql.Result, err error) {
|
||||
return Model.Data(r).InsertIgnore()
|
||||
}
|
||||
|
||||
// Replace does "REPLACE...INTO..." statement for inserting current object into table.
|
||||
// If there's already another same record in the table (it checks using primary key or unique index),
|
||||
// it deletes it and insert this one.
|
||||
|
||||
@@ -8,12 +8,13 @@ import (
|
||||
"database/sql"
|
||||
"github.com/gogf/gf/database/gdb"
|
||||
"github.com/gogf/gf/frame/g"
|
||||
"github.com/gogf/gf/frame/gmvc"
|
||||
"time"
|
||||
)
|
||||
|
||||
// arModel is a active record design model for table sys_dict_data operations.
|
||||
type arModel struct {
|
||||
M *gdb.Model
|
||||
gmvc.M
|
||||
}
|
||||
|
||||
var (
|
||||
@@ -21,6 +22,38 @@ var (
|
||||
Table = "sys_dict_data"
|
||||
// Model is the model object of sys_dict_data.
|
||||
Model = &arModel{g.DB("default").Table(Table).Safe()}
|
||||
// Columns defines and stores column names for table sys_dict_data.
|
||||
Columns = struct {
|
||||
DictCode string // 字典编码
|
||||
DictSort string // 字典排序
|
||||
DictLabel string // 字典标签
|
||||
DictValue string // 字典键值
|
||||
DictType string // 字典类型
|
||||
CssClass string // 样式属性(其他样式扩展)
|
||||
ListClass string // 表格回显样式
|
||||
IsDefault string // 是否默认(1是 0否)
|
||||
Status string // 状态(0正常 1停用)
|
||||
CreateBy string // 创建者
|
||||
CreateTime string // 创建时间
|
||||
UpdateBy string // 更新者
|
||||
UpdateTime string // 更新时间
|
||||
Remark string // 备注
|
||||
}{
|
||||
DictCode: "dict_code",
|
||||
DictSort: "dict_sort",
|
||||
DictLabel: "dict_label",
|
||||
DictValue: "dict_value",
|
||||
DictType: "dict_type",
|
||||
CssClass: "css_class",
|
||||
ListClass: "list_class",
|
||||
IsDefault: "is_default",
|
||||
Status: "status",
|
||||
CreateBy: "create_by",
|
||||
CreateTime: "create_time",
|
||||
UpdateBy: "update_by",
|
||||
UpdateTime: "update_time",
|
||||
Remark: "remark",
|
||||
}
|
||||
)
|
||||
|
||||
// FindOne is a convenience method for Model.FindOne.
|
||||
@@ -41,6 +74,12 @@ func FindValue(fieldsAndWhere ...interface{}) (gdb.Value, error) {
|
||||
return Model.FindValue(fieldsAndWhere...)
|
||||
}
|
||||
|
||||
// FindArray is a convenience method for Model.FindArray.
|
||||
// See Model.FindArray.
|
||||
func FindArray(fieldsAndWhere ...interface{}) ([]gdb.Value, error) {
|
||||
return Model.FindArray(fieldsAndWhere...)
|
||||
}
|
||||
|
||||
// FindCount is a convenience method for Model.FindCount.
|
||||
// See Model.FindCount.
|
||||
func FindCount(where ...interface{}) (int, error) {
|
||||
@@ -52,6 +91,11 @@ func Insert(data ...interface{}) (result sql.Result, err error) {
|
||||
return Model.Insert(data...)
|
||||
}
|
||||
|
||||
// InsertIgnore is a convenience method for Model.InsertIgnore.
|
||||
func InsertIgnore(data ...interface{}) (result sql.Result, err error) {
|
||||
return Model.InsertIgnore(data...)
|
||||
}
|
||||
|
||||
// Replace is a convenience method for Model.Replace.
|
||||
func Replace(data ...interface{}) (result sql.Result, err error) {
|
||||
return Model.Replace(data...)
|
||||
@@ -94,18 +138,30 @@ func (m *arModel) Slave() *arModel {
|
||||
}
|
||||
|
||||
// LeftJoin does "LEFT JOIN ... ON ..." statement on the model.
|
||||
func (m *arModel) LeftJoin(joinTable string, on string) *arModel {
|
||||
return &arModel{m.M.LeftJoin(joinTable, on)}
|
||||
// The parameter <table> can be joined table and its joined condition,
|
||||
// and also with its alias name, like:
|
||||
// Table("user").LeftJoin("user_detail", "user_detail.uid=user.uid")
|
||||
// Table("user", "u").LeftJoin("user_detail", "ud", "ud.uid=u.uid")
|
||||
func (m *arModel) LeftJoin(table ...string) *arModel {
|
||||
return &arModel{m.M.LeftJoin(table...)}
|
||||
}
|
||||
|
||||
// RightJoin does "RIGHT JOIN ... ON ..." statement on the model.
|
||||
func (m *arModel) RightJoin(joinTable string, on string) *arModel {
|
||||
return &arModel{m.M.RightJoin(joinTable, on)}
|
||||
// The parameter <table> can be joined table and its joined condition,
|
||||
// and also with its alias name, like:
|
||||
// Table("user").RightJoin("user_detail", "user_detail.uid=user.uid")
|
||||
// Table("user", "u").RightJoin("user_detail", "ud", "ud.uid=u.uid")
|
||||
func (m *arModel) RightJoin(table ...string) *arModel {
|
||||
return &arModel{m.M.RightJoin(table...)}
|
||||
}
|
||||
|
||||
// InnerJoin does "INNER JOIN ... ON ..." statement on the model.
|
||||
func (m *arModel) InnerJoin(joinTable string, on string) *arModel {
|
||||
return &arModel{m.M.InnerJoin(joinTable, on)}
|
||||
// The parameter <table> can be joined table and its joined condition,
|
||||
// and also with its alias name, like:
|
||||
// Table("user").InnerJoin("user_detail", "user_detail.uid=user.uid")
|
||||
// Table("user", "u").InnerJoin("user_detail", "ud", "ud.uid=u.uid")
|
||||
func (m *arModel) InnerJoin(table ...string) *arModel {
|
||||
return &arModel{m.M.InnerJoin(table...)}
|
||||
}
|
||||
|
||||
// Fields sets the operation fields of the model, multiple fields joined using char ','.
|
||||
@@ -165,8 +221,8 @@ func (m *arModel) Group(groupBy string) *arModel {
|
||||
}
|
||||
|
||||
// Order sets the "ORDER BY" statement for the model.
|
||||
func (m *arModel) Order(orderBy string) *arModel {
|
||||
return &arModel{m.M.Order(orderBy)}
|
||||
func (m *arModel) Order(orderBy ...string) *arModel {
|
||||
return &arModel{m.M.Order(orderBy...)}
|
||||
}
|
||||
|
||||
// Limit sets the "LIMIT" statement for the model.
|
||||
@@ -207,8 +263,8 @@ func (m *arModel) Batch(batch int) *arModel {
|
||||
// control the cache like changing the <duration> or clearing the cache with specified <name>.
|
||||
//
|
||||
// Note that, the cache feature is disabled if the model is operating on a transaction.
|
||||
func (m *arModel) Cache(expire time.Duration, name ...string) *arModel {
|
||||
return &arModel{m.M.Cache(expire, name...)}
|
||||
func (m *arModel) Cache(duration time.Duration, name ...string) *arModel {
|
||||
return &arModel{m.M.Cache(duration, name...)}
|
||||
}
|
||||
|
||||
// Data sets the operation data for the model.
|
||||
@@ -222,53 +278,6 @@ func (m *arModel) Data(data ...interface{}) *arModel {
|
||||
return &arModel{m.M.Data(data...)}
|
||||
}
|
||||
|
||||
// Insert does "INSERT INTO ..." statement for the model.
|
||||
// The optional parameter <data> is the same as the parameter of Model.Data function,
|
||||
// see Model.Data.
|
||||
func (m *arModel) Insert(data ...interface{}) (result sql.Result, err error) {
|
||||
return m.M.Insert(data...)
|
||||
}
|
||||
|
||||
// Replace does "REPLACE INTO ..." statement for the model.
|
||||
// The optional parameter <data> is the same as the parameter of Model.Data function,
|
||||
// see Model.Data.
|
||||
func (m *arModel) Replace(data ...interface{}) (result sql.Result, err error) {
|
||||
return m.M.Replace(data...)
|
||||
}
|
||||
|
||||
// Save does "INSERT INTO ... ON DUPLICATE KEY UPDATE..." statement for the model.
|
||||
// It updates the record if there's primary or unique index in the saving data,
|
||||
// or else it inserts a new record into the table.
|
||||
//
|
||||
// The optional parameter <data> is the same as the parameter of Model.Data function,
|
||||
// see Model.Data.
|
||||
func (m *arModel) Save(data ...interface{}) (result sql.Result, err error) {
|
||||
return m.M.Save(data...)
|
||||
}
|
||||
|
||||
// Update does "UPDATE ... " statement for the model.
|
||||
//
|
||||
// If the optional parameter <dataAndWhere> is given, the dataAndWhere[0] is the updated
|
||||
// data field, and dataAndWhere[1:] is treated as where condition fields.
|
||||
// Also see Model.Data and Model.Where functions.
|
||||
func (m *arModel) Update(dataAndWhere ...interface{}) (result sql.Result, err error) {
|
||||
return m.M.Update(dataAndWhere...)
|
||||
}
|
||||
|
||||
// Delete does "DELETE FROM ... " statement for the model.
|
||||
// The optional parameter <where> is the same as the parameter of Model.Where function,
|
||||
// see Model.Where.
|
||||
func (m *arModel) Delete(where ...interface{}) (result sql.Result, err error) {
|
||||
return m.M.Delete(where...)
|
||||
}
|
||||
|
||||
// Count does "SELECT COUNT(x) FROM ..." statement for the model.
|
||||
// The optional parameter <where> is the same as the parameter of Model.Where function,
|
||||
// see Model.Where.
|
||||
func (m *arModel) Count(where ...interface{}) (int, error) {
|
||||
return m.M.Count(where...)
|
||||
}
|
||||
|
||||
// All does "SELECT FROM ..." statement for the model.
|
||||
// It retrieves the records from table and returns the result as []*Entity.
|
||||
// It returns nil if there's no record retrieved with the given conditions from table.
|
||||
@@ -304,16 +313,6 @@ func (m *arModel) One(where ...interface{}) (*Entity, error) {
|
||||
return entity, nil
|
||||
}
|
||||
|
||||
// Value retrieves a specified record value from table and returns the result as interface type.
|
||||
// It returns nil if there's no record found with the given conditions from table.
|
||||
//
|
||||
// If the optional parameter <fieldsAndWhere> is given, the fieldsAndWhere[0] is the selected fields
|
||||
// and fieldsAndWhere[1:] is treated as where condition fields.
|
||||
// Also see Model.Fields and Model.Where functions.
|
||||
func (m *arModel) Value(fieldsAndWhere ...interface{}) (gdb.Value, error) {
|
||||
return m.M.Value(fieldsAndWhere...)
|
||||
}
|
||||
|
||||
// FindOne retrieves and returns a single Record by Model.WherePri and Model.One.
|
||||
// Also see Model.WherePri and Model.One.
|
||||
func (m *arModel) FindOne(where ...interface{}) (*Entity, error) {
|
||||
@@ -342,18 +341,6 @@ func (m *arModel) FindAll(where ...interface{}) ([]*Entity, error) {
|
||||
return entities, nil
|
||||
}
|
||||
|
||||
// FindValue retrieves and returns single field value by Model.WherePri and Model.Value.
|
||||
// Also see Model.WherePri and Model.Value.
|
||||
func (m *arModel) FindValue(fieldsAndWhere ...interface{}) (gdb.Value, error) {
|
||||
return m.M.FindValue(fieldsAndWhere...)
|
||||
}
|
||||
|
||||
// FindCount retrieves and returns the record number by Model.WherePri and Model.Count.
|
||||
// Also see Model.WherePri and Model.Count.
|
||||
func (m *arModel) FindCount(where ...interface{}) (int, error) {
|
||||
return m.M.FindCount(where...)
|
||||
}
|
||||
|
||||
// Chunk iterates the table with given size and callback function.
|
||||
func (m *arModel) Chunk(limit int, callback func(entities []*Entity, err error) bool) {
|
||||
m.M.Chunk(limit, func(result gdb.Result, err error) bool {
|
||||
@@ -365,3 +352,18 @@ func (m *arModel) Chunk(limit int, callback func(entities []*Entity, err error)
|
||||
return callback(entities, err)
|
||||
})
|
||||
}
|
||||
|
||||
// LockUpdate sets the lock for update for current operation.
|
||||
func (m *arModel) LockUpdate() *arModel {
|
||||
return &arModel{m.M.LockUpdate()}
|
||||
}
|
||||
|
||||
// LockShared sets the lock in share mode for current operation.
|
||||
func (m *arModel) LockShared() *arModel {
|
||||
return &arModel{m.M.LockShared()}
|
||||
}
|
||||
|
||||
// Unscoped enables/disables the soft deleting feature.
|
||||
func (m *arModel) Unscoped() *arModel {
|
||||
return &arModel{m.M.Unscoped()}
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ type SelectPageReq struct {
|
||||
}
|
||||
|
||||
//添加数据
|
||||
func AddSave(req *AddReq, userId int) (int64, error) {
|
||||
func AddSave(req *AddReq, userId uint64) (int64, error) {
|
||||
var entity Entity
|
||||
entity.Status = req.Status
|
||||
entity.DictType = req.DictType
|
||||
@@ -76,7 +76,7 @@ func GetDictById(id int) (dict *Entity, err error) {
|
||||
}
|
||||
|
||||
//修改保存字典类型
|
||||
func EditSave(req *EditReq, userId int) (int64, error) {
|
||||
func EditSave(req *EditReq, userId uint64) (int64, error) {
|
||||
entity, err := GetDictById(gconv.Int(req.DictId))
|
||||
if err != nil || entity == nil {
|
||||
return 0, err
|
||||
|
||||
@@ -33,6 +33,11 @@ func (r *Entity) Insert() (result sql.Result, err error) {
|
||||
return Model.Data(r).Insert()
|
||||
}
|
||||
|
||||
// InsertIgnore does "INSERT IGNORE INTO ..." statement for inserting current object into table.
|
||||
func (r *Entity) InsertIgnore() (result sql.Result, err error) {
|
||||
return Model.Data(r).InsertIgnore()
|
||||
}
|
||||
|
||||
// Replace does "REPLACE...INTO..." statement for inserting current object into table.
|
||||
// If there's already another same record in the table (it checks using primary key or unique index),
|
||||
// it deletes it and insert this one.
|
||||
|
||||
@@ -8,12 +8,13 @@ import (
|
||||
"database/sql"
|
||||
"github.com/gogf/gf/database/gdb"
|
||||
"github.com/gogf/gf/frame/g"
|
||||
"github.com/gogf/gf/frame/gmvc"
|
||||
"time"
|
||||
)
|
||||
|
||||
// arModel is a active record design model for table sys_dict_type operations.
|
||||
type arModel struct {
|
||||
M *gdb.Model
|
||||
gmvc.M
|
||||
}
|
||||
|
||||
var (
|
||||
@@ -21,6 +22,28 @@ var (
|
||||
Table = "sys_dict_type"
|
||||
// Model is the model object of sys_dict_type.
|
||||
Model = &arModel{g.DB("default").Table(Table).Safe()}
|
||||
// Columns defines and stores column names for table sys_dict_type.
|
||||
Columns = struct {
|
||||
DictId string // 字典主键
|
||||
DictName string // 字典名称
|
||||
DictType string // 字典类型
|
||||
Status string // 状态(0正常 1停用)
|
||||
CreateBy string // 创建者
|
||||
CreateTime string // 创建时间
|
||||
UpdateBy string // 更新者
|
||||
UpdateTime string // 更新时间
|
||||
Remark string // 备注
|
||||
}{
|
||||
DictId: "dict_id",
|
||||
DictName: "dict_name",
|
||||
DictType: "dict_type",
|
||||
Status: "status",
|
||||
CreateBy: "create_by",
|
||||
CreateTime: "create_time",
|
||||
UpdateBy: "update_by",
|
||||
UpdateTime: "update_time",
|
||||
Remark: "remark",
|
||||
}
|
||||
)
|
||||
|
||||
// FindOne is a convenience method for Model.FindOne.
|
||||
@@ -41,6 +64,12 @@ func FindValue(fieldsAndWhere ...interface{}) (gdb.Value, error) {
|
||||
return Model.FindValue(fieldsAndWhere...)
|
||||
}
|
||||
|
||||
// FindArray is a convenience method for Model.FindArray.
|
||||
// See Model.FindArray.
|
||||
func FindArray(fieldsAndWhere ...interface{}) ([]gdb.Value, error) {
|
||||
return Model.FindArray(fieldsAndWhere...)
|
||||
}
|
||||
|
||||
// FindCount is a convenience method for Model.FindCount.
|
||||
// See Model.FindCount.
|
||||
func FindCount(where ...interface{}) (int, error) {
|
||||
@@ -52,6 +81,11 @@ func Insert(data ...interface{}) (result sql.Result, err error) {
|
||||
return Model.Insert(data...)
|
||||
}
|
||||
|
||||
// InsertIgnore is a convenience method for Model.InsertIgnore.
|
||||
func InsertIgnore(data ...interface{}) (result sql.Result, err error) {
|
||||
return Model.InsertIgnore(data...)
|
||||
}
|
||||
|
||||
// Replace is a convenience method for Model.Replace.
|
||||
func Replace(data ...interface{}) (result sql.Result, err error) {
|
||||
return Model.Replace(data...)
|
||||
@@ -94,18 +128,30 @@ func (m *arModel) Slave() *arModel {
|
||||
}
|
||||
|
||||
// LeftJoin does "LEFT JOIN ... ON ..." statement on the model.
|
||||
func (m *arModel) LeftJoin(joinTable string, on string) *arModel {
|
||||
return &arModel{m.M.LeftJoin(joinTable, on)}
|
||||
// The parameter <table> can be joined table and its joined condition,
|
||||
// and also with its alias name, like:
|
||||
// Table("user").LeftJoin("user_detail", "user_detail.uid=user.uid")
|
||||
// Table("user", "u").LeftJoin("user_detail", "ud", "ud.uid=u.uid")
|
||||
func (m *arModel) LeftJoin(table ...string) *arModel {
|
||||
return &arModel{m.M.LeftJoin(table...)}
|
||||
}
|
||||
|
||||
// RightJoin does "RIGHT JOIN ... ON ..." statement on the model.
|
||||
func (m *arModel) RightJoin(joinTable string, on string) *arModel {
|
||||
return &arModel{m.M.RightJoin(joinTable, on)}
|
||||
// The parameter <table> can be joined table and its joined condition,
|
||||
// and also with its alias name, like:
|
||||
// Table("user").RightJoin("user_detail", "user_detail.uid=user.uid")
|
||||
// Table("user", "u").RightJoin("user_detail", "ud", "ud.uid=u.uid")
|
||||
func (m *arModel) RightJoin(table ...string) *arModel {
|
||||
return &arModel{m.M.RightJoin(table...)}
|
||||
}
|
||||
|
||||
// InnerJoin does "INNER JOIN ... ON ..." statement on the model.
|
||||
func (m *arModel) InnerJoin(joinTable string, on string) *arModel {
|
||||
return &arModel{m.M.InnerJoin(joinTable, on)}
|
||||
// The parameter <table> can be joined table and its joined condition,
|
||||
// and also with its alias name, like:
|
||||
// Table("user").InnerJoin("user_detail", "user_detail.uid=user.uid")
|
||||
// Table("user", "u").InnerJoin("user_detail", "ud", "ud.uid=u.uid")
|
||||
func (m *arModel) InnerJoin(table ...string) *arModel {
|
||||
return &arModel{m.M.InnerJoin(table...)}
|
||||
}
|
||||
|
||||
// Fields sets the operation fields of the model, multiple fields joined using char ','.
|
||||
@@ -165,8 +211,8 @@ func (m *arModel) Group(groupBy string) *arModel {
|
||||
}
|
||||
|
||||
// Order sets the "ORDER BY" statement for the model.
|
||||
func (m *arModel) Order(orderBy string) *arModel {
|
||||
return &arModel{m.M.Order(orderBy)}
|
||||
func (m *arModel) Order(orderBy ...string) *arModel {
|
||||
return &arModel{m.M.Order(orderBy...)}
|
||||
}
|
||||
|
||||
// Limit sets the "LIMIT" statement for the model.
|
||||
@@ -207,8 +253,8 @@ func (m *arModel) Batch(batch int) *arModel {
|
||||
// control the cache like changing the <duration> or clearing the cache with specified <name>.
|
||||
//
|
||||
// Note that, the cache feature is disabled if the model is operating on a transaction.
|
||||
func (m *arModel) Cache(expire time.Duration, name ...string) *arModel {
|
||||
return &arModel{m.M.Cache(expire, name...)}
|
||||
func (m *arModel) Cache(duration time.Duration, name ...string) *arModel {
|
||||
return &arModel{m.M.Cache(duration, name...)}
|
||||
}
|
||||
|
||||
// Data sets the operation data for the model.
|
||||
@@ -222,53 +268,6 @@ func (m *arModel) Data(data ...interface{}) *arModel {
|
||||
return &arModel{m.M.Data(data...)}
|
||||
}
|
||||
|
||||
// Insert does "INSERT INTO ..." statement for the model.
|
||||
// The optional parameter <data> is the same as the parameter of Model.Data function,
|
||||
// see Model.Data.
|
||||
func (m *arModel) Insert(data ...interface{}) (result sql.Result, err error) {
|
||||
return m.M.Insert(data...)
|
||||
}
|
||||
|
||||
// Replace does "REPLACE INTO ..." statement for the model.
|
||||
// The optional parameter <data> is the same as the parameter of Model.Data function,
|
||||
// see Model.Data.
|
||||
func (m *arModel) Replace(data ...interface{}) (result sql.Result, err error) {
|
||||
return m.M.Replace(data...)
|
||||
}
|
||||
|
||||
// Save does "INSERT INTO ... ON DUPLICATE KEY UPDATE..." statement for the model.
|
||||
// It updates the record if there's primary or unique index in the saving data,
|
||||
// or else it inserts a new record into the table.
|
||||
//
|
||||
// The optional parameter <data> is the same as the parameter of Model.Data function,
|
||||
// see Model.Data.
|
||||
func (m *arModel) Save(data ...interface{}) (result sql.Result, err error) {
|
||||
return m.M.Save(data...)
|
||||
}
|
||||
|
||||
// Update does "UPDATE ... " statement for the model.
|
||||
//
|
||||
// If the optional parameter <dataAndWhere> is given, the dataAndWhere[0] is the updated
|
||||
// data field, and dataAndWhere[1:] is treated as where condition fields.
|
||||
// Also see Model.Data and Model.Where functions.
|
||||
func (m *arModel) Update(dataAndWhere ...interface{}) (result sql.Result, err error) {
|
||||
return m.M.Update(dataAndWhere...)
|
||||
}
|
||||
|
||||
// Delete does "DELETE FROM ... " statement for the model.
|
||||
// The optional parameter <where> is the same as the parameter of Model.Where function,
|
||||
// see Model.Where.
|
||||
func (m *arModel) Delete(where ...interface{}) (result sql.Result, err error) {
|
||||
return m.M.Delete(where...)
|
||||
}
|
||||
|
||||
// Count does "SELECT COUNT(x) FROM ..." statement for the model.
|
||||
// The optional parameter <where> is the same as the parameter of Model.Where function,
|
||||
// see Model.Where.
|
||||
func (m *arModel) Count(where ...interface{}) (int, error) {
|
||||
return m.M.Count(where...)
|
||||
}
|
||||
|
||||
// All does "SELECT FROM ..." statement for the model.
|
||||
// It retrieves the records from table and returns the result as []*Entity.
|
||||
// It returns nil if there's no record retrieved with the given conditions from table.
|
||||
@@ -304,16 +303,6 @@ func (m *arModel) One(where ...interface{}) (*Entity, error) {
|
||||
return entity, nil
|
||||
}
|
||||
|
||||
// Value retrieves a specified record value from table and returns the result as interface type.
|
||||
// It returns nil if there's no record found with the given conditions from table.
|
||||
//
|
||||
// If the optional parameter <fieldsAndWhere> is given, the fieldsAndWhere[0] is the selected fields
|
||||
// and fieldsAndWhere[1:] is treated as where condition fields.
|
||||
// Also see Model.Fields and Model.Where functions.
|
||||
func (m *arModel) Value(fieldsAndWhere ...interface{}) (gdb.Value, error) {
|
||||
return m.M.Value(fieldsAndWhere...)
|
||||
}
|
||||
|
||||
// FindOne retrieves and returns a single Record by Model.WherePri and Model.One.
|
||||
// Also see Model.WherePri and Model.One.
|
||||
func (m *arModel) FindOne(where ...interface{}) (*Entity, error) {
|
||||
@@ -342,18 +331,6 @@ func (m *arModel) FindAll(where ...interface{}) ([]*Entity, error) {
|
||||
return entities, nil
|
||||
}
|
||||
|
||||
// FindValue retrieves and returns single field value by Model.WherePri and Model.Value.
|
||||
// Also see Model.WherePri and Model.Value.
|
||||
func (m *arModel) FindValue(fieldsAndWhere ...interface{}) (gdb.Value, error) {
|
||||
return m.M.FindValue(fieldsAndWhere...)
|
||||
}
|
||||
|
||||
// FindCount retrieves and returns the record number by Model.WherePri and Model.Count.
|
||||
// Also see Model.WherePri and Model.Count.
|
||||
func (m *arModel) FindCount(where ...interface{}) (int, error) {
|
||||
return m.M.FindCount(where...)
|
||||
}
|
||||
|
||||
// Chunk iterates the table with given size and callback function.
|
||||
func (m *arModel) Chunk(limit int, callback func(entities []*Entity, err error) bool) {
|
||||
m.M.Chunk(limit, func(result gdb.Result, err error) bool {
|
||||
@@ -365,3 +342,18 @@ func (m *arModel) Chunk(limit int, callback func(entities []*Entity, err error)
|
||||
return callback(entities, err)
|
||||
})
|
||||
}
|
||||
|
||||
// LockUpdate sets the lock for update for current operation.
|
||||
func (m *arModel) LockUpdate() *arModel {
|
||||
return &arModel{m.M.LockUpdate()}
|
||||
}
|
||||
|
||||
// LockShared sets the lock in share mode for current operation.
|
||||
func (m *arModel) LockShared() *arModel {
|
||||
return &arModel{m.M.LockShared()}
|
||||
}
|
||||
|
||||
// Unscoped enables/disables the soft deleting feature.
|
||||
func (m *arModel) Unscoped() *arModel {
|
||||
return &arModel{m.M.Unscoped()}
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ func GetJobs() (jobs []*Entity, err error) {
|
||||
}
|
||||
|
||||
//添加计划任务
|
||||
func Add(req *ReqAdd, userId int) (id int64, err error) {
|
||||
func Add(req *ReqAdd, userId uint64) (id int64, err error) {
|
||||
entity := new(Entity)
|
||||
entity.JobName = req.JobName
|
||||
entity.JobGroup = req.JobGroup
|
||||
@@ -90,7 +90,7 @@ func GetJobInfoById(id int64) (job *Entity, err error) {
|
||||
}
|
||||
|
||||
//修改计划任务
|
||||
func Edit(req *ReqEdit, userId int) (rows int64, err error) {
|
||||
func Edit(req *ReqEdit, userId uint64) (rows int64, err error) {
|
||||
entity, err := GetJobInfoById(req.JobId)
|
||||
if err != nil {
|
||||
return
|
||||
|
||||
@@ -38,6 +38,11 @@ func (r *Entity) Insert() (result sql.Result, err error) {
|
||||
return Model.Data(r).Insert()
|
||||
}
|
||||
|
||||
// InsertIgnore does "INSERT IGNORE INTO ..." statement for inserting current object into table.
|
||||
func (r *Entity) InsertIgnore() (result sql.Result, err error) {
|
||||
return Model.Data(r).InsertIgnore()
|
||||
}
|
||||
|
||||
// Replace does "REPLACE...INTO..." statement for inserting current object into table.
|
||||
// If there's already another same record in the table (it checks using primary key or unique index),
|
||||
// it deletes it and insert this one.
|
||||
|
||||
@@ -8,12 +8,13 @@ import (
|
||||
"database/sql"
|
||||
"github.com/gogf/gf/database/gdb"
|
||||
"github.com/gogf/gf/frame/g"
|
||||
"github.com/gogf/gf/frame/gmvc"
|
||||
"time"
|
||||
)
|
||||
|
||||
// arModel is a active record design model for table sys_job operations.
|
||||
type arModel struct {
|
||||
M *gdb.Model
|
||||
gmvc.M
|
||||
}
|
||||
|
||||
var (
|
||||
@@ -21,6 +22,38 @@ var (
|
||||
Table = "sys_job"
|
||||
// Model is the model object of sys_job.
|
||||
Model = &arModel{g.DB("default").Table(Table).Safe()}
|
||||
// Columns defines and stores column names for table sys_job.
|
||||
Columns = struct {
|
||||
JobId string // 任务ID
|
||||
JobName string // 任务名称
|
||||
JobParams string // 参数
|
||||
JobGroup string // 任务组名
|
||||
InvokeTarget string // 调用目标字符串
|
||||
CronExpression string // cron执行表达式
|
||||
MisfirePolicy string // 计划执行策略(1多次执行 2执行一次)
|
||||
Concurrent string // 是否并发执行(0允许 1禁止)
|
||||
Status string // 状态(0正常 1暂停)
|
||||
CreateBy string // 创建者
|
||||
CreateTime string // 创建时间
|
||||
UpdateBy string // 更新者
|
||||
UpdateTime string // 更新时间
|
||||
Remark string // 备注信息
|
||||
}{
|
||||
JobId: "job_id",
|
||||
JobName: "job_name",
|
||||
JobParams: "job_params",
|
||||
JobGroup: "job_group",
|
||||
InvokeTarget: "invoke_target",
|
||||
CronExpression: "cron_expression",
|
||||
MisfirePolicy: "misfire_policy",
|
||||
Concurrent: "concurrent",
|
||||
Status: "status",
|
||||
CreateBy: "create_by",
|
||||
CreateTime: "create_time",
|
||||
UpdateBy: "update_by",
|
||||
UpdateTime: "update_time",
|
||||
Remark: "remark",
|
||||
}
|
||||
)
|
||||
|
||||
// FindOne is a convenience method for Model.FindOne.
|
||||
@@ -41,6 +74,12 @@ func FindValue(fieldsAndWhere ...interface{}) (gdb.Value, error) {
|
||||
return Model.FindValue(fieldsAndWhere...)
|
||||
}
|
||||
|
||||
// FindArray is a convenience method for Model.FindArray.
|
||||
// See Model.FindArray.
|
||||
func FindArray(fieldsAndWhere ...interface{}) ([]gdb.Value, error) {
|
||||
return Model.FindArray(fieldsAndWhere...)
|
||||
}
|
||||
|
||||
// FindCount is a convenience method for Model.FindCount.
|
||||
// See Model.FindCount.
|
||||
func FindCount(where ...interface{}) (int, error) {
|
||||
@@ -52,6 +91,11 @@ func Insert(data ...interface{}) (result sql.Result, err error) {
|
||||
return Model.Insert(data...)
|
||||
}
|
||||
|
||||
// InsertIgnore is a convenience method for Model.InsertIgnore.
|
||||
func InsertIgnore(data ...interface{}) (result sql.Result, err error) {
|
||||
return Model.InsertIgnore(data...)
|
||||
}
|
||||
|
||||
// Replace is a convenience method for Model.Replace.
|
||||
func Replace(data ...interface{}) (result sql.Result, err error) {
|
||||
return Model.Replace(data...)
|
||||
@@ -94,18 +138,30 @@ func (m *arModel) Slave() *arModel {
|
||||
}
|
||||
|
||||
// LeftJoin does "LEFT JOIN ... ON ..." statement on the model.
|
||||
func (m *arModel) LeftJoin(joinTable string, on string) *arModel {
|
||||
return &arModel{m.M.LeftJoin(joinTable, on)}
|
||||
// The parameter <table> can be joined table and its joined condition,
|
||||
// and also with its alias name, like:
|
||||
// Table("user").LeftJoin("user_detail", "user_detail.uid=user.uid")
|
||||
// Table("user", "u").LeftJoin("user_detail", "ud", "ud.uid=u.uid")
|
||||
func (m *arModel) LeftJoin(table ...string) *arModel {
|
||||
return &arModel{m.M.LeftJoin(table...)}
|
||||
}
|
||||
|
||||
// RightJoin does "RIGHT JOIN ... ON ..." statement on the model.
|
||||
func (m *arModel) RightJoin(joinTable string, on string) *arModel {
|
||||
return &arModel{m.M.RightJoin(joinTable, on)}
|
||||
// The parameter <table> can be joined table and its joined condition,
|
||||
// and also with its alias name, like:
|
||||
// Table("user").RightJoin("user_detail", "user_detail.uid=user.uid")
|
||||
// Table("user", "u").RightJoin("user_detail", "ud", "ud.uid=u.uid")
|
||||
func (m *arModel) RightJoin(table ...string) *arModel {
|
||||
return &arModel{m.M.RightJoin(table...)}
|
||||
}
|
||||
|
||||
// InnerJoin does "INNER JOIN ... ON ..." statement on the model.
|
||||
func (m *arModel) InnerJoin(joinTable string, on string) *arModel {
|
||||
return &arModel{m.M.InnerJoin(joinTable, on)}
|
||||
// The parameter <table> can be joined table and its joined condition,
|
||||
// and also with its alias name, like:
|
||||
// Table("user").InnerJoin("user_detail", "user_detail.uid=user.uid")
|
||||
// Table("user", "u").InnerJoin("user_detail", "ud", "ud.uid=u.uid")
|
||||
func (m *arModel) InnerJoin(table ...string) *arModel {
|
||||
return &arModel{m.M.InnerJoin(table...)}
|
||||
}
|
||||
|
||||
// Fields sets the operation fields of the model, multiple fields joined using char ','.
|
||||
@@ -165,8 +221,8 @@ func (m *arModel) Group(groupBy string) *arModel {
|
||||
}
|
||||
|
||||
// Order sets the "ORDER BY" statement for the model.
|
||||
func (m *arModel) Order(orderBy string) *arModel {
|
||||
return &arModel{m.M.Order(orderBy)}
|
||||
func (m *arModel) Order(orderBy ...string) *arModel {
|
||||
return &arModel{m.M.Order(orderBy...)}
|
||||
}
|
||||
|
||||
// Limit sets the "LIMIT" statement for the model.
|
||||
@@ -207,8 +263,8 @@ func (m *arModel) Batch(batch int) *arModel {
|
||||
// control the cache like changing the <duration> or clearing the cache with specified <name>.
|
||||
//
|
||||
// Note that, the cache feature is disabled if the model is operating on a transaction.
|
||||
func (m *arModel) Cache(expire time.Duration, name ...string) *arModel {
|
||||
return &arModel{m.M.Cache(expire, name...)}
|
||||
func (m *arModel) Cache(duration time.Duration, name ...string) *arModel {
|
||||
return &arModel{m.M.Cache(duration, name...)}
|
||||
}
|
||||
|
||||
// Data sets the operation data for the model.
|
||||
@@ -222,53 +278,6 @@ func (m *arModel) Data(data ...interface{}) *arModel {
|
||||
return &arModel{m.M.Data(data...)}
|
||||
}
|
||||
|
||||
// Insert does "INSERT INTO ..." statement for the model.
|
||||
// The optional parameter <data> is the same as the parameter of Model.Data function,
|
||||
// see Model.Data.
|
||||
func (m *arModel) Insert(data ...interface{}) (result sql.Result, err error) {
|
||||
return m.M.Insert(data...)
|
||||
}
|
||||
|
||||
// Replace does "REPLACE INTO ..." statement for the model.
|
||||
// The optional parameter <data> is the same as the parameter of Model.Data function,
|
||||
// see Model.Data.
|
||||
func (m *arModel) Replace(data ...interface{}) (result sql.Result, err error) {
|
||||
return m.M.Replace(data...)
|
||||
}
|
||||
|
||||
// Save does "INSERT INTO ... ON DUPLICATE KEY UPDATE..." statement for the model.
|
||||
// It updates the record if there's primary or unique index in the saving data,
|
||||
// or else it inserts a new record into the table.
|
||||
//
|
||||
// The optional parameter <data> is the same as the parameter of Model.Data function,
|
||||
// see Model.Data.
|
||||
func (m *arModel) Save(data ...interface{}) (result sql.Result, err error) {
|
||||
return m.M.Save(data...)
|
||||
}
|
||||
|
||||
// Update does "UPDATE ... " statement for the model.
|
||||
//
|
||||
// If the optional parameter <dataAndWhere> is given, the dataAndWhere[0] is the updated
|
||||
// data field, and dataAndWhere[1:] is treated as where condition fields.
|
||||
// Also see Model.Data and Model.Where functions.
|
||||
func (m *arModel) Update(dataAndWhere ...interface{}) (result sql.Result, err error) {
|
||||
return m.M.Update(dataAndWhere...)
|
||||
}
|
||||
|
||||
// Delete does "DELETE FROM ... " statement for the model.
|
||||
// The optional parameter <where> is the same as the parameter of Model.Where function,
|
||||
// see Model.Where.
|
||||
func (m *arModel) Delete(where ...interface{}) (result sql.Result, err error) {
|
||||
return m.M.Delete(where...)
|
||||
}
|
||||
|
||||
// Count does "SELECT COUNT(x) FROM ..." statement for the model.
|
||||
// The optional parameter <where> is the same as the parameter of Model.Where function,
|
||||
// see Model.Where.
|
||||
func (m *arModel) Count(where ...interface{}) (int, error) {
|
||||
return m.M.Count(where...)
|
||||
}
|
||||
|
||||
// All does "SELECT FROM ..." statement for the model.
|
||||
// It retrieves the records from table and returns the result as []*Entity.
|
||||
// It returns nil if there's no record retrieved with the given conditions from table.
|
||||
@@ -304,16 +313,6 @@ func (m *arModel) One(where ...interface{}) (*Entity, error) {
|
||||
return entity, nil
|
||||
}
|
||||
|
||||
// Value retrieves a specified record value from table and returns the result as interface type.
|
||||
// It returns nil if there's no record found with the given conditions from table.
|
||||
//
|
||||
// If the optional parameter <fieldsAndWhere> is given, the fieldsAndWhere[0] is the selected fields
|
||||
// and fieldsAndWhere[1:] is treated as where condition fields.
|
||||
// Also see Model.Fields and Model.Where functions.
|
||||
func (m *arModel) Value(fieldsAndWhere ...interface{}) (gdb.Value, error) {
|
||||
return m.M.Value(fieldsAndWhere...)
|
||||
}
|
||||
|
||||
// FindOne retrieves and returns a single Record by Model.WherePri and Model.One.
|
||||
// Also see Model.WherePri and Model.One.
|
||||
func (m *arModel) FindOne(where ...interface{}) (*Entity, error) {
|
||||
@@ -342,18 +341,6 @@ func (m *arModel) FindAll(where ...interface{}) ([]*Entity, error) {
|
||||
return entities, nil
|
||||
}
|
||||
|
||||
// FindValue retrieves and returns single field value by Model.WherePri and Model.Value.
|
||||
// Also see Model.WherePri and Model.Value.
|
||||
func (m *arModel) FindValue(fieldsAndWhere ...interface{}) (gdb.Value, error) {
|
||||
return m.M.FindValue(fieldsAndWhere...)
|
||||
}
|
||||
|
||||
// FindCount retrieves and returns the record number by Model.WherePri and Model.Count.
|
||||
// Also see Model.WherePri and Model.Count.
|
||||
func (m *arModel) FindCount(where ...interface{}) (int, error) {
|
||||
return m.M.FindCount(where...)
|
||||
}
|
||||
|
||||
// Chunk iterates the table with given size and callback function.
|
||||
func (m *arModel) Chunk(limit int, callback func(entities []*Entity, err error) bool) {
|
||||
m.M.Chunk(limit, func(result gdb.Result, err error) bool {
|
||||
@@ -365,3 +352,18 @@ func (m *arModel) Chunk(limit int, callback func(entities []*Entity, err error)
|
||||
return callback(entities, err)
|
||||
})
|
||||
}
|
||||
|
||||
// LockUpdate sets the lock for update for current operation.
|
||||
func (m *arModel) LockUpdate() *arModel {
|
||||
return &arModel{m.M.LockUpdate()}
|
||||
}
|
||||
|
||||
// LockShared sets the lock in share mode for current operation.
|
||||
func (m *arModel) LockShared() *arModel {
|
||||
return &arModel{m.M.LockShared()}
|
||||
}
|
||||
|
||||
// Unscoped enables/disables the soft deleting feature.
|
||||
func (m *arModel) Unscoped() *arModel {
|
||||
return &arModel{m.M.Unscoped()}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ type Entity struct {
|
||||
Status int `orm:"status" json:"status"` // 登录状态(0成功 1失败)
|
||||
Msg string `orm:"msg" json:"msg"` // 提示消息
|
||||
LoginTime int64 `orm:"login_time" json:"login_time"` // 访问时间
|
||||
Module string `orm:"module" json:"module"` //登录模块
|
||||
Module string `orm:"module" json:"module"` // 登录模块
|
||||
}
|
||||
|
||||
// OmitEmpty sets OPTION_OMITEMPTY option for the model, which automatically filers
|
||||
@@ -34,6 +34,11 @@ func (r *Entity) Insert() (result sql.Result, err error) {
|
||||
return Model.Data(r).Insert()
|
||||
}
|
||||
|
||||
// InsertIgnore does "INSERT IGNORE INTO ..." statement for inserting current object into table.
|
||||
func (r *Entity) InsertIgnore() (result sql.Result, err error) {
|
||||
return Model.Data(r).InsertIgnore()
|
||||
}
|
||||
|
||||
// Replace does "REPLACE...INTO..." statement for inserting current object into table.
|
||||
// If there's already another same record in the table (it checks using primary key or unique index),
|
||||
// it deletes it and insert this one.
|
||||
|
||||
@@ -8,12 +8,13 @@ import (
|
||||
"database/sql"
|
||||
"github.com/gogf/gf/database/gdb"
|
||||
"github.com/gogf/gf/frame/g"
|
||||
"github.com/gogf/gf/frame/gmvc"
|
||||
"time"
|
||||
)
|
||||
|
||||
// arModel is a active record design model for table sys_login_log operations.
|
||||
type arModel struct {
|
||||
M *gdb.Model
|
||||
gmvc.M
|
||||
}
|
||||
|
||||
var (
|
||||
@@ -21,6 +22,30 @@ var (
|
||||
Table = "sys_login_log"
|
||||
// Model is the model object of sys_login_log.
|
||||
Model = &arModel{g.DB("default").Table(Table).Safe()}
|
||||
// Columns defines and stores column names for table sys_login_log.
|
||||
Columns = struct {
|
||||
InfoId string // 访问ID
|
||||
LoginName string // 登录账号
|
||||
Ipaddr string // 登录IP地址
|
||||
LoginLocation string // 登录地点
|
||||
Browser string // 浏览器类型
|
||||
Os string // 操作系统
|
||||
Status string // 登录状态(0成功 1失败)
|
||||
Msg string // 提示消息
|
||||
LoginTime string // 访问时间
|
||||
Module string // 登录模块
|
||||
}{
|
||||
InfoId: "info_id",
|
||||
LoginName: "login_name",
|
||||
Ipaddr: "ipaddr",
|
||||
LoginLocation: "login_location",
|
||||
Browser: "browser",
|
||||
Os: "os",
|
||||
Status: "status",
|
||||
Msg: "msg",
|
||||
LoginTime: "login_time",
|
||||
Module: "module",
|
||||
}
|
||||
)
|
||||
|
||||
// FindOne is a convenience method for Model.FindOne.
|
||||
@@ -41,6 +66,12 @@ func FindValue(fieldsAndWhere ...interface{}) (gdb.Value, error) {
|
||||
return Model.FindValue(fieldsAndWhere...)
|
||||
}
|
||||
|
||||
// FindArray is a convenience method for Model.FindArray.
|
||||
// See Model.FindArray.
|
||||
func FindArray(fieldsAndWhere ...interface{}) ([]gdb.Value, error) {
|
||||
return Model.FindArray(fieldsAndWhere...)
|
||||
}
|
||||
|
||||
// FindCount is a convenience method for Model.FindCount.
|
||||
// See Model.FindCount.
|
||||
func FindCount(where ...interface{}) (int, error) {
|
||||
@@ -52,6 +83,11 @@ func Insert(data ...interface{}) (result sql.Result, err error) {
|
||||
return Model.Insert(data...)
|
||||
}
|
||||
|
||||
// InsertIgnore is a convenience method for Model.InsertIgnore.
|
||||
func InsertIgnore(data ...interface{}) (result sql.Result, err error) {
|
||||
return Model.InsertIgnore(data...)
|
||||
}
|
||||
|
||||
// Replace is a convenience method for Model.Replace.
|
||||
func Replace(data ...interface{}) (result sql.Result, err error) {
|
||||
return Model.Replace(data...)
|
||||
@@ -94,18 +130,30 @@ func (m *arModel) Slave() *arModel {
|
||||
}
|
||||
|
||||
// LeftJoin does "LEFT JOIN ... ON ..." statement on the model.
|
||||
func (m *arModel) LeftJoin(joinTable string, on string) *arModel {
|
||||
return &arModel{m.M.LeftJoin(joinTable, on)}
|
||||
// The parameter <table> can be joined table and its joined condition,
|
||||
// and also with its alias name, like:
|
||||
// Table("user").LeftJoin("user_detail", "user_detail.uid=user.uid")
|
||||
// Table("user", "u").LeftJoin("user_detail", "ud", "ud.uid=u.uid")
|
||||
func (m *arModel) LeftJoin(table ...string) *arModel {
|
||||
return &arModel{m.M.LeftJoin(table...)}
|
||||
}
|
||||
|
||||
// RightJoin does "RIGHT JOIN ... ON ..." statement on the model.
|
||||
func (m *arModel) RightJoin(joinTable string, on string) *arModel {
|
||||
return &arModel{m.M.RightJoin(joinTable, on)}
|
||||
// The parameter <table> can be joined table and its joined condition,
|
||||
// and also with its alias name, like:
|
||||
// Table("user").RightJoin("user_detail", "user_detail.uid=user.uid")
|
||||
// Table("user", "u").RightJoin("user_detail", "ud", "ud.uid=u.uid")
|
||||
func (m *arModel) RightJoin(table ...string) *arModel {
|
||||
return &arModel{m.M.RightJoin(table...)}
|
||||
}
|
||||
|
||||
// InnerJoin does "INNER JOIN ... ON ..." statement on the model.
|
||||
func (m *arModel) InnerJoin(joinTable string, on string) *arModel {
|
||||
return &arModel{m.M.InnerJoin(joinTable, on)}
|
||||
// The parameter <table> can be joined table and its joined condition,
|
||||
// and also with its alias name, like:
|
||||
// Table("user").InnerJoin("user_detail", "user_detail.uid=user.uid")
|
||||
// Table("user", "u").InnerJoin("user_detail", "ud", "ud.uid=u.uid")
|
||||
func (m *arModel) InnerJoin(table ...string) *arModel {
|
||||
return &arModel{m.M.InnerJoin(table...)}
|
||||
}
|
||||
|
||||
// Fields sets the operation fields of the model, multiple fields joined using char ','.
|
||||
@@ -165,8 +213,8 @@ func (m *arModel) Group(groupBy string) *arModel {
|
||||
}
|
||||
|
||||
// Order sets the "ORDER BY" statement for the model.
|
||||
func (m *arModel) Order(orderBy string) *arModel {
|
||||
return &arModel{m.M.Order(orderBy)}
|
||||
func (m *arModel) Order(orderBy ...string) *arModel {
|
||||
return &arModel{m.M.Order(orderBy...)}
|
||||
}
|
||||
|
||||
// Limit sets the "LIMIT" statement for the model.
|
||||
@@ -207,8 +255,8 @@ func (m *arModel) Batch(batch int) *arModel {
|
||||
// control the cache like changing the <duration> or clearing the cache with specified <name>.
|
||||
//
|
||||
// Note that, the cache feature is disabled if the model is operating on a transaction.
|
||||
func (m *arModel) Cache(expire time.Duration, name ...string) *arModel {
|
||||
return &arModel{m.M.Cache(expire, name...)}
|
||||
func (m *arModel) Cache(duration time.Duration, name ...string) *arModel {
|
||||
return &arModel{m.M.Cache(duration, name...)}
|
||||
}
|
||||
|
||||
// Data sets the operation data for the model.
|
||||
@@ -222,53 +270,6 @@ func (m *arModel) Data(data ...interface{}) *arModel {
|
||||
return &arModel{m.M.Data(data...)}
|
||||
}
|
||||
|
||||
// Insert does "INSERT INTO ..." statement for the model.
|
||||
// The optional parameter <data> is the same as the parameter of Model.Data function,
|
||||
// see Model.Data.
|
||||
func (m *arModel) Insert(data ...interface{}) (result sql.Result, err error) {
|
||||
return m.M.Insert(data...)
|
||||
}
|
||||
|
||||
// Replace does "REPLACE INTO ..." statement for the model.
|
||||
// The optional parameter <data> is the same as the parameter of Model.Data function,
|
||||
// see Model.Data.
|
||||
func (m *arModel) Replace(data ...interface{}) (result sql.Result, err error) {
|
||||
return m.M.Replace(data...)
|
||||
}
|
||||
|
||||
// Save does "INSERT INTO ... ON DUPLICATE KEY UPDATE..." statement for the model.
|
||||
// It updates the record if there's primary or unique index in the saving data,
|
||||
// or else it inserts a new record into the table.
|
||||
//
|
||||
// The optional parameter <data> is the same as the parameter of Model.Data function,
|
||||
// see Model.Data.
|
||||
func (m *arModel) Save(data ...interface{}) (result sql.Result, err error) {
|
||||
return m.M.Save(data...)
|
||||
}
|
||||
|
||||
// Update does "UPDATE ... " statement for the model.
|
||||
//
|
||||
// If the optional parameter <dataAndWhere> is given, the dataAndWhere[0] is the updated
|
||||
// data field, and dataAndWhere[1:] is treated as where condition fields.
|
||||
// Also see Model.Data and Model.Where functions.
|
||||
func (m *arModel) Update(dataAndWhere ...interface{}) (result sql.Result, err error) {
|
||||
return m.M.Update(dataAndWhere...)
|
||||
}
|
||||
|
||||
// Delete does "DELETE FROM ... " statement for the model.
|
||||
// The optional parameter <where> is the same as the parameter of Model.Where function,
|
||||
// see Model.Where.
|
||||
func (m *arModel) Delete(where ...interface{}) (result sql.Result, err error) {
|
||||
return m.M.Delete(where...)
|
||||
}
|
||||
|
||||
// Count does "SELECT COUNT(x) FROM ..." statement for the model.
|
||||
// The optional parameter <where> is the same as the parameter of Model.Where function,
|
||||
// see Model.Where.
|
||||
func (m *arModel) Count(where ...interface{}) (int, error) {
|
||||
return m.M.Count(where...)
|
||||
}
|
||||
|
||||
// All does "SELECT FROM ..." statement for the model.
|
||||
// It retrieves the records from table and returns the result as []*Entity.
|
||||
// It returns nil if there's no record retrieved with the given conditions from table.
|
||||
@@ -304,16 +305,6 @@ func (m *arModel) One(where ...interface{}) (*Entity, error) {
|
||||
return entity, nil
|
||||
}
|
||||
|
||||
// Value retrieves a specified record value from table and returns the result as interface type.
|
||||
// It returns nil if there's no record found with the given conditions from table.
|
||||
//
|
||||
// If the optional parameter <fieldsAndWhere> is given, the fieldsAndWhere[0] is the selected fields
|
||||
// and fieldsAndWhere[1:] is treated as where condition fields.
|
||||
// Also see Model.Fields and Model.Where functions.
|
||||
func (m *arModel) Value(fieldsAndWhere ...interface{}) (gdb.Value, error) {
|
||||
return m.M.Value(fieldsAndWhere...)
|
||||
}
|
||||
|
||||
// FindOne retrieves and returns a single Record by Model.WherePri and Model.One.
|
||||
// Also see Model.WherePri and Model.One.
|
||||
func (m *arModel) FindOne(where ...interface{}) (*Entity, error) {
|
||||
@@ -342,18 +333,6 @@ func (m *arModel) FindAll(where ...interface{}) ([]*Entity, error) {
|
||||
return entities, nil
|
||||
}
|
||||
|
||||
// FindValue retrieves and returns single field value by Model.WherePri and Model.Value.
|
||||
// Also see Model.WherePri and Model.Value.
|
||||
func (m *arModel) FindValue(fieldsAndWhere ...interface{}) (gdb.Value, error) {
|
||||
return m.M.FindValue(fieldsAndWhere...)
|
||||
}
|
||||
|
||||
// FindCount retrieves and returns the record number by Model.WherePri and Model.Count.
|
||||
// Also see Model.WherePri and Model.Count.
|
||||
func (m *arModel) FindCount(where ...interface{}) (int, error) {
|
||||
return m.M.FindCount(where...)
|
||||
}
|
||||
|
||||
// Chunk iterates the table with given size and callback function.
|
||||
func (m *arModel) Chunk(limit int, callback func(entities []*Entity, err error) bool) {
|
||||
m.M.Chunk(limit, func(result gdb.Result, err error) bool {
|
||||
@@ -365,3 +344,18 @@ func (m *arModel) Chunk(limit int, callback func(entities []*Entity, err error)
|
||||
return callback(entities, err)
|
||||
})
|
||||
}
|
||||
|
||||
// LockUpdate sets the lock for update for current operation.
|
||||
func (m *arModel) LockUpdate() *arModel {
|
||||
return &arModel{m.M.LockUpdate()}
|
||||
}
|
||||
|
||||
// LockShared sets the lock in share mode for current operation.
|
||||
func (m *arModel) LockShared() *arModel {
|
||||
return &arModel{m.M.LockShared()}
|
||||
}
|
||||
|
||||
// Unscoped enables/disables the soft deleting feature.
|
||||
func (m *arModel) Unscoped() *arModel {
|
||||
return &arModel{m.M.Unscoped()}
|
||||
}
|
||||
|
||||
@@ -40,6 +40,11 @@ func (r *Entity) Insert() (result sql.Result, err error) {
|
||||
return Model.Data(r).Insert()
|
||||
}
|
||||
|
||||
// InsertIgnore does "INSERT IGNORE INTO ..." statement for inserting current object into table.
|
||||
func (r *Entity) InsertIgnore() (result sql.Result, err error) {
|
||||
return Model.Data(r).InsertIgnore()
|
||||
}
|
||||
|
||||
// Replace does "REPLACE...INTO..." statement for inserting current object into table.
|
||||
// If there's already another same record in the table (it checks using primary key or unique index),
|
||||
// it deletes it and insert this one.
|
||||
|
||||
@@ -8,12 +8,13 @@ import (
|
||||
"database/sql"
|
||||
"github.com/gogf/gf/database/gdb"
|
||||
"github.com/gogf/gf/frame/g"
|
||||
"github.com/gogf/gf/frame/gmvc"
|
||||
"time"
|
||||
)
|
||||
|
||||
// arModel is a active record design model for table sys_oper_log operations.
|
||||
type arModel struct {
|
||||
M *gdb.Model
|
||||
gmvc.M
|
||||
}
|
||||
|
||||
var (
|
||||
@@ -21,6 +22,42 @@ var (
|
||||
Table = "sys_oper_log"
|
||||
// Model is the model object of sys_oper_log.
|
||||
Model = &arModel{g.DB("default").Table(Table).Safe()}
|
||||
// Columns defines and stores column names for table sys_oper_log.
|
||||
Columns = struct {
|
||||
OperId string // 日志主键
|
||||
Title string // 模块标题
|
||||
BusinessType string // 业务类型(0其它 1新增 2修改 3删除)
|
||||
Method string // 方法名称
|
||||
RequestMethod string // 请求方式
|
||||
OperatorType string // 操作类别(0其它 1后台用户 2手机端用户)
|
||||
OperName string // 操作人员
|
||||
DeptName string // 部门名称
|
||||
OperUrl string // 请求URL
|
||||
OperIp string // 主机地址
|
||||
OperLocation string // 操作地点
|
||||
OperParam string // 请求参数
|
||||
JsonResult string // 返回参数
|
||||
Status string // 操作状态(0正常 1异常)
|
||||
ErrorMsg string // 错误消息
|
||||
OperTime string // 操作时间
|
||||
}{
|
||||
OperId: "oper_id",
|
||||
Title: "title",
|
||||
BusinessType: "business_type",
|
||||
Method: "method",
|
||||
RequestMethod: "request_method",
|
||||
OperatorType: "operator_type",
|
||||
OperName: "oper_name",
|
||||
DeptName: "dept_name",
|
||||
OperUrl: "oper_url",
|
||||
OperIp: "oper_ip",
|
||||
OperLocation: "oper_location",
|
||||
OperParam: "oper_param",
|
||||
JsonResult: "json_result",
|
||||
Status: "status",
|
||||
ErrorMsg: "error_msg",
|
||||
OperTime: "oper_time",
|
||||
}
|
||||
)
|
||||
|
||||
// FindOne is a convenience method for Model.FindOne.
|
||||
@@ -41,6 +78,12 @@ func FindValue(fieldsAndWhere ...interface{}) (gdb.Value, error) {
|
||||
return Model.FindValue(fieldsAndWhere...)
|
||||
}
|
||||
|
||||
// FindArray is a convenience method for Model.FindArray.
|
||||
// See Model.FindArray.
|
||||
func FindArray(fieldsAndWhere ...interface{}) ([]gdb.Value, error) {
|
||||
return Model.FindArray(fieldsAndWhere...)
|
||||
}
|
||||
|
||||
// FindCount is a convenience method for Model.FindCount.
|
||||
// See Model.FindCount.
|
||||
func FindCount(where ...interface{}) (int, error) {
|
||||
@@ -52,6 +95,11 @@ func Insert(data ...interface{}) (result sql.Result, err error) {
|
||||
return Model.Insert(data...)
|
||||
}
|
||||
|
||||
// InsertIgnore is a convenience method for Model.InsertIgnore.
|
||||
func InsertIgnore(data ...interface{}) (result sql.Result, err error) {
|
||||
return Model.InsertIgnore(data...)
|
||||
}
|
||||
|
||||
// Replace is a convenience method for Model.Replace.
|
||||
func Replace(data ...interface{}) (result sql.Result, err error) {
|
||||
return Model.Replace(data...)
|
||||
@@ -94,18 +142,30 @@ func (m *arModel) Slave() *arModel {
|
||||
}
|
||||
|
||||
// LeftJoin does "LEFT JOIN ... ON ..." statement on the model.
|
||||
func (m *arModel) LeftJoin(joinTable string, on string) *arModel {
|
||||
return &arModel{m.M.LeftJoin(joinTable, on)}
|
||||
// The parameter <table> can be joined table and its joined condition,
|
||||
// and also with its alias name, like:
|
||||
// Table("user").LeftJoin("user_detail", "user_detail.uid=user.uid")
|
||||
// Table("user", "u").LeftJoin("user_detail", "ud", "ud.uid=u.uid")
|
||||
func (m *arModel) LeftJoin(table ...string) *arModel {
|
||||
return &arModel{m.M.LeftJoin(table...)}
|
||||
}
|
||||
|
||||
// RightJoin does "RIGHT JOIN ... ON ..." statement on the model.
|
||||
func (m *arModel) RightJoin(joinTable string, on string) *arModel {
|
||||
return &arModel{m.M.RightJoin(joinTable, on)}
|
||||
// The parameter <table> can be joined table and its joined condition,
|
||||
// and also with its alias name, like:
|
||||
// Table("user").RightJoin("user_detail", "user_detail.uid=user.uid")
|
||||
// Table("user", "u").RightJoin("user_detail", "ud", "ud.uid=u.uid")
|
||||
func (m *arModel) RightJoin(table ...string) *arModel {
|
||||
return &arModel{m.M.RightJoin(table...)}
|
||||
}
|
||||
|
||||
// InnerJoin does "INNER JOIN ... ON ..." statement on the model.
|
||||
func (m *arModel) InnerJoin(joinTable string, on string) *arModel {
|
||||
return &arModel{m.M.InnerJoin(joinTable, on)}
|
||||
// The parameter <table> can be joined table and its joined condition,
|
||||
// and also with its alias name, like:
|
||||
// Table("user").InnerJoin("user_detail", "user_detail.uid=user.uid")
|
||||
// Table("user", "u").InnerJoin("user_detail", "ud", "ud.uid=u.uid")
|
||||
func (m *arModel) InnerJoin(table ...string) *arModel {
|
||||
return &arModel{m.M.InnerJoin(table...)}
|
||||
}
|
||||
|
||||
// Fields sets the operation fields of the model, multiple fields joined using char ','.
|
||||
@@ -165,8 +225,8 @@ func (m *arModel) Group(groupBy string) *arModel {
|
||||
}
|
||||
|
||||
// Order sets the "ORDER BY" statement for the model.
|
||||
func (m *arModel) Order(orderBy string) *arModel {
|
||||
return &arModel{m.M.Order(orderBy)}
|
||||
func (m *arModel) Order(orderBy ...string) *arModel {
|
||||
return &arModel{m.M.Order(orderBy...)}
|
||||
}
|
||||
|
||||
// Limit sets the "LIMIT" statement for the model.
|
||||
@@ -207,8 +267,8 @@ func (m *arModel) Batch(batch int) *arModel {
|
||||
// control the cache like changing the <duration> or clearing the cache with specified <name>.
|
||||
//
|
||||
// Note that, the cache feature is disabled if the model is operating on a transaction.
|
||||
func (m *arModel) Cache(expire time.Duration, name ...string) *arModel {
|
||||
return &arModel{m.M.Cache(expire, name...)}
|
||||
func (m *arModel) Cache(duration time.Duration, name ...string) *arModel {
|
||||
return &arModel{m.M.Cache(duration, name...)}
|
||||
}
|
||||
|
||||
// Data sets the operation data for the model.
|
||||
@@ -222,53 +282,6 @@ func (m *arModel) Data(data ...interface{}) *arModel {
|
||||
return &arModel{m.M.Data(data...)}
|
||||
}
|
||||
|
||||
// Insert does "INSERT INTO ..." statement for the model.
|
||||
// The optional parameter <data> is the same as the parameter of Model.Data function,
|
||||
// see Model.Data.
|
||||
func (m *arModel) Insert(data ...interface{}) (result sql.Result, err error) {
|
||||
return m.M.Insert(data...)
|
||||
}
|
||||
|
||||
// Replace does "REPLACE INTO ..." statement for the model.
|
||||
// The optional parameter <data> is the same as the parameter of Model.Data function,
|
||||
// see Model.Data.
|
||||
func (m *arModel) Replace(data ...interface{}) (result sql.Result, err error) {
|
||||
return m.M.Replace(data...)
|
||||
}
|
||||
|
||||
// Save does "INSERT INTO ... ON DUPLICATE KEY UPDATE..." statement for the model.
|
||||
// It updates the record if there's primary or unique index in the saving data,
|
||||
// or else it inserts a new record into the table.
|
||||
//
|
||||
// The optional parameter <data> is the same as the parameter of Model.Data function,
|
||||
// see Model.Data.
|
||||
func (m *arModel) Save(data ...interface{}) (result sql.Result, err error) {
|
||||
return m.M.Save(data...)
|
||||
}
|
||||
|
||||
// Update does "UPDATE ... " statement for the model.
|
||||
//
|
||||
// If the optional parameter <dataAndWhere> is given, the dataAndWhere[0] is the updated
|
||||
// data field, and dataAndWhere[1:] is treated as where condition fields.
|
||||
// Also see Model.Data and Model.Where functions.
|
||||
func (m *arModel) Update(dataAndWhere ...interface{}) (result sql.Result, err error) {
|
||||
return m.M.Update(dataAndWhere...)
|
||||
}
|
||||
|
||||
// Delete does "DELETE FROM ... " statement for the model.
|
||||
// The optional parameter <where> is the same as the parameter of Model.Where function,
|
||||
// see Model.Where.
|
||||
func (m *arModel) Delete(where ...interface{}) (result sql.Result, err error) {
|
||||
return m.M.Delete(where...)
|
||||
}
|
||||
|
||||
// Count does "SELECT COUNT(x) FROM ..." statement for the model.
|
||||
// The optional parameter <where> is the same as the parameter of Model.Where function,
|
||||
// see Model.Where.
|
||||
func (m *arModel) Count(where ...interface{}) (int, error) {
|
||||
return m.M.Count(where...)
|
||||
}
|
||||
|
||||
// All does "SELECT FROM ..." statement for the model.
|
||||
// It retrieves the records from table and returns the result as []*Entity.
|
||||
// It returns nil if there's no record retrieved with the given conditions from table.
|
||||
@@ -304,16 +317,6 @@ func (m *arModel) One(where ...interface{}) (*Entity, error) {
|
||||
return entity, nil
|
||||
}
|
||||
|
||||
// Value retrieves a specified record value from table and returns the result as interface type.
|
||||
// It returns nil if there's no record found with the given conditions from table.
|
||||
//
|
||||
// If the optional parameter <fieldsAndWhere> is given, the fieldsAndWhere[0] is the selected fields
|
||||
// and fieldsAndWhere[1:] is treated as where condition fields.
|
||||
// Also see Model.Fields and Model.Where functions.
|
||||
func (m *arModel) Value(fieldsAndWhere ...interface{}) (gdb.Value, error) {
|
||||
return m.M.Value(fieldsAndWhere...)
|
||||
}
|
||||
|
||||
// FindOne retrieves and returns a single Record by Model.WherePri and Model.One.
|
||||
// Also see Model.WherePri and Model.One.
|
||||
func (m *arModel) FindOne(where ...interface{}) (*Entity, error) {
|
||||
@@ -342,18 +345,6 @@ func (m *arModel) FindAll(where ...interface{}) ([]*Entity, error) {
|
||||
return entities, nil
|
||||
}
|
||||
|
||||
// FindValue retrieves and returns single field value by Model.WherePri and Model.Value.
|
||||
// Also see Model.WherePri and Model.Value.
|
||||
func (m *arModel) FindValue(fieldsAndWhere ...interface{}) (gdb.Value, error) {
|
||||
return m.M.FindValue(fieldsAndWhere...)
|
||||
}
|
||||
|
||||
// FindCount retrieves and returns the record number by Model.WherePri and Model.Count.
|
||||
// Also see Model.WherePri and Model.Count.
|
||||
func (m *arModel) FindCount(where ...interface{}) (int, error) {
|
||||
return m.M.FindCount(where...)
|
||||
}
|
||||
|
||||
// Chunk iterates the table with given size and callback function.
|
||||
func (m *arModel) Chunk(limit int, callback func(entities []*Entity, err error) bool) {
|
||||
m.M.Chunk(limit, func(result gdb.Result, err error) bool {
|
||||
@@ -365,3 +356,18 @@ func (m *arModel) Chunk(limit int, callback func(entities []*Entity, err error)
|
||||
return callback(entities, err)
|
||||
})
|
||||
}
|
||||
|
||||
// LockUpdate sets the lock for update for current operation.
|
||||
func (m *arModel) LockUpdate() *arModel {
|
||||
return &arModel{m.M.LockUpdate()}
|
||||
}
|
||||
|
||||
// LockShared sets the lock in share mode for current operation.
|
||||
func (m *arModel) LockShared() *arModel {
|
||||
return &arModel{m.M.LockShared()}
|
||||
}
|
||||
|
||||
// Unscoped enables/disables the soft deleting feature.
|
||||
func (m *arModel) Unscoped() *arModel {
|
||||
return &arModel{m.M.Unscoped()}
|
||||
}
|
||||
|
||||
@@ -39,13 +39,13 @@ type AddParams struct {
|
||||
PostSort int `p:"postSort" v:"required#岗位排序不能为空"`
|
||||
Status string `p:"status" v:"required#状态不能为空"`
|
||||
Remark string `p:"remark"`
|
||||
AddUser int
|
||||
AddUser uint64
|
||||
}
|
||||
|
||||
type EditParams struct {
|
||||
PostId int64 `p:"postId" v:"required#id必须"`
|
||||
AddParams
|
||||
UpUser int
|
||||
UpUser uint64
|
||||
}
|
||||
|
||||
func List(req *SearchParams) (total, page int, list gdb.Result, err error) {
|
||||
|
||||
@@ -10,8 +10,8 @@ import (
|
||||
|
||||
//设置用户状态参数
|
||||
type StatusReq struct {
|
||||
Id int `p:"userId" v:"required#用户id不能为空"`
|
||||
UserStatus int `p:"status" v:"required#用户状态不能为空"`
|
||||
Id int `p:"userId" v:"required#用户id不能为空"`
|
||||
UserStatus uint `p:"status" v:"required#用户状态不能为空"`
|
||||
}
|
||||
|
||||
//重置用户密码状态参数
|
||||
@@ -35,7 +35,7 @@ type SearchReq struct {
|
||||
|
||||
//添加修改用户公用请求字段
|
||||
type SetUserReq struct {
|
||||
DeptId int64 `p:"deptId" v:"required#用户部门不能为空"` //所属部门
|
||||
DeptId uint64 `p:"deptId" v:"required#用户部门不能为空"` //所属部门
|
||||
Email string `p:"email" v:"email#邮箱格式错误"` //邮箱
|
||||
NickName string `p:"nickName" v:"required#用户昵称不能为空"`
|
||||
Phonenumber string `p:"phonenumber" v:"required|phone#手机号不能为空|手机号格式错误"`
|
||||
@@ -43,7 +43,7 @@ type SetUserReq struct {
|
||||
Remark string `p:"remark"`
|
||||
RoleIds []int64 `p:"roleIds"`
|
||||
Sex int `p:"sex"`
|
||||
Status int `p:"status"`
|
||||
Status uint `p:"status"`
|
||||
IsAdmin int `p:"is_admin"` // 是否后台管理员 1 是 0 否
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ type EditUserReq struct {
|
||||
UserId int `p:"userId" v:"required#用户id不能为空"`
|
||||
}
|
||||
|
||||
func GetUserById(id int) (*Entity, error) {
|
||||
func GetUserById(id uint64) (*Entity, error) {
|
||||
return Model.Where("id", id).One()
|
||||
}
|
||||
|
||||
@@ -160,7 +160,7 @@ func GetAdminList(req *SearchReq) (total, page int, userList []*Entity, err erro
|
||||
req.PageNum = 1
|
||||
}
|
||||
page = req.PageNum
|
||||
userList, err = userModel.ForPage(page, req.PageSize).OrderBy("id asc").All()
|
||||
userList, err = userModel.Page(page, req.PageSize).Order("id asc").All()
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -11,27 +11,24 @@ import (
|
||||
|
||||
// Entity is the golang structure for table user.
|
||||
type Entity struct {
|
||||
Id int `orm:"id,primary" json:"id"` //
|
||||
Id uint64 `orm:"id,primary" json:"id"` //
|
||||
UserName string `orm:"user_name,unique" json:"user_name"` // 用户名
|
||||
Mobile string `orm:"mobile,unique" json:"mobile"` // 中国手机不带国家代码,国际手机号格式为:国家代码-手机号
|
||||
UserNickname string `orm:"user_nickname" json:"user_nickname"` // 用户昵称
|
||||
Birthday int `orm:"birthday" json:"birthday"` // 生日
|
||||
CreateTime int `orm:"create_time" json:"create_time"` // 注册时间
|
||||
UserPassword string `orm:"user_password" json:"user_password"` // 登录密码;cmf_password加密
|
||||
UserStatus int `orm:"user_status" json:"user_status"` // 用户状态;0:禁用,1:正常,2:未验证
|
||||
UserStatus uint `orm:"user_status" json:"user_status"` // 用户状态;0:禁用,1:正常,2:未验证
|
||||
UserEmail string `orm:"user_email" json:"user_email"` // 用户登录邮箱
|
||||
Sex int `orm:"sex" json:"sex"` // 性别;0:保密,1:男,2:女
|
||||
Avatar string `orm:"avatar" json:"avatar"` // 用户头像
|
||||
LastLoginTime int `orm:"last_login_time" json:"last_login_time"` // 最后登录时间
|
||||
LastLoginIp string `orm:"last_login_ip" json:"last_login_ip"` // 最后登录ip
|
||||
DeptId int64 `orm:"dept_id" json:"dept_id"` //所属部门id
|
||||
DeptId uint64 `orm:"dept_id" json:"dept_id"` // 部门id
|
||||
Remark string `orm:"remark" json:"remark"` // 备注
|
||||
IsAdmin int `orm:"is_admin" json:"is_admin"` // 是否后台管理员 1 是 0 否
|
||||
}
|
||||
|
||||
// User is alias of Entity, which some developers say they just want.
|
||||
type User = Entity
|
||||
|
||||
// OmitEmpty sets OPTION_OMITEMPTY option for the model, which automatically filers
|
||||
// the data and where attributes for empty values.
|
||||
func (r *Entity) OmitEmpty() *arModel {
|
||||
@@ -43,6 +40,11 @@ func (r *Entity) Insert() (result sql.Result, err error) {
|
||||
return Model.Data(r).Insert()
|
||||
}
|
||||
|
||||
// InsertIgnore does "INSERT IGNORE INTO ..." statement for inserting current object into table.
|
||||
func (r *Entity) InsertIgnore() (result sql.Result, err error) {
|
||||
return Model.Data(r).InsertIgnore()
|
||||
}
|
||||
|
||||
// Replace does "REPLACE...INTO..." statement for inserting current object into table.
|
||||
// If there's already another same record in the table (it checks using primary key or unique index),
|
||||
// it deletes it and insert this one.
|
||||
|
||||
@@ -8,12 +8,13 @@ import (
|
||||
"database/sql"
|
||||
"github.com/gogf/gf/database/gdb"
|
||||
"github.com/gogf/gf/frame/g"
|
||||
"github.com/gogf/gf/frame/gmvc"
|
||||
"time"
|
||||
)
|
||||
|
||||
// arModel is a active record design model for table user operations.
|
||||
type arModel struct {
|
||||
Model *gdb.Model
|
||||
gmvc.M
|
||||
}
|
||||
|
||||
var (
|
||||
@@ -21,63 +22,176 @@ var (
|
||||
Table = "user"
|
||||
// Model is the model object of user.
|
||||
Model = &arModel{g.DB("default").Table(Table).Safe()}
|
||||
// Columns defines and stores column names for table user.
|
||||
Columns = struct {
|
||||
Id string //
|
||||
UserName string // 用户名
|
||||
Mobile string // 中国手机不带国家代码,国际手机号格式为:国家代码-手机号
|
||||
UserNickname string // 用户昵称
|
||||
Birthday string // 生日
|
||||
CreateTime string // 注册时间
|
||||
UserPassword string // 登录密码;cmf_password加密
|
||||
UserStatus string // 用户状态;0:禁用,1:正常,2:未验证
|
||||
UserEmail string // 用户登录邮箱
|
||||
Sex string // 性别;0:保密,1:男,2:女
|
||||
Avatar string // 用户头像
|
||||
LastLoginTime string // 最后登录时间
|
||||
LastLoginIp string // 最后登录ip
|
||||
DeptId string // 部门id
|
||||
Remark string // 备注
|
||||
IsAdmin string // 是否后台管理员 1 是 0 否
|
||||
}{
|
||||
Id: "id",
|
||||
UserName: "user_name",
|
||||
Mobile: "mobile",
|
||||
UserNickname: "user_nickname",
|
||||
Birthday: "birthday",
|
||||
CreateTime: "create_time",
|
||||
UserPassword: "user_password",
|
||||
UserStatus: "user_status",
|
||||
UserEmail: "user_email",
|
||||
Sex: "sex",
|
||||
Avatar: "avatar",
|
||||
LastLoginTime: "last_login_time",
|
||||
LastLoginIp: "last_login_ip",
|
||||
DeptId: "dept_id",
|
||||
Remark: "remark",
|
||||
IsAdmin: "is_admin",
|
||||
}
|
||||
)
|
||||
|
||||
// FindOne is a convenience method for Model.FindOne.
|
||||
// See Model.FindOne.
|
||||
func FindOne(where ...interface{}) (*Entity, error) {
|
||||
return Model.FindOne(where...)
|
||||
}
|
||||
|
||||
// FindAll is a convenience method for Model.FindAll.
|
||||
// See Model.FindAll.
|
||||
func FindAll(where ...interface{}) ([]*Entity, error) {
|
||||
return Model.FindAll(where...)
|
||||
}
|
||||
|
||||
// FindValue is a convenience method for Model.FindValue.
|
||||
// See Model.FindValue.
|
||||
func FindValue(fieldsAndWhere ...interface{}) (gdb.Value, error) {
|
||||
return Model.FindValue(fieldsAndWhere...)
|
||||
}
|
||||
|
||||
// FindArray is a convenience method for Model.FindArray.
|
||||
// See Model.FindArray.
|
||||
func FindArray(fieldsAndWhere ...interface{}) ([]gdb.Value, error) {
|
||||
return Model.FindArray(fieldsAndWhere...)
|
||||
}
|
||||
|
||||
// FindCount is a convenience method for Model.FindCount.
|
||||
// See Model.FindCount.
|
||||
func FindCount(where ...interface{}) (int, error) {
|
||||
return Model.FindCount(where...)
|
||||
}
|
||||
|
||||
// Insert is a convenience method for Model.Insert.
|
||||
func Insert(data ...interface{}) (result sql.Result, err error) {
|
||||
return Model.Insert(data...)
|
||||
}
|
||||
|
||||
// InsertIgnore is a convenience method for Model.InsertIgnore.
|
||||
func InsertIgnore(data ...interface{}) (result sql.Result, err error) {
|
||||
return Model.InsertIgnore(data...)
|
||||
}
|
||||
|
||||
// Replace is a convenience method for Model.Replace.
|
||||
func Replace(data ...interface{}) (result sql.Result, err error) {
|
||||
return Model.Replace(data...)
|
||||
}
|
||||
|
||||
// Save is a convenience method for Model.Save.
|
||||
func Save(data ...interface{}) (result sql.Result, err error) {
|
||||
return Model.Save(data...)
|
||||
}
|
||||
|
||||
// Update is a convenience method for Model.Update.
|
||||
func Update(dataAndWhere ...interface{}) (result sql.Result, err error) {
|
||||
return Model.Update(dataAndWhere...)
|
||||
}
|
||||
|
||||
// Delete is a convenience method for Model.Delete.
|
||||
func Delete(where ...interface{}) (result sql.Result, err error) {
|
||||
return Model.Delete(where...)
|
||||
}
|
||||
|
||||
// As sets an alias name for current table.
|
||||
func (m *arModel) As(as string) *arModel {
|
||||
return &arModel{m.M.As(as)}
|
||||
}
|
||||
|
||||
// TX sets the transaction for current operation.
|
||||
func (m *arModel) TX(tx *gdb.TX) *arModel {
|
||||
return &arModel{m.Model.TX(tx)}
|
||||
return &arModel{m.M.TX(tx)}
|
||||
}
|
||||
|
||||
// Master marks the following operation on master node.
|
||||
func (m *arModel) Master() *arModel {
|
||||
return &arModel{m.Model.Master()}
|
||||
return &arModel{m.M.Master()}
|
||||
}
|
||||
|
||||
// Slave marks the following operation on slave node.
|
||||
// Note that it makes sense only if there's any slave node configured.
|
||||
func (m *arModel) Slave() *arModel {
|
||||
return &arModel{m.Model.Slave()}
|
||||
return &arModel{m.M.Slave()}
|
||||
}
|
||||
|
||||
// LeftJoin does "LEFT JOIN ... ON ..." statement on the model.
|
||||
func (m *arModel) LeftJoin(joinTable string, on string) *arModel {
|
||||
return &arModel{m.Model.LeftJoin(joinTable, on)}
|
||||
// The parameter <table> can be joined table and its joined condition,
|
||||
// and also with its alias name, like:
|
||||
// Table("user").LeftJoin("user_detail", "user_detail.uid=user.uid")
|
||||
// Table("user", "u").LeftJoin("user_detail", "ud", "ud.uid=u.uid")
|
||||
func (m *arModel) LeftJoin(table ...string) *arModel {
|
||||
return &arModel{m.M.LeftJoin(table...)}
|
||||
}
|
||||
|
||||
// RightJoin does "RIGHT JOIN ... ON ..." statement on the model.
|
||||
func (m *arModel) RightJoin(joinTable string, on string) *arModel {
|
||||
return &arModel{m.Model.RightJoin(joinTable, on)}
|
||||
// The parameter <table> can be joined table and its joined condition,
|
||||
// and also with its alias name, like:
|
||||
// Table("user").RightJoin("user_detail", "user_detail.uid=user.uid")
|
||||
// Table("user", "u").RightJoin("user_detail", "ud", "ud.uid=u.uid")
|
||||
func (m *arModel) RightJoin(table ...string) *arModel {
|
||||
return &arModel{m.M.RightJoin(table...)}
|
||||
}
|
||||
|
||||
// InnerJoin does "INNER JOIN ... ON ..." statement on the model.
|
||||
func (m *arModel) InnerJoin(joinTable string, on string) *arModel {
|
||||
return &arModel{m.Model.InnerJoin(joinTable, on)}
|
||||
// The parameter <table> can be joined table and its joined condition,
|
||||
// and also with its alias name, like:
|
||||
// Table("user").InnerJoin("user_detail", "user_detail.uid=user.uid")
|
||||
// Table("user", "u").InnerJoin("user_detail", "ud", "ud.uid=u.uid")
|
||||
func (m *arModel) InnerJoin(table ...string) *arModel {
|
||||
return &arModel{m.M.InnerJoin(table...)}
|
||||
}
|
||||
|
||||
// Fields sets the operation fields of the model, multiple fields joined using char ','.
|
||||
func (m *arModel) Fields(fields string) *arModel {
|
||||
return &arModel{m.Model.Fields(fields)}
|
||||
return &arModel{m.M.Fields(fields)}
|
||||
}
|
||||
|
||||
// FieldsEx sets the excluded operation fields of the model, multiple fields joined using char ','.
|
||||
func (m *arModel) FieldsEx(fields string) *arModel {
|
||||
return &arModel{m.Model.FieldsEx(fields)}
|
||||
return &arModel{m.M.FieldsEx(fields)}
|
||||
}
|
||||
|
||||
// Option sets the extra operation option for the model.
|
||||
func (m *arModel) Option(option int) *arModel {
|
||||
return &arModel{m.Model.Option(option)}
|
||||
return &arModel{m.M.Option(option)}
|
||||
}
|
||||
|
||||
// OmitEmpty sets OPTION_OMITEMPTY option for the model, which automatically filers
|
||||
// the data and where attributes for empty values.
|
||||
func (m *arModel) OmitEmpty() *arModel {
|
||||
return &arModel{m.Model.OmitEmpty()}
|
||||
return &arModel{m.M.OmitEmpty()}
|
||||
}
|
||||
|
||||
// Filter marks filtering the fields which does not exist in the fields of the operated table.
|
||||
func (m *arModel) Filter() *arModel {
|
||||
return &arModel{m.Model.Filter()}
|
||||
return &arModel{m.M.Filter()}
|
||||
}
|
||||
|
||||
// Where sets the condition statement for the model. The parameter <where> can be type of
|
||||
@@ -92,27 +206,27 @@ func (m *arModel) Filter() *arModel {
|
||||
// Where("age IN(?,?)", 18, 50)
|
||||
// Where(User{ Id : 1, UserName : "john"})
|
||||
func (m *arModel) Where(where interface{}, args ...interface{}) *arModel {
|
||||
return &arModel{m.Model.Where(where, args...)}
|
||||
return &arModel{m.M.Where(where, args...)}
|
||||
}
|
||||
|
||||
// And adds "AND" condition to the where statement.
|
||||
func (m *arModel) And(where interface{}, args ...interface{}) *arModel {
|
||||
return &arModel{m.Model.And(where, args...)}
|
||||
return &arModel{m.M.And(where, args...)}
|
||||
}
|
||||
|
||||
// Or adds "OR" condition to the where statement.
|
||||
func (m *arModel) Or(where interface{}, args ...interface{}) *arModel {
|
||||
return &arModel{m.Model.Or(where, args...)}
|
||||
return &arModel{m.M.Or(where, args...)}
|
||||
}
|
||||
|
||||
// GroupBy sets the "GROUP BY" statement for the model.
|
||||
func (m *arModel) GroupBy(groupBy string) *arModel {
|
||||
return &arModel{m.Model.GroupBy(groupBy)}
|
||||
// Group sets the "GROUP BY" statement for the model.
|
||||
func (m *arModel) Group(groupBy string) *arModel {
|
||||
return &arModel{m.M.Group(groupBy)}
|
||||
}
|
||||
|
||||
// OrderBy sets the "ORDER BY" statement for the model.
|
||||
func (m *arModel) OrderBy(orderBy string) *arModel {
|
||||
return &arModel{m.Model.OrderBy(orderBy)}
|
||||
// Order sets the "ORDER BY" statement for the model.
|
||||
func (m *arModel) Order(orderBy ...string) *arModel {
|
||||
return &arModel{m.M.Order(orderBy...)}
|
||||
}
|
||||
|
||||
// Limit sets the "LIMIT" statement for the model.
|
||||
@@ -120,25 +234,25 @@ func (m *arModel) OrderBy(orderBy string) *arModel {
|
||||
// it then sets "LIMIT limit[0],limit[1]" statement for the model, or else it sets "LIMIT limit[0]"
|
||||
// statement.
|
||||
func (m *arModel) Limit(limit ...int) *arModel {
|
||||
return &arModel{m.Model.Limit(limit...)}
|
||||
return &arModel{m.M.Limit(limit...)}
|
||||
}
|
||||
|
||||
// Offset sets the "OFFSET" statement for the model.
|
||||
// It only makes sense for some databases like SQLServer, PostgreSQL, etc.
|
||||
func (m *arModel) Offset(offset int) *arModel {
|
||||
return &arModel{m.Model.Offset(offset)}
|
||||
return &arModel{m.M.Offset(offset)}
|
||||
}
|
||||
|
||||
// ForPage sets the paging number for the model.
|
||||
// Page sets the paging number for the model.
|
||||
// The parameter <page> is started from 1 for paging.
|
||||
// Note that, it differs that the Limit function start from 0 for "LIMIT" statement.
|
||||
func (m *arModel) ForPage(page, limit int) *arModel {
|
||||
return &arModel{m.Model.Page(page, limit)}
|
||||
func (m *arModel) Page(page, limit int) *arModel {
|
||||
return &arModel{m.M.Page(page, limit)}
|
||||
}
|
||||
|
||||
// Batch sets the batch operation number for the model.
|
||||
func (m *arModel) Batch(batch int) *arModel {
|
||||
return &arModel{m.Model.Batch(batch)}
|
||||
return &arModel{m.M.Batch(batch)}
|
||||
}
|
||||
|
||||
// Cache sets the cache feature for the model. It caches the result of the sql, which means
|
||||
@@ -153,8 +267,8 @@ func (m *arModel) Batch(batch int) *arModel {
|
||||
// control the cache like changing the <duration> or clearing the cache with specified <name>.
|
||||
//
|
||||
// Note that, the cache feature is disabled if the model is operating on a transaction.
|
||||
func (m *arModel) Cache(expire time.Duration, name ...string) *arModel {
|
||||
return &arModel{m.Model.Cache(expire, name...)}
|
||||
func (m *arModel) Cache(duration time.Duration, name ...string) *arModel {
|
||||
return &arModel{m.M.Cache(duration, name...)}
|
||||
}
|
||||
|
||||
// Data sets the operation data for the model.
|
||||
@@ -165,46 +279,17 @@ func (m *arModel) Cache(expire time.Duration, name ...string) *arModel {
|
||||
// Data(g.Map{"uid": 10000, "name":"john"})
|
||||
// Data(g.Slice{g.Map{"uid": 10000, "name":"john"}, g.Map{"uid": 20000, "name":"smith"})
|
||||
func (m *arModel) Data(data ...interface{}) *arModel {
|
||||
return &arModel{m.Model.Data(data...)}
|
||||
}
|
||||
|
||||
// Insert does "INSERT INTO ..." statement for the model.
|
||||
func (m *arModel) Insert() (result sql.Result, err error) {
|
||||
return m.Model.Insert()
|
||||
}
|
||||
|
||||
// Replace does "REPLACE INTO ..." statement for the model.
|
||||
func (m *arModel) Replace() (result sql.Result, err error) {
|
||||
return m.Model.Replace()
|
||||
}
|
||||
|
||||
// Save does "INSERT INTO ... ON DUPLICATE KEY UPDATE..." statement for the model.
|
||||
// It updates the record if there's primary or unique index in the saving data,
|
||||
// or else it inserts a new record into the table.
|
||||
func (m *arModel) Save() (result sql.Result, err error) {
|
||||
return m.Model.Save()
|
||||
}
|
||||
|
||||
// Update does "UPDATE ... " statement for the model.
|
||||
func (m *arModel) Update() (result sql.Result, err error) {
|
||||
return m.Model.Update()
|
||||
}
|
||||
|
||||
// Delete does "DELETE FROM ... " statement for the model.
|
||||
func (m *arModel) Delete() (result sql.Result, err error) {
|
||||
return m.Model.Delete()
|
||||
}
|
||||
|
||||
// Count does "SELECT COUNT(x) FROM ..." statement for the model.
|
||||
func (m *arModel) Count() (int, error) {
|
||||
return m.Model.Count()
|
||||
return &arModel{m.M.Data(data...)}
|
||||
}
|
||||
|
||||
// All does "SELECT FROM ..." statement for the model.
|
||||
// It retrieves the records from table and returns the result as []*Entity.
|
||||
// It returns nil if there's no record retrieved with the given conditions from table.
|
||||
func (m *arModel) All() ([]*Entity, error) {
|
||||
all, err := m.Model.All()
|
||||
//
|
||||
// The optional parameter <where> is the same as the parameter of Model.Where function,
|
||||
// see Model.Where.
|
||||
func (m *arModel) All(where ...interface{}) ([]*Entity, error) {
|
||||
all, err := m.M.All(where...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -217,8 +302,11 @@ func (m *arModel) All() ([]*Entity, error) {
|
||||
|
||||
// One retrieves one record from table and returns the result as *Entity.
|
||||
// It returns nil if there's no record retrieved with the given conditions from table.
|
||||
func (m *arModel) One() (*Entity, error) {
|
||||
one, err := m.Model.One()
|
||||
//
|
||||
// The optional parameter <where> is the same as the parameter of Model.Where function,
|
||||
// see Model.Where.
|
||||
func (m *arModel) One(where ...interface{}) (*Entity, error) {
|
||||
one, err := m.M.One(where...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -229,15 +317,37 @@ func (m *arModel) One() (*Entity, error) {
|
||||
return entity, nil
|
||||
}
|
||||
|
||||
// Value retrieves a specified record value from table and returns the result as interface type.
|
||||
// It returns nil if there's no record found with the given conditions from table.
|
||||
func (m *arModel) Value() (gdb.Value, error) {
|
||||
return m.Model.Value()
|
||||
// FindOne retrieves and returns a single Record by Model.WherePri and Model.One.
|
||||
// Also see Model.WherePri and Model.One.
|
||||
func (m *arModel) FindOne(where ...interface{}) (*Entity, error) {
|
||||
one, err := m.M.FindOne(where...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var entity *Entity
|
||||
if err = one.Struct(&entity); err != nil && err != sql.ErrNoRows {
|
||||
return nil, err
|
||||
}
|
||||
return entity, nil
|
||||
}
|
||||
|
||||
// FindAll retrieves and returns Result by by Model.WherePri and Model.All.
|
||||
// Also see Model.WherePri and Model.All.
|
||||
func (m *arModel) FindAll(where ...interface{}) ([]*Entity, error) {
|
||||
all, err := m.M.FindAll(where...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var entities []*Entity
|
||||
if err = all.Structs(&entities); err != nil && err != sql.ErrNoRows {
|
||||
return nil, err
|
||||
}
|
||||
return entities, nil
|
||||
}
|
||||
|
||||
// Chunk iterates the table with given size and callback function.
|
||||
func (m *arModel) Chunk(limit int, callback func(entities []*Entity, err error) bool) {
|
||||
m.Model.Chunk(limit, func(result gdb.Result, err error) bool {
|
||||
m.M.Chunk(limit, func(result gdb.Result, err error) bool {
|
||||
var entities []*Entity
|
||||
err = result.Structs(&entities)
|
||||
if err == sql.ErrNoRows {
|
||||
@@ -246,3 +356,18 @@ func (m *arModel) Chunk(limit int, callback func(entities []*Entity, err error)
|
||||
return callback(entities, err)
|
||||
})
|
||||
}
|
||||
|
||||
// LockUpdate sets the lock for update for current operation.
|
||||
func (m *arModel) LockUpdate() *arModel {
|
||||
return &arModel{m.M.LockUpdate()}
|
||||
}
|
||||
|
||||
// LockShared sets the lock in share mode for current operation.
|
||||
func (m *arModel) LockShared() *arModel {
|
||||
return &arModel{m.M.LockShared()}
|
||||
}
|
||||
|
||||
// Unscoped enables/disables the soft deleting feature.
|
||||
func (m *arModel) Unscoped() *arModel {
|
||||
return &arModel{m.M.Unscoped()}
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ func AddUserPost(postIds []int64, userId int64) (err error) {
|
||||
}
|
||||
|
||||
//获取用户岗位
|
||||
func GetAdminPosts(userId int) (postIds []int64, err error) {
|
||||
func GetAdminPosts(userId uint64) (postIds []int64, err error) {
|
||||
list, e := Model.All(Columns.UserId, userId)
|
||||
if e != nil {
|
||||
g.Log().Error(e)
|
||||
@@ -44,7 +44,7 @@ func GetAdminPosts(userId int) (postIds []int64, err error) {
|
||||
}
|
||||
|
||||
//根据用户id获取岗位信息详情
|
||||
func GetPostsByUserId(userId int) ([]*sys_post.Entity, error) {
|
||||
func GetPostsByUserId(userId uint64) ([]*sys_post.Entity, error) {
|
||||
model := g.DB().Table(Table)
|
||||
datas := ([]*sys_post.Entity)(nil)
|
||||
err := model.As("a").InnerJoin("sys_post b", "a.post_id = b.post_id").Fields("b.*").Where(Columns.UserId, userId).Structs(&datas)
|
||||
|
||||
Reference in New Issue
Block a user