代码拉取完成,页面将自动刷新
// @generated Do not edit this file, which is automatically generated by the generator.
package dbschema
import (
"fmt"
"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_FileEmbedded []*FileEmbedded
func (s Slice_FileEmbedded) 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_FileEmbedded) RangeRaw(fn func(m *FileEmbedded) error) error {
for _, v := range s {
if err := fn(v); err != nil {
return err
}
}
return nil
}
// FileEmbedded 嵌入文件
type FileEmbedded struct {
base factory.Base
objects []*FileEmbedded
Id uint64 `db:"id,omitempty,pk" bson:"id,omitempty" comment:"主键" json:"id" xml:"id"`
Project string `db:"project" bson:"project" comment:"项目名" json:"project" xml:"project"`
TableId string `db:"table_id" bson:"table_id" comment:"表主键" json:"table_id" xml:"table_id"`
TableName string `db:"table_name" bson:"table_name" comment:"表名称" json:"table_name" xml:"table_name"`
FieldName string `db:"field_name" bson:"field_name" comment:"字段名" json:"field_name" xml:"field_name"`
FileIds string `db:"file_ids" bson:"file_ids" comment:"文件id列表" json:"file_ids" xml:"file_ids"`
Embedded string `db:"embedded" bson:"embedded" comment:"是否(Y/N)为内嵌文件" json:"embedded" xml:"embedded"`
}
// - base function
func (a *FileEmbedded) Trans() *factory.Transaction {
return a.base.Trans()
}
func (a *FileEmbedded) Use(trans *factory.Transaction) factory.Model {
a.base.Use(trans)
return a
}
func (a *FileEmbedded) SetContext(ctx echo.Context) factory.Model {
a.base.SetContext(ctx)
return a
}
func (a *FileEmbedded) EventON(on ...bool) factory.Model {
a.base.EventON(on...)
return a
}
func (a *FileEmbedded) EventOFF(off ...bool) factory.Model {
a.base.EventOFF(off...)
return a
}
func (a *FileEmbedded) Context() echo.Context {
return a.base.Context()
}
func (a *FileEmbedded) SetConnID(connID int) factory.Model {
a.base.SetConnID(connID)
return a
}
func (a *FileEmbedded) SetNamer(namer func(string) string) factory.Model {
a.base.SetNamer(namer)
return a
}
func (a *FileEmbedded) Namer() func(string) string {
return a.base.Namer()
}
func (a *FileEmbedded) SetParam(param *factory.Param) factory.Model {
a.base.SetParam(param)
return a
}
func (a *FileEmbedded) 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 *FileEmbedded) 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 *FileEmbedded) Objects() []*FileEmbedded {
if a.objects == nil {
return nil
}
return a.objects[:]
}
func (a *FileEmbedded) NewObjects() factory.Ranger {
return &Slice_FileEmbedded{}
}
func (a *FileEmbedded) InitObjects() *[]*FileEmbedded {
a.objects = []*FileEmbedded{}
return &a.objects
}
func (a *FileEmbedded) NewParam() *factory.Param {
return factory.NewParam(factory.DefaultFactory).SetIndex(a.base.ConnID()).SetTrans(a.base.Trans()).SetCollection(a.Name_()).SetModel(a)
}
func (a *FileEmbedded) Short_() string {
return "file_embedded"
}
func (a *FileEmbedded) Struct_() string {
return "FileEmbedded"
}
func (a *FileEmbedded) Name_() string {
if a.base.Namer() != nil {
return WithPrefix(a.base.Namer()(a.Short_()))
}
return WithPrefix(factory.TableNamerGet(a.Short_())(a))
}
func (a *FileEmbedded) CPAFrom(source factory.Model) factory.Model {
a.SetContext(source.Context())
a.Use(source.Trans())
a.SetNamer(source.Namer())
return a
}
func (a *FileEmbedded) 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 *FileEmbedded) 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 *FileEmbedded) GroupBy(keyField string, inputRows ...[]*FileEmbedded) map[string][]*FileEmbedded {
var rows []*FileEmbedded
if len(inputRows) > 0 {
rows = inputRows[0]
} else {
rows = a.Objects()
}
r := map[string][]*FileEmbedded{}
for _, row := range rows {
dmap := row.AsMap()
vkey := fmt.Sprint(dmap[keyField])
if _, y := r[vkey]; !y {
r[vkey] = []*FileEmbedded{}
}
r[vkey] = append(r[vkey], row)
}
return r
}
func (a *FileEmbedded) KeyBy(keyField string, inputRows ...[]*FileEmbedded) map[string]*FileEmbedded {
var rows []*FileEmbedded
if len(inputRows) > 0 {
rows = inputRows[0]
} else {
rows = a.Objects()
}
r := map[string]*FileEmbedded{}
for _, row := range rows {
dmap := row.AsMap()
vkey := fmt.Sprint(dmap[keyField])
r[vkey] = row
}
return r
}
func (a *FileEmbedded) AsKV(keyField string, valueField string, inputRows ...[]*FileEmbedded) map[string]interface{} {
var rows []*FileEmbedded
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 *FileEmbedded) 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 *FileEmbedded) Add() (pk interface{}, err error) {
a.Id = 0
if len(a.TableId) == 0 {
a.TableId = "0"
}
if len(a.Embedded) == 0 {
a.Embedded = "Y"
}
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.(uint64); y {
a.Id = v
} else if v, y := pk.(int64); y {
a.Id = uint64(v)
}
}
if err == nil && a.base.Eventable() {
err = DBI.Fire("created", a, nil)
}
return
}
func (a *FileEmbedded) Edit(mw func(db.Result) db.Result, args ...interface{}) (err error) {
if len(a.TableId) == 0 {
a.TableId = "0"
}
if len(a.Embedded) == 0 {
a.Embedded = "Y"
}
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 *FileEmbedded) 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 *FileEmbedded) SetFields(mw func(db.Result) db.Result, kvset map[string]interface{}, args ...interface{}) (err error) {
if val, ok := kvset["table_id"]; ok && val != nil {
if v, ok := val.(string); ok && len(v) == 0 {
kvset["table_id"] = "0"
}
}
if val, ok := kvset["embedded"]; ok && val != nil {
if v, ok := val.(string); ok && len(v) == 0 {
kvset["embedded"] = "Y"
}
}
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 *FileEmbedded) Upsert(mw func(db.Result) db.Result, args ...interface{}) (pk interface{}, err error) {
pk, err = a.Param(mw, args...).SetSend(a).Upsert(func() error {
if len(a.TableId) == 0 {
a.TableId = "0"
}
if len(a.Embedded) == 0 {
a.Embedded = "Y"
}
if !a.base.Eventable() {
return nil
}
return DBI.Fire("updating", a, mw, args...)
}, func() error {
a.Id = 0
if len(a.TableId) == 0 {
a.TableId = "0"
}
if len(a.Embedded) == 0 {
a.Embedded = "Y"
}
if !a.base.Eventable() {
return nil
}
return DBI.Fire("creating", a, nil)
})
if err == nil && pk != nil {
if v, y := pk.(uint64); y {
a.Id = v
} else if v, y := pk.(int64); y {
a.Id = uint64(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 *FileEmbedded) 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 *FileEmbedded) Count(mw func(db.Result) db.Result, args ...interface{}) (int64, error) {
return a.Param(mw, args...).Count()
}
func (a *FileEmbedded) Reset() *FileEmbedded {
a.Id = 0
a.Project = ``
a.TableId = ``
a.TableName = ``
a.FieldName = ``
a.FileIds = ``
a.Embedded = ``
return a
}
func (a *FileEmbedded) AsMap() map[string]interface{} {
r := map[string]interface{}{}
r["Id"] = a.Id
r["Project"] = a.Project
r["TableId"] = a.TableId
r["TableName"] = a.TableName
r["FieldName"] = a.FieldName
r["FileIds"] = a.FileIds
r["Embedded"] = a.Embedded
return r
}
func (a *FileEmbedded) FromRow(row map[string]interface{}) {
for key, value := range row {
switch key {
case "id":
a.Id = param.AsUint64(value)
case "project":
a.Project = param.AsString(value)
case "table_id":
a.TableId = param.AsString(value)
case "table_name":
a.TableName = param.AsString(value)
case "field_name":
a.FieldName = param.AsString(value)
case "file_ids":
a.FileIds = param.AsString(value)
case "embedded":
a.Embedded = param.AsString(value)
}
}
}
func (a *FileEmbedded) 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.AsUint64(vv)
case "Project":
a.Project = param.AsString(vv)
case "TableId":
a.TableId = param.AsString(vv)
case "TableName":
a.TableName = param.AsString(vv)
case "FieldName":
a.FieldName = param.AsString(vv)
case "FileIds":
a.FileIds = param.AsString(vv)
case "Embedded":
a.Embedded = param.AsString(vv)
}
}
}
func (a *FileEmbedded) AsRow() map[string]interface{} {
r := map[string]interface{}{}
r["id"] = a.Id
r["project"] = a.Project
r["table_id"] = a.TableId
r["table_name"] = a.TableName
r["field_name"] = a.FieldName
r["file_ids"] = a.FileIds
r["embedded"] = a.Embedded
return r
}
func (a *FileEmbedded) BatchValidate(kvset map[string]interface{}) error {
if kvset == nil {
kvset = a.AsRow()
}
return factory.BatchValidate(a.Short_(), kvset)
}
func (a *FileEmbedded) Validate(field string, value interface{}) error {
return factory.Validate(a.Short_(), field, value)
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。