65 Star 396 Fork 128

admpub/nging

Create your Gitee Account
Explore and code with more than 12 million developers,Free private repositories !:)
Sign up
文件
Clone or Download
FrpGroup.go 10.16 KB
Copy Edit Raw Blame History
admpub authored 2019-10-27 20:57 . update
// @generated Do not edit this file, which is automatically generated by the generator.
package dbschema
import (
"fmt"
"time"
"github.com/webx-top/db"
"github.com/webx-top/db/lib/factory"
"github.com/webx-top/echo"
"github.com/webx-top/echo/param"
)
type Slice_FrpGroup []*FrpGroup
func (s Slice_FrpGroup) Range(fn func(m factory.Model) error) error {
for _, v := range s {
if err := fn(v); err != nil {
return err
}
}
return nil
}
func (s Slice_FrpGroup) RangeRaw(fn func(m *FrpGroup) error) error {
for _, v := range s {
if err := fn(v); err != nil {
return err
}
}
return nil
}
// FrpGroup FRP服务组
type FrpGroup struct {
base factory.Base
objects []*FrpGroup
Id uint `db:"id,omitempty,pk" bson:"id,omitempty" comment:"" json:"id" xml:"id"`
Uid uint `db:"uid" bson:"uid" comment:"用户ID" json:"uid" xml:"uid"`
Name string `db:"name" bson:"name" comment:"组名" json:"name" xml:"name"`
Description string `db:"description" bson:"description" comment:"说明" json:"description" xml:"description"`
Created uint `db:"created" bson:"created" comment:"创建时间" json:"created" xml:"created"`
Updated uint `db:"updated" bson:"updated" comment:"修改时间" json:"updated" xml:"updated"`
}
// - base function
func (a *FrpGroup) Trans() *factory.Transaction {
return a.base.Trans()
}
func (a *FrpGroup) Use(trans *factory.Transaction) factory.Model {
a.base.Use(trans)
return a
}
func (a *FrpGroup) SetContext(ctx echo.Context) factory.Model {
a.base.SetContext(ctx)
return a
}
func (a *FrpGroup) EventON(on ...bool) factory.Model {
a.base.EventON(on...)
return a
}
func (a *FrpGroup) EventOFF(off ...bool) factory.Model {
a.base.EventOFF(off...)
return a
}
func (a *FrpGroup) Context() echo.Context {
return a.base.Context()
}
func (a *FrpGroup) SetConnID(connID int) factory.Model {
a.base.SetConnID(connID)
return a
}
func (a *FrpGroup) SetNamer(namer func(string) string) factory.Model {
a.base.SetNamer(namer)
return a
}
func (a *FrpGroup) Namer() func(string) string {
return a.base.Namer()
}
func (a *FrpGroup) SetParam(param *factory.Param) factory.Model {
a.base.SetParam(param)
return a
}
func (a *FrpGroup) Param(mw func(db.Result) db.Result, args ...interface{}) *factory.Param {
if a.base.Param() == nil {
return a.NewParam().SetMiddleware(mw).SetArgs(args...)
}
return a.base.Param().SetMiddleware(mw).SetArgs(args...)
}
// - current function
func (a *FrpGroup) New(structName string, connID ...int) factory.Model {
if len(connID) > 0 {
return factory.NewModel(structName, connID[0]).Use(a.base.Trans())
}
return factory.NewModel(structName, a.base.ConnID()).Use(a.base.Trans())
}
func (a *FrpGroup) Objects() []*FrpGroup {
if a.objects == nil {
return nil
}
return a.objects[:]
}
func (a *FrpGroup) NewObjects() factory.Ranger {
return &Slice_FrpGroup{}
}
func (a *FrpGroup) InitObjects() *[]*FrpGroup {
a.objects = []*FrpGroup{}
return &a.objects
}
func (a *FrpGroup) NewParam() *factory.Param {
return factory.NewParam(factory.DefaultFactory).SetIndex(a.base.ConnID()).SetTrans(a.base.Trans()).SetCollection(a.Name_()).SetModel(a)
}
func (a *FrpGroup) Short_() string {
return "frp_group"
}
func (a *FrpGroup) Struct_() string {
return "FrpGroup"
}
func (a *FrpGroup) Name_() string {
if a.base.Namer() != nil {
return WithPrefix(a.base.Namer()(a.Short_()))
}
return WithPrefix(factory.TableNamerGet(a.Short_())(a))
}
func (a *FrpGroup) CPAFrom(source factory.Model) factory.Model {
a.SetContext(source.Context())
a.Use(source.Trans())
a.SetNamer(source.Namer())
return a
}
func (a *FrpGroup) Get(mw func(db.Result) db.Result, args ...interface{}) error {
base := a.base
err := a.Param(mw, args...).SetRecv(a).One()
a.base = base
return err
}
func (a *FrpGroup) List(recv interface{}, mw func(db.Result) db.Result, page, size int, args ...interface{}) (func() int64, error) {
if recv == nil {
recv = a.InitObjects()
}
return a.Param(mw, args...).SetPage(page).SetSize(size).SetRecv(recv).List()
}
func (a *FrpGroup) GroupBy(keyField string, inputRows ...[]*FrpGroup) map[string][]*FrpGroup {
var rows []*FrpGroup
if len(inputRows) > 0 {
rows = inputRows[0]
} else {
rows = a.Objects()
}
r := map[string][]*FrpGroup{}
for _, row := range rows {
dmap := row.AsMap()
vkey := fmt.Sprint(dmap[keyField])
if _, y := r[vkey]; !y {
r[vkey] = []*FrpGroup{}
}
r[vkey] = append(r[vkey], row)
}
return r
}
func (a *FrpGroup) KeyBy(keyField string, inputRows ...[]*FrpGroup) map[string]*FrpGroup {
var rows []*FrpGroup
if len(inputRows) > 0 {
rows = inputRows[0]
} else {
rows = a.Objects()
}
r := map[string]*FrpGroup{}
for _, row := range rows {
dmap := row.AsMap()
vkey := fmt.Sprint(dmap[keyField])
r[vkey] = row
}
return r
}
func (a *FrpGroup) AsKV(keyField string, valueField string, inputRows ...[]*FrpGroup) map[string]interface{} {
var rows []*FrpGroup
if len(inputRows) > 0 {
rows = inputRows[0]
} else {
rows = a.Objects()
}
r := map[string]interface{}{}
for _, row := range rows {
dmap := row.AsMap()
vkey := fmt.Sprint(dmap[keyField])
r[vkey] = dmap[valueField]
}
return r
}
func (a *FrpGroup) ListByOffset(recv interface{}, mw func(db.Result) db.Result, offset, size int, args ...interface{}) (func() int64, error) {
if recv == nil {
recv = a.InitObjects()
}
return a.Param(mw, args...).SetOffset(offset).SetSize(size).SetRecv(recv).List()
}
func (a *FrpGroup) Add() (pk interface{}, err error) {
a.Created = uint(time.Now().Unix())
a.Id = 0
if a.base.Eventable() {
err = DBI.Fire("creating", a, nil)
if err != nil {
return
}
}
pk, err = a.Param(nil).SetSend(a).Insert()
if err == nil && pk != nil {
if v, y := pk.(uint); y {
a.Id = v
} else if v, y := pk.(int64); y {
a.Id = uint(v)
}
}
if err == nil && a.base.Eventable() {
err = DBI.Fire("created", a, nil)
}
return
}
func (a *FrpGroup) Edit(mw func(db.Result) db.Result, args ...interface{}) (err error) {
a.Updated = uint(time.Now().Unix())
if !a.base.Eventable() {
return a.Param(mw, args...).SetSend(a).Update()
}
if err = DBI.Fire("updating", a, mw, args...); err != nil {
return
}
if err = a.Param(mw, args...).SetSend(a).Update(); err != nil {
return
}
return DBI.Fire("updated", a, mw, args...)
}
func (a *FrpGroup) SetField(mw func(db.Result) db.Result, field string, value interface{}, args ...interface{}) (err error) {
return a.SetFields(mw, map[string]interface{}{
field: value,
}, args...)
}
func (a *FrpGroup) SetFields(mw func(db.Result) db.Result, kvset map[string]interface{}, args ...interface{}) (err error) {
kvset["updated"] = uint(time.Now().Unix())
if !a.base.Eventable() {
return a.Param(mw, args...).SetSend(kvset).Update()
}
m := *a
m.FromRow(kvset)
var editColumns []string
for column := range kvset {
editColumns = append(editColumns, column)
}
if err = DBI.FireUpdate("updating", &m, editColumns, mw, args...); err != nil {
return
}
if err = a.Param(mw, args...).SetSend(kvset).Update(); err != nil {
return
}
return DBI.FireUpdate("updated", &m, editColumns, mw, args...)
}
func (a *FrpGroup) Upsert(mw func(db.Result) db.Result, args ...interface{}) (pk interface{}, err error) {
pk, err = a.Param(mw, args...).SetSend(a).Upsert(func() error {
a.Updated = uint(time.Now().Unix())
if !a.base.Eventable() {
return nil
}
return DBI.Fire("updating", a, mw, args...)
}, func() error {
a.Created = uint(time.Now().Unix())
a.Id = 0
if !a.base.Eventable() {
return nil
}
return DBI.Fire("creating", a, nil)
})
if err == nil && pk != nil {
if v, y := pk.(uint); y {
a.Id = v
} else if v, y := pk.(int64); y {
a.Id = uint(v)
}
}
if err == nil && a.base.Eventable() {
if pk == nil {
err = DBI.Fire("updated", a, mw, args...)
} else {
err = DBI.Fire("created", a, nil)
}
}
return
}
func (a *FrpGroup) Delete(mw func(db.Result) db.Result, args ...interface{}) (err error) {
if !a.base.Eventable() {
return a.Param(mw, args...).Delete()
}
if err = DBI.Fire("deleting", a, mw, args...); err != nil {
return
}
if err = a.Param(mw, args...).Delete(); err != nil {
return
}
return DBI.Fire("deleted", a, mw, args...)
}
func (a *FrpGroup) Count(mw func(db.Result) db.Result, args ...interface{}) (int64, error) {
return a.Param(mw, args...).Count()
}
func (a *FrpGroup) Reset() *FrpGroup {
a.Id = 0
a.Uid = 0
a.Name = ``
a.Description = ``
a.Created = 0
a.Updated = 0
return a
}
func (a *FrpGroup) AsMap() map[string]interface{} {
r := map[string]interface{}{}
r["Id"] = a.Id
r["Uid"] = a.Uid
r["Name"] = a.Name
r["Description"] = a.Description
r["Created"] = a.Created
r["Updated"] = a.Updated
return r
}
func (a *FrpGroup) FromRow(row map[string]interface{}) {
for key, value := range row {
switch key {
case "id":
a.Id = param.AsUint(value)
case "uid":
a.Uid = param.AsUint(value)
case "name":
a.Name = param.AsString(value)
case "description":
a.Description = param.AsString(value)
case "created":
a.Created = param.AsUint(value)
case "updated":
a.Updated = param.AsUint(value)
}
}
}
func (a *FrpGroup) Set(key interface{}, value ...interface{}) {
switch k := key.(type) {
case map[string]interface{}:
for kk, vv := range k {
a.Set(kk, vv)
}
default:
var (
kk string
vv interface{}
)
if k, y := key.(string); y {
kk = k
} else {
kk = fmt.Sprint(key)
}
if len(value) > 0 {
vv = value[0]
}
switch kk {
case "Id":
a.Id = param.AsUint(vv)
case "Uid":
a.Uid = param.AsUint(vv)
case "Name":
a.Name = param.AsString(vv)
case "Description":
a.Description = param.AsString(vv)
case "Created":
a.Created = param.AsUint(vv)
case "Updated":
a.Updated = param.AsUint(vv)
}
}
}
func (a *FrpGroup) AsRow() map[string]interface{} {
r := map[string]interface{}{}
r["id"] = a.Id
r["uid"] = a.Uid
r["name"] = a.Name
r["description"] = a.Description
r["created"] = a.Created
r["updated"] = a.Updated
return r
}
func (a *FrpGroup) BatchValidate(kvset map[string]interface{}) error {
if kvset == nil {
kvset = a.AsRow()
}
return factory.BatchValidate(a.Short_(), kvset)
}
func (a *FrpGroup) Validate(field string, value interface{}) error {
return factory.Validate(a.Short_(), field, value)
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/admpub/nging.git
git@gitee.com:admpub/nging.git
admpub
nging
nging
v2.1.0

Search