代码拉取完成,页面将自动刷新
// @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_NgingDbSync []*NgingDbSync
func (s Slice_NgingDbSync) 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_NgingDbSync) RangeRaw(fn func(m *NgingDbSync) error) error {
for _, v := range s {
if err := fn(v); err != nil {
return err
}
}
return nil
}
func (s Slice_NgingDbSync) GroupBy(keyField string) map[string][]*NgingDbSync {
r := map[string][]*NgingDbSync{}
for _, row := range s {
dmap := row.AsMap()
vkey := fmt.Sprint(dmap[keyField])
if _, y := r[vkey]; !y {
r[vkey] = []*NgingDbSync{}
}
r[vkey] = append(r[vkey], row)
}
return r
}
func (s Slice_NgingDbSync) KeyBy(keyField string) map[string]*NgingDbSync {
r := map[string]*NgingDbSync{}
for _, row := range s {
dmap := row.AsMap()
vkey := fmt.Sprint(dmap[keyField])
r[vkey] = row
}
return r
}
func (s Slice_NgingDbSync) AsKV(keyField string, valueField string) param.Store {
r := param.Store{}
for _, row := range s {
dmap := row.AsMap()
vkey := fmt.Sprint(dmap[keyField])
r[vkey] = dmap[valueField]
}
return r
}
func (s Slice_NgingDbSync) Transform(transfers map[string]param.Transfer) []param.Store {
r := make([]param.Store, len(s))
for idx, row := range s {
r[idx] = row.AsMap().Transform(transfers)
}
return r
}
func (s Slice_NgingDbSync) FromList(data interface{}) Slice_NgingDbSync {
values, ok := data.([]*NgingDbSync)
if !ok {
for _, value := range data.([]interface{}) {
row := &NgingDbSync{}
row.FromRow(value.(map[string]interface{}))
s = append(s, row)
}
return s
}
s = append(s, values...)
return s
}
// NgingDbSync 数据表同步方案
type NgingDbSync struct {
base factory.Base
objects []*NgingDbSync
Id uint `db:"id,omitempty,pk" bson:"id,omitempty" comment:"ID" json:"id" xml:"id"`
Name string `db:"name" bson:"name" comment:"方案名" json:"name" xml:"name"`
SourceAccountId uint `db:"source_account_id" bson:"source_account_id" comment:"源数据库账号ID" json:"source_account_id" xml:"source_account_id"`
DsnSource string `db:"dsn_source" bson:"dsn_source" comment:"同步源" json:"dsn_source" xml:"dsn_source"`
DestinationAccountId uint `db:"destination_account_id" bson:"destination_account_id" comment:"目标数据库账号ID" json:"destination_account_id" xml:"destination_account_id"`
DsnDestination string `db:"dsn_destination" bson:"dsn_destination" comment:"目标数据库" json:"dsn_destination" xml:"dsn_destination"`
Tables string `db:"tables" bson:"tables" comment:"要同步的表" json:"tables" xml:"tables"`
SkipTables string `db:"skip_tables" bson:"skip_tables" comment:"要跳过的表" json:"skip_tables" xml:"skip_tables"`
AlterIgnore string `db:"alter_ignore" bson:"alter_ignore" comment:"要忽略的列、索引、外键" json:"alter_ignore" xml:"alter_ignore"`
Drop uint `db:"drop" bson:"drop" comment:"删除待同步数据库中多余的字段、索引、外键 " json:"drop" xml:"drop"`
MailTo string `db:"mail_to" bson:"mail_to" comment:"发送邮件" json:"mail_to" xml:"mail_to"`
Created uint `db:"created" bson:"created" comment:"创建时间" json:"created" xml:"created"`
Updated int `db:"updated" bson:"updated" comment:"更新时间" json:"updated" xml:"updated"`
}
// - base function
func (a *NgingDbSync) Trans() *factory.Transaction {
return a.base.Trans()
}
func (a *NgingDbSync) Use(trans *factory.Transaction) factory.Model {
a.base.Use(trans)
return a
}
func (a *NgingDbSync) SetContext(ctx echo.Context) factory.Model {
a.base.SetContext(ctx)
return a
}
func (a *NgingDbSync) EventON(on ...bool) factory.Model {
a.base.EventON(on...)
return a
}
func (a *NgingDbSync) EventOFF(off ...bool) factory.Model {
a.base.EventOFF(off...)
return a
}
func (a *NgingDbSync) Context() echo.Context {
return a.base.Context()
}
func (a *NgingDbSync) SetConnID(connID int) factory.Model {
a.base.SetConnID(connID)
return a
}
func (a *NgingDbSync) SetNamer(namer func(string) string) factory.Model {
a.base.SetNamer(namer)
return a
}
func (a *NgingDbSync) Namer() func(string) string {
return a.base.Namer()
}
func (a *NgingDbSync) SetParam(param *factory.Param) factory.Model {
a.base.SetParam(param)
return a
}
func (a *NgingDbSync) 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 *NgingDbSync) 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 *NgingDbSync) Objects() []*NgingDbSync {
if a.objects == nil {
return nil
}
return a.objects[:]
}
func (a *NgingDbSync) XObjects() Slice_NgingDbSync {
return Slice_NgingDbSync(a.Objects())
}
func (a *NgingDbSync) NewObjects() factory.Ranger {
return &Slice_NgingDbSync{}
}
func (a *NgingDbSync) InitObjects() *[]*NgingDbSync {
a.objects = []*NgingDbSync{}
return &a.objects
}
func (a *NgingDbSync) NewParam() *factory.Param {
return factory.NewParam(factory.DefaultFactory).SetIndex(a.base.ConnID()).SetTrans(a.base.Trans()).SetCollection(a.Name_()).SetModel(a)
}
func (a *NgingDbSync) Short_() string {
return "nging_db_sync"
}
func (a *NgingDbSync) Struct_() string {
return "NgingDbSync"
}
func (a *NgingDbSync) Name_() string {
if a.base.Namer() != nil {
return WithPrefix(a.base.Namer()(a.Short_()))
}
return WithPrefix(factory.TableNamerGet(a.Short_())(a))
}
func (a *NgingDbSync) CPAFrom(source factory.Model) factory.Model {
a.SetContext(source.Context())
a.Use(source.Trans())
a.SetNamer(source.Namer())
return a
}
func (a *NgingDbSync) Get(mw func(db.Result) db.Result, args ...interface{}) (err error) {
base := a.base
if !a.base.Eventable() {
err = a.Param(mw, args...).SetRecv(a).One()
a.base = base
return
}
queryParam := a.Param(mw, args...).SetRecv(a)
if err = DBI.FireReading(a, queryParam); err != nil {
return
}
err = queryParam.One()
a.base = base
if err == nil {
err = DBI.FireReaded(a, queryParam)
}
return
}
func (a *NgingDbSync) List(recv interface{}, mw func(db.Result) db.Result, page, size int, args ...interface{}) (func() int64, error) {
if recv == nil {
recv = a.InitObjects()
}
if !a.base.Eventable() {
return a.Param(mw, args...).SetPage(page).SetSize(size).SetRecv(recv).List()
}
queryParam := a.Param(mw, args...).SetPage(page).SetSize(size).SetRecv(recv)
if err := DBI.FireReading(a, queryParam); err != nil {
return nil, err
}
cnt, err := queryParam.List()
if err == nil {
switch v := recv.(type) {
case *[]*NgingDbSync:
err = DBI.FireReaded(a, queryParam, Slice_NgingDbSync(*v))
case []*NgingDbSync:
err = DBI.FireReaded(a, queryParam, Slice_NgingDbSync(v))
case factory.Ranger:
err = DBI.FireReaded(a, queryParam, v)
}
}
return cnt, err
}
func (a *NgingDbSync) GroupBy(keyField string, inputRows ...[]*NgingDbSync) map[string][]*NgingDbSync {
var rows Slice_NgingDbSync
if len(inputRows) > 0 {
rows = Slice_NgingDbSync(inputRows[0])
} else {
rows = Slice_NgingDbSync(a.Objects())
}
return rows.GroupBy(keyField)
}
func (a *NgingDbSync) KeyBy(keyField string, inputRows ...[]*NgingDbSync) map[string]*NgingDbSync {
var rows Slice_NgingDbSync
if len(inputRows) > 0 {
rows = Slice_NgingDbSync(inputRows[0])
} else {
rows = Slice_NgingDbSync(a.Objects())
}
return rows.KeyBy(keyField)
}
func (a *NgingDbSync) AsKV(keyField string, valueField string, inputRows ...[]*NgingDbSync) param.Store {
var rows Slice_NgingDbSync
if len(inputRows) > 0 {
rows = Slice_NgingDbSync(inputRows[0])
} else {
rows = Slice_NgingDbSync(a.Objects())
}
return rows.AsKV(keyField, valueField)
}
func (a *NgingDbSync) ListByOffset(recv interface{}, mw func(db.Result) db.Result, offset, size int, args ...interface{}) (func() int64, error) {
if recv == nil {
recv = a.InitObjects()
}
if !a.base.Eventable() {
return a.Param(mw, args...).SetOffset(offset).SetSize(size).SetRecv(recv).List()
}
queryParam := a.Param(mw, args...).SetOffset(offset).SetSize(size).SetRecv(recv)
if err := DBI.FireReading(a, queryParam); err != nil {
return nil, err
}
cnt, err := queryParam.List()
if err == nil {
switch v := recv.(type) {
case *[]*NgingDbSync:
err = DBI.FireReaded(a, queryParam, Slice_NgingDbSync(*v))
case []*NgingDbSync:
err = DBI.FireReaded(a, queryParam, Slice_NgingDbSync(v))
case factory.Ranger:
err = DBI.FireReaded(a, queryParam, v)
}
}
return cnt, err
}
func (a *NgingDbSync) 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 *NgingDbSync) Edit(mw func(db.Result) db.Result, args ...interface{}) (err error) {
a.Updated = int(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 *NgingDbSync) 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 *NgingDbSync) SetFields(mw func(db.Result) db.Result, kvset map[string]interface{}, args ...interface{}) (err error) {
kvset["updated"] = int(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 *NgingDbSync) 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 = int(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 *NgingDbSync) 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 *NgingDbSync) Count(mw func(db.Result) db.Result, args ...interface{}) (int64, error) {
return a.Param(mw, args...).Count()
}
func (a *NgingDbSync) Reset() *NgingDbSync {
a.Id = 0
a.Name = ``
a.SourceAccountId = 0
a.DsnSource = ``
a.DestinationAccountId = 0
a.DsnDestination = ``
a.Tables = ``
a.SkipTables = ``
a.AlterIgnore = ``
a.Drop = 0
a.MailTo = ``
a.Created = 0
a.Updated = 0
return a
}
func (a *NgingDbSync) AsMap() param.Store {
r := param.Store{}
r["Id"] = a.Id
r["Name"] = a.Name
r["SourceAccountId"] = a.SourceAccountId
r["DsnSource"] = a.DsnSource
r["DestinationAccountId"] = a.DestinationAccountId
r["DsnDestination"] = a.DsnDestination
r["Tables"] = a.Tables
r["SkipTables"] = a.SkipTables
r["AlterIgnore"] = a.AlterIgnore
r["Drop"] = a.Drop
r["MailTo"] = a.MailTo
r["Created"] = a.Created
r["Updated"] = a.Updated
return r
}
func (a *NgingDbSync) FromRow(row map[string]interface{}) {
for key, value := range row {
switch key {
case "id":
a.Id = param.AsUint(value)
case "name":
a.Name = param.AsString(value)
case "source_account_id":
a.SourceAccountId = param.AsUint(value)
case "dsn_source":
a.DsnSource = param.AsString(value)
case "destination_account_id":
a.DestinationAccountId = param.AsUint(value)
case "dsn_destination":
a.DsnDestination = param.AsString(value)
case "tables":
a.Tables = param.AsString(value)
case "skip_tables":
a.SkipTables = param.AsString(value)
case "alter_ignore":
a.AlterIgnore = param.AsString(value)
case "drop":
a.Drop = param.AsUint(value)
case "mail_to":
a.MailTo = param.AsString(value)
case "created":
a.Created = param.AsUint(value)
case "updated":
a.Updated = param.AsInt(value)
}
}
}
func (a *NgingDbSync) 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 "Name":
a.Name = param.AsString(vv)
case "SourceAccountId":
a.SourceAccountId = param.AsUint(vv)
case "DsnSource":
a.DsnSource = param.AsString(vv)
case "DestinationAccountId":
a.DestinationAccountId = param.AsUint(vv)
case "DsnDestination":
a.DsnDestination = param.AsString(vv)
case "Tables":
a.Tables = param.AsString(vv)
case "SkipTables":
a.SkipTables = param.AsString(vv)
case "AlterIgnore":
a.AlterIgnore = param.AsString(vv)
case "Drop":
a.Drop = param.AsUint(vv)
case "MailTo":
a.MailTo = param.AsString(vv)
case "Created":
a.Created = param.AsUint(vv)
case "Updated":
a.Updated = param.AsInt(vv)
}
}
}
func (a *NgingDbSync) AsRow() param.Store {
r := param.Store{}
r["id"] = a.Id
r["name"] = a.Name
r["source_account_id"] = a.SourceAccountId
r["dsn_source"] = a.DsnSource
r["destination_account_id"] = a.DestinationAccountId
r["dsn_destination"] = a.DsnDestination
r["tables"] = a.Tables
r["skip_tables"] = a.SkipTables
r["alter_ignore"] = a.AlterIgnore
r["drop"] = a.Drop
r["mail_to"] = a.MailTo
r["created"] = a.Created
r["updated"] = a.Updated
return r
}
func (a *NgingDbSync) BatchValidate(kvset map[string]interface{}) error {
if kvset == nil {
kvset = a.AsRow()
}
return factory.BatchValidate(a.Short_(), kvset)
}
func (a *NgingDbSync) Validate(field string, value interface{}) error {
return factory.Validate(a.Short_(), field, value)
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。