mirror of
https://github.com/0xJacky/nginx-ui.git
synced 2025-05-10 18:05:48 +02:00
feat(env_group): migrate site_category to env_group
This commit is contained in:
parent
de1860718e
commit
a379211e3c
66 changed files with 4837 additions and 4251 deletions
374
query/env_groups.gen.go
Normal file
374
query/env_groups.gen.go
Normal file
|
@ -0,0 +1,374 @@
|
|||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
|
||||
package query
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/clause"
|
||||
"gorm.io/gorm/schema"
|
||||
|
||||
"gorm.io/gen"
|
||||
"gorm.io/gen/field"
|
||||
|
||||
"gorm.io/plugin/dbresolver"
|
||||
|
||||
"github.com/0xJacky/Nginx-UI/model"
|
||||
)
|
||||
|
||||
func newEnvGroup(db *gorm.DB, opts ...gen.DOOption) envGroup {
|
||||
_envGroup := envGroup{}
|
||||
|
||||
_envGroup.envGroupDo.UseDB(db, opts...)
|
||||
_envGroup.envGroupDo.UseModel(&model.EnvGroup{})
|
||||
|
||||
tableName := _envGroup.envGroupDo.TableName()
|
||||
_envGroup.ALL = field.NewAsterisk(tableName)
|
||||
_envGroup.ID = field.NewUint64(tableName, "id")
|
||||
_envGroup.CreatedAt = field.NewTime(tableName, "created_at")
|
||||
_envGroup.UpdatedAt = field.NewTime(tableName, "updated_at")
|
||||
_envGroup.DeletedAt = field.NewField(tableName, "deleted_at")
|
||||
_envGroup.Name = field.NewString(tableName, "name")
|
||||
_envGroup.SyncNodeIds = field.NewField(tableName, "sync_node_ids")
|
||||
_envGroup.OrderID = field.NewInt(tableName, "order_id")
|
||||
|
||||
_envGroup.fillFieldMap()
|
||||
|
||||
return _envGroup
|
||||
}
|
||||
|
||||
type envGroup struct {
|
||||
envGroupDo
|
||||
|
||||
ALL field.Asterisk
|
||||
ID field.Uint64
|
||||
CreatedAt field.Time
|
||||
UpdatedAt field.Time
|
||||
DeletedAt field.Field
|
||||
Name field.String
|
||||
SyncNodeIds field.Field
|
||||
OrderID field.Int
|
||||
|
||||
fieldMap map[string]field.Expr
|
||||
}
|
||||
|
||||
func (e envGroup) Table(newTableName string) *envGroup {
|
||||
e.envGroupDo.UseTable(newTableName)
|
||||
return e.updateTableName(newTableName)
|
||||
}
|
||||
|
||||
func (e envGroup) As(alias string) *envGroup {
|
||||
e.envGroupDo.DO = *(e.envGroupDo.As(alias).(*gen.DO))
|
||||
return e.updateTableName(alias)
|
||||
}
|
||||
|
||||
func (e *envGroup) updateTableName(table string) *envGroup {
|
||||
e.ALL = field.NewAsterisk(table)
|
||||
e.ID = field.NewUint64(table, "id")
|
||||
e.CreatedAt = field.NewTime(table, "created_at")
|
||||
e.UpdatedAt = field.NewTime(table, "updated_at")
|
||||
e.DeletedAt = field.NewField(table, "deleted_at")
|
||||
e.Name = field.NewString(table, "name")
|
||||
e.SyncNodeIds = field.NewField(table, "sync_node_ids")
|
||||
e.OrderID = field.NewInt(table, "order_id")
|
||||
|
||||
e.fillFieldMap()
|
||||
|
||||
return e
|
||||
}
|
||||
|
||||
func (e *envGroup) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
|
||||
_f, ok := e.fieldMap[fieldName]
|
||||
if !ok || _f == nil {
|
||||
return nil, false
|
||||
}
|
||||
_oe, ok := _f.(field.OrderExpr)
|
||||
return _oe, ok
|
||||
}
|
||||
|
||||
func (e *envGroup) fillFieldMap() {
|
||||
e.fieldMap = make(map[string]field.Expr, 7)
|
||||
e.fieldMap["id"] = e.ID
|
||||
e.fieldMap["created_at"] = e.CreatedAt
|
||||
e.fieldMap["updated_at"] = e.UpdatedAt
|
||||
e.fieldMap["deleted_at"] = e.DeletedAt
|
||||
e.fieldMap["name"] = e.Name
|
||||
e.fieldMap["sync_node_ids"] = e.SyncNodeIds
|
||||
e.fieldMap["order_id"] = e.OrderID
|
||||
}
|
||||
|
||||
func (e envGroup) clone(db *gorm.DB) envGroup {
|
||||
e.envGroupDo.ReplaceConnPool(db.Statement.ConnPool)
|
||||
return e
|
||||
}
|
||||
|
||||
func (e envGroup) replaceDB(db *gorm.DB) envGroup {
|
||||
e.envGroupDo.ReplaceDB(db)
|
||||
return e
|
||||
}
|
||||
|
||||
type envGroupDo struct{ gen.DO }
|
||||
|
||||
// FirstByID Where("id=@id")
|
||||
func (e envGroupDo) FirstByID(id uint64) (result *model.EnvGroup, err error) {
|
||||
var params []interface{}
|
||||
|
||||
var generateSQL strings.Builder
|
||||
params = append(params, id)
|
||||
generateSQL.WriteString("id=? ")
|
||||
|
||||
var executeSQL *gorm.DB
|
||||
executeSQL = e.UnderlyingDB().Where(generateSQL.String(), params...).Take(&result) // ignore_security_alert
|
||||
err = executeSQL.Error
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// DeleteByID update @@table set deleted_at=strftime('%Y-%m-%d %H:%M:%S','now') where id=@id
|
||||
func (e envGroupDo) DeleteByID(id uint64) (err error) {
|
||||
var params []interface{}
|
||||
|
||||
var generateSQL strings.Builder
|
||||
params = append(params, id)
|
||||
generateSQL.WriteString("update env_groups set deleted_at=strftime('%Y-%m-%d %H:%M:%S','now') where id=? ")
|
||||
|
||||
var executeSQL *gorm.DB
|
||||
executeSQL = e.UnderlyingDB().Exec(generateSQL.String(), params...) // ignore_security_alert
|
||||
err = executeSQL.Error
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (e envGroupDo) Debug() *envGroupDo {
|
||||
return e.withDO(e.DO.Debug())
|
||||
}
|
||||
|
||||
func (e envGroupDo) WithContext(ctx context.Context) *envGroupDo {
|
||||
return e.withDO(e.DO.WithContext(ctx))
|
||||
}
|
||||
|
||||
func (e envGroupDo) ReadDB() *envGroupDo {
|
||||
return e.Clauses(dbresolver.Read)
|
||||
}
|
||||
|
||||
func (e envGroupDo) WriteDB() *envGroupDo {
|
||||
return e.Clauses(dbresolver.Write)
|
||||
}
|
||||
|
||||
func (e envGroupDo) Session(config *gorm.Session) *envGroupDo {
|
||||
return e.withDO(e.DO.Session(config))
|
||||
}
|
||||
|
||||
func (e envGroupDo) Clauses(conds ...clause.Expression) *envGroupDo {
|
||||
return e.withDO(e.DO.Clauses(conds...))
|
||||
}
|
||||
|
||||
func (e envGroupDo) Returning(value interface{}, columns ...string) *envGroupDo {
|
||||
return e.withDO(e.DO.Returning(value, columns...))
|
||||
}
|
||||
|
||||
func (e envGroupDo) Not(conds ...gen.Condition) *envGroupDo {
|
||||
return e.withDO(e.DO.Not(conds...))
|
||||
}
|
||||
|
||||
func (e envGroupDo) Or(conds ...gen.Condition) *envGroupDo {
|
||||
return e.withDO(e.DO.Or(conds...))
|
||||
}
|
||||
|
||||
func (e envGroupDo) Select(conds ...field.Expr) *envGroupDo {
|
||||
return e.withDO(e.DO.Select(conds...))
|
||||
}
|
||||
|
||||
func (e envGroupDo) Where(conds ...gen.Condition) *envGroupDo {
|
||||
return e.withDO(e.DO.Where(conds...))
|
||||
}
|
||||
|
||||
func (e envGroupDo) Order(conds ...field.Expr) *envGroupDo {
|
||||
return e.withDO(e.DO.Order(conds...))
|
||||
}
|
||||
|
||||
func (e envGroupDo) Distinct(cols ...field.Expr) *envGroupDo {
|
||||
return e.withDO(e.DO.Distinct(cols...))
|
||||
}
|
||||
|
||||
func (e envGroupDo) Omit(cols ...field.Expr) *envGroupDo {
|
||||
return e.withDO(e.DO.Omit(cols...))
|
||||
}
|
||||
|
||||
func (e envGroupDo) Join(table schema.Tabler, on ...field.Expr) *envGroupDo {
|
||||
return e.withDO(e.DO.Join(table, on...))
|
||||
}
|
||||
|
||||
func (e envGroupDo) LeftJoin(table schema.Tabler, on ...field.Expr) *envGroupDo {
|
||||
return e.withDO(e.DO.LeftJoin(table, on...))
|
||||
}
|
||||
|
||||
func (e envGroupDo) RightJoin(table schema.Tabler, on ...field.Expr) *envGroupDo {
|
||||
return e.withDO(e.DO.RightJoin(table, on...))
|
||||
}
|
||||
|
||||
func (e envGroupDo) Group(cols ...field.Expr) *envGroupDo {
|
||||
return e.withDO(e.DO.Group(cols...))
|
||||
}
|
||||
|
||||
func (e envGroupDo) Having(conds ...gen.Condition) *envGroupDo {
|
||||
return e.withDO(e.DO.Having(conds...))
|
||||
}
|
||||
|
||||
func (e envGroupDo) Limit(limit int) *envGroupDo {
|
||||
return e.withDO(e.DO.Limit(limit))
|
||||
}
|
||||
|
||||
func (e envGroupDo) Offset(offset int) *envGroupDo {
|
||||
return e.withDO(e.DO.Offset(offset))
|
||||
}
|
||||
|
||||
func (e envGroupDo) Scopes(funcs ...func(gen.Dao) gen.Dao) *envGroupDo {
|
||||
return e.withDO(e.DO.Scopes(funcs...))
|
||||
}
|
||||
|
||||
func (e envGroupDo) Unscoped() *envGroupDo {
|
||||
return e.withDO(e.DO.Unscoped())
|
||||
}
|
||||
|
||||
func (e envGroupDo) Create(values ...*model.EnvGroup) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return e.DO.Create(values)
|
||||
}
|
||||
|
||||
func (e envGroupDo) CreateInBatches(values []*model.EnvGroup, batchSize int) error {
|
||||
return e.DO.CreateInBatches(values, batchSize)
|
||||
}
|
||||
|
||||
// Save : !!! underlying implementation is different with GORM
|
||||
// The method is equivalent to executing the statement: db.Clauses(clause.OnConflict{UpdateAll: true}).Create(values)
|
||||
func (e envGroupDo) Save(values ...*model.EnvGroup) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return e.DO.Save(values)
|
||||
}
|
||||
|
||||
func (e envGroupDo) First() (*model.EnvGroup, error) {
|
||||
if result, err := e.DO.First(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.EnvGroup), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (e envGroupDo) Take() (*model.EnvGroup, error) {
|
||||
if result, err := e.DO.Take(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.EnvGroup), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (e envGroupDo) Last() (*model.EnvGroup, error) {
|
||||
if result, err := e.DO.Last(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.EnvGroup), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (e envGroupDo) Find() ([]*model.EnvGroup, error) {
|
||||
result, err := e.DO.Find()
|
||||
return result.([]*model.EnvGroup), err
|
||||
}
|
||||
|
||||
func (e envGroupDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.EnvGroup, err error) {
|
||||
buf := make([]*model.EnvGroup, 0, batchSize)
|
||||
err = e.DO.FindInBatches(&buf, batchSize, func(tx gen.Dao, batch int) error {
|
||||
defer func() { results = append(results, buf...) }()
|
||||
return fc(tx, batch)
|
||||
})
|
||||
return results, err
|
||||
}
|
||||
|
||||
func (e envGroupDo) FindInBatches(result *[]*model.EnvGroup, batchSize int, fc func(tx gen.Dao, batch int) error) error {
|
||||
return e.DO.FindInBatches(result, batchSize, fc)
|
||||
}
|
||||
|
||||
func (e envGroupDo) Attrs(attrs ...field.AssignExpr) *envGroupDo {
|
||||
return e.withDO(e.DO.Attrs(attrs...))
|
||||
}
|
||||
|
||||
func (e envGroupDo) Assign(attrs ...field.AssignExpr) *envGroupDo {
|
||||
return e.withDO(e.DO.Assign(attrs...))
|
||||
}
|
||||
|
||||
func (e envGroupDo) Joins(fields ...field.RelationField) *envGroupDo {
|
||||
for _, _f := range fields {
|
||||
e = *e.withDO(e.DO.Joins(_f))
|
||||
}
|
||||
return &e
|
||||
}
|
||||
|
||||
func (e envGroupDo) Preload(fields ...field.RelationField) *envGroupDo {
|
||||
for _, _f := range fields {
|
||||
e = *e.withDO(e.DO.Preload(_f))
|
||||
}
|
||||
return &e
|
||||
}
|
||||
|
||||
func (e envGroupDo) FirstOrInit() (*model.EnvGroup, error) {
|
||||
if result, err := e.DO.FirstOrInit(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.EnvGroup), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (e envGroupDo) FirstOrCreate() (*model.EnvGroup, error) {
|
||||
if result, err := e.DO.FirstOrCreate(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.EnvGroup), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (e envGroupDo) FindByPage(offset int, limit int) (result []*model.EnvGroup, count int64, err error) {
|
||||
result, err = e.Offset(offset).Limit(limit).Find()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if size := len(result); 0 < limit && 0 < size && size < limit {
|
||||
count = int64(size + offset)
|
||||
return
|
||||
}
|
||||
|
||||
count, err = e.Offset(-1).Limit(-1).Count()
|
||||
return
|
||||
}
|
||||
|
||||
func (e envGroupDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) {
|
||||
count, err = e.Count()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = e.Offset(offset).Limit(limit).Scan(result)
|
||||
return
|
||||
}
|
||||
|
||||
func (e envGroupDo) Scan(result interface{}) (err error) {
|
||||
return e.DO.Scan(result)
|
||||
}
|
||||
|
||||
func (e envGroupDo) Delete(models ...*model.EnvGroup) (result gen.ResultInfo, err error) {
|
||||
return e.DO.Delete(models)
|
||||
}
|
||||
|
||||
func (e *envGroupDo) withDO(do gen.Dao) *envGroupDo {
|
||||
e.DO = *do.(*gen.DO)
|
||||
return e
|
||||
}
|
16
query/gen.go
16
query/gen.go
|
@ -25,11 +25,11 @@ var (
|
|||
Config *config
|
||||
ConfigBackup *configBackup
|
||||
DnsCredential *dnsCredential
|
||||
EnvGroup *envGroup
|
||||
Environment *environment
|
||||
Notification *notification
|
||||
Passkey *passkey
|
||||
Site *site
|
||||
SiteCategory *siteCategory
|
||||
Stream *stream
|
||||
User *user
|
||||
)
|
||||
|
@ -44,11 +44,11 @@ func SetDefault(db *gorm.DB, opts ...gen.DOOption) {
|
|||
Config = &Q.Config
|
||||
ConfigBackup = &Q.ConfigBackup
|
||||
DnsCredential = &Q.DnsCredential
|
||||
EnvGroup = &Q.EnvGroup
|
||||
Environment = &Q.Environment
|
||||
Notification = &Q.Notification
|
||||
Passkey = &Q.Passkey
|
||||
Site = &Q.Site
|
||||
SiteCategory = &Q.SiteCategory
|
||||
Stream = &Q.Stream
|
||||
User = &Q.User
|
||||
}
|
||||
|
@ -64,11 +64,11 @@ func Use(db *gorm.DB, opts ...gen.DOOption) *Query {
|
|||
Config: newConfig(db, opts...),
|
||||
ConfigBackup: newConfigBackup(db, opts...),
|
||||
DnsCredential: newDnsCredential(db, opts...),
|
||||
EnvGroup: newEnvGroup(db, opts...),
|
||||
Environment: newEnvironment(db, opts...),
|
||||
Notification: newNotification(db, opts...),
|
||||
Passkey: newPasskey(db, opts...),
|
||||
Site: newSite(db, opts...),
|
||||
SiteCategory: newSiteCategory(db, opts...),
|
||||
Stream: newStream(db, opts...),
|
||||
User: newUser(db, opts...),
|
||||
}
|
||||
|
@ -85,11 +85,11 @@ type Query struct {
|
|||
Config config
|
||||
ConfigBackup configBackup
|
||||
DnsCredential dnsCredential
|
||||
EnvGroup envGroup
|
||||
Environment environment
|
||||
Notification notification
|
||||
Passkey passkey
|
||||
Site site
|
||||
SiteCategory siteCategory
|
||||
Stream stream
|
||||
User user
|
||||
}
|
||||
|
@ -107,11 +107,11 @@ func (q *Query) clone(db *gorm.DB) *Query {
|
|||
Config: q.Config.clone(db),
|
||||
ConfigBackup: q.ConfigBackup.clone(db),
|
||||
DnsCredential: q.DnsCredential.clone(db),
|
||||
EnvGroup: q.EnvGroup.clone(db),
|
||||
Environment: q.Environment.clone(db),
|
||||
Notification: q.Notification.clone(db),
|
||||
Passkey: q.Passkey.clone(db),
|
||||
Site: q.Site.clone(db),
|
||||
SiteCategory: q.SiteCategory.clone(db),
|
||||
Stream: q.Stream.clone(db),
|
||||
User: q.User.clone(db),
|
||||
}
|
||||
|
@ -136,11 +136,11 @@ func (q *Query) ReplaceDB(db *gorm.DB) *Query {
|
|||
Config: q.Config.replaceDB(db),
|
||||
ConfigBackup: q.ConfigBackup.replaceDB(db),
|
||||
DnsCredential: q.DnsCredential.replaceDB(db),
|
||||
EnvGroup: q.EnvGroup.replaceDB(db),
|
||||
Environment: q.Environment.replaceDB(db),
|
||||
Notification: q.Notification.replaceDB(db),
|
||||
Passkey: q.Passkey.replaceDB(db),
|
||||
Site: q.Site.replaceDB(db),
|
||||
SiteCategory: q.SiteCategory.replaceDB(db),
|
||||
Stream: q.Stream.replaceDB(db),
|
||||
User: q.User.replaceDB(db),
|
||||
}
|
||||
|
@ -155,11 +155,11 @@ type queryCtx struct {
|
|||
Config *configDo
|
||||
ConfigBackup *configBackupDo
|
||||
DnsCredential *dnsCredentialDo
|
||||
EnvGroup *envGroupDo
|
||||
Environment *environmentDo
|
||||
Notification *notificationDo
|
||||
Passkey *passkeyDo
|
||||
Site *siteDo
|
||||
SiteCategory *siteCategoryDo
|
||||
Stream *streamDo
|
||||
User *userDo
|
||||
}
|
||||
|
@ -174,11 +174,11 @@ func (q *Query) WithContext(ctx context.Context) *queryCtx {
|
|||
Config: q.Config.WithContext(ctx),
|
||||
ConfigBackup: q.ConfigBackup.WithContext(ctx),
|
||||
DnsCredential: q.DnsCredential.WithContext(ctx),
|
||||
EnvGroup: q.EnvGroup.WithContext(ctx),
|
||||
Environment: q.Environment.WithContext(ctx),
|
||||
Notification: q.Notification.WithContext(ctx),
|
||||
Passkey: q.Passkey.WithContext(ctx),
|
||||
Site: q.Site.WithContext(ctx),
|
||||
SiteCategory: q.SiteCategory.WithContext(ctx),
|
||||
Stream: q.Stream.WithContext(ctx),
|
||||
User: q.User.WithContext(ctx),
|
||||
}
|
||||
|
|
|
@ -1,374 +0,0 @@
|
|||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
// Code generated by gorm.io/gen. DO NOT EDIT.
|
||||
|
||||
package query
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/clause"
|
||||
"gorm.io/gorm/schema"
|
||||
|
||||
"gorm.io/gen"
|
||||
"gorm.io/gen/field"
|
||||
|
||||
"gorm.io/plugin/dbresolver"
|
||||
|
||||
"github.com/0xJacky/Nginx-UI/model"
|
||||
)
|
||||
|
||||
func newSiteCategory(db *gorm.DB, opts ...gen.DOOption) siteCategory {
|
||||
_siteCategory := siteCategory{}
|
||||
|
||||
_siteCategory.siteCategoryDo.UseDB(db, opts...)
|
||||
_siteCategory.siteCategoryDo.UseModel(&model.SiteCategory{})
|
||||
|
||||
tableName := _siteCategory.siteCategoryDo.TableName()
|
||||
_siteCategory.ALL = field.NewAsterisk(tableName)
|
||||
_siteCategory.ID = field.NewUint64(tableName, "id")
|
||||
_siteCategory.CreatedAt = field.NewTime(tableName, "created_at")
|
||||
_siteCategory.UpdatedAt = field.NewTime(tableName, "updated_at")
|
||||
_siteCategory.DeletedAt = field.NewField(tableName, "deleted_at")
|
||||
_siteCategory.Name = field.NewString(tableName, "name")
|
||||
_siteCategory.SyncNodeIds = field.NewField(tableName, "sync_node_ids")
|
||||
_siteCategory.OrderID = field.NewInt(tableName, "order_id")
|
||||
|
||||
_siteCategory.fillFieldMap()
|
||||
|
||||
return _siteCategory
|
||||
}
|
||||
|
||||
type siteCategory struct {
|
||||
siteCategoryDo
|
||||
|
||||
ALL field.Asterisk
|
||||
ID field.Uint64
|
||||
CreatedAt field.Time
|
||||
UpdatedAt field.Time
|
||||
DeletedAt field.Field
|
||||
Name field.String
|
||||
SyncNodeIds field.Field
|
||||
OrderID field.Int
|
||||
|
||||
fieldMap map[string]field.Expr
|
||||
}
|
||||
|
||||
func (s siteCategory) Table(newTableName string) *siteCategory {
|
||||
s.siteCategoryDo.UseTable(newTableName)
|
||||
return s.updateTableName(newTableName)
|
||||
}
|
||||
|
||||
func (s siteCategory) As(alias string) *siteCategory {
|
||||
s.siteCategoryDo.DO = *(s.siteCategoryDo.As(alias).(*gen.DO))
|
||||
return s.updateTableName(alias)
|
||||
}
|
||||
|
||||
func (s *siteCategory) updateTableName(table string) *siteCategory {
|
||||
s.ALL = field.NewAsterisk(table)
|
||||
s.ID = field.NewUint64(table, "id")
|
||||
s.CreatedAt = field.NewTime(table, "created_at")
|
||||
s.UpdatedAt = field.NewTime(table, "updated_at")
|
||||
s.DeletedAt = field.NewField(table, "deleted_at")
|
||||
s.Name = field.NewString(table, "name")
|
||||
s.SyncNodeIds = field.NewField(table, "sync_node_ids")
|
||||
s.OrderID = field.NewInt(table, "order_id")
|
||||
|
||||
s.fillFieldMap()
|
||||
|
||||
return s
|
||||
}
|
||||
|
||||
func (s *siteCategory) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
|
||||
_f, ok := s.fieldMap[fieldName]
|
||||
if !ok || _f == nil {
|
||||
return nil, false
|
||||
}
|
||||
_oe, ok := _f.(field.OrderExpr)
|
||||
return _oe, ok
|
||||
}
|
||||
|
||||
func (s *siteCategory) fillFieldMap() {
|
||||
s.fieldMap = make(map[string]field.Expr, 7)
|
||||
s.fieldMap["id"] = s.ID
|
||||
s.fieldMap["created_at"] = s.CreatedAt
|
||||
s.fieldMap["updated_at"] = s.UpdatedAt
|
||||
s.fieldMap["deleted_at"] = s.DeletedAt
|
||||
s.fieldMap["name"] = s.Name
|
||||
s.fieldMap["sync_node_ids"] = s.SyncNodeIds
|
||||
s.fieldMap["order_id"] = s.OrderID
|
||||
}
|
||||
|
||||
func (s siteCategory) clone(db *gorm.DB) siteCategory {
|
||||
s.siteCategoryDo.ReplaceConnPool(db.Statement.ConnPool)
|
||||
return s
|
||||
}
|
||||
|
||||
func (s siteCategory) replaceDB(db *gorm.DB) siteCategory {
|
||||
s.siteCategoryDo.ReplaceDB(db)
|
||||
return s
|
||||
}
|
||||
|
||||
type siteCategoryDo struct{ gen.DO }
|
||||
|
||||
// FirstByID Where("id=@id")
|
||||
func (s siteCategoryDo) FirstByID(id uint64) (result *model.SiteCategory, err error) {
|
||||
var params []interface{}
|
||||
|
||||
var generateSQL strings.Builder
|
||||
params = append(params, id)
|
||||
generateSQL.WriteString("id=? ")
|
||||
|
||||
var executeSQL *gorm.DB
|
||||
executeSQL = s.UnderlyingDB().Where(generateSQL.String(), params...).Take(&result) // ignore_security_alert
|
||||
err = executeSQL.Error
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// DeleteByID update @@table set deleted_at=strftime('%Y-%m-%d %H:%M:%S','now') where id=@id
|
||||
func (s siteCategoryDo) DeleteByID(id uint64) (err error) {
|
||||
var params []interface{}
|
||||
|
||||
var generateSQL strings.Builder
|
||||
params = append(params, id)
|
||||
generateSQL.WriteString("update site_categories set deleted_at=strftime('%Y-%m-%d %H:%M:%S','now') where id=? ")
|
||||
|
||||
var executeSQL *gorm.DB
|
||||
executeSQL = s.UnderlyingDB().Exec(generateSQL.String(), params...) // ignore_security_alert
|
||||
err = executeSQL.Error
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (s siteCategoryDo) Debug() *siteCategoryDo {
|
||||
return s.withDO(s.DO.Debug())
|
||||
}
|
||||
|
||||
func (s siteCategoryDo) WithContext(ctx context.Context) *siteCategoryDo {
|
||||
return s.withDO(s.DO.WithContext(ctx))
|
||||
}
|
||||
|
||||
func (s siteCategoryDo) ReadDB() *siteCategoryDo {
|
||||
return s.Clauses(dbresolver.Read)
|
||||
}
|
||||
|
||||
func (s siteCategoryDo) WriteDB() *siteCategoryDo {
|
||||
return s.Clauses(dbresolver.Write)
|
||||
}
|
||||
|
||||
func (s siteCategoryDo) Session(config *gorm.Session) *siteCategoryDo {
|
||||
return s.withDO(s.DO.Session(config))
|
||||
}
|
||||
|
||||
func (s siteCategoryDo) Clauses(conds ...clause.Expression) *siteCategoryDo {
|
||||
return s.withDO(s.DO.Clauses(conds...))
|
||||
}
|
||||
|
||||
func (s siteCategoryDo) Returning(value interface{}, columns ...string) *siteCategoryDo {
|
||||
return s.withDO(s.DO.Returning(value, columns...))
|
||||
}
|
||||
|
||||
func (s siteCategoryDo) Not(conds ...gen.Condition) *siteCategoryDo {
|
||||
return s.withDO(s.DO.Not(conds...))
|
||||
}
|
||||
|
||||
func (s siteCategoryDo) Or(conds ...gen.Condition) *siteCategoryDo {
|
||||
return s.withDO(s.DO.Or(conds...))
|
||||
}
|
||||
|
||||
func (s siteCategoryDo) Select(conds ...field.Expr) *siteCategoryDo {
|
||||
return s.withDO(s.DO.Select(conds...))
|
||||
}
|
||||
|
||||
func (s siteCategoryDo) Where(conds ...gen.Condition) *siteCategoryDo {
|
||||
return s.withDO(s.DO.Where(conds...))
|
||||
}
|
||||
|
||||
func (s siteCategoryDo) Order(conds ...field.Expr) *siteCategoryDo {
|
||||
return s.withDO(s.DO.Order(conds...))
|
||||
}
|
||||
|
||||
func (s siteCategoryDo) Distinct(cols ...field.Expr) *siteCategoryDo {
|
||||
return s.withDO(s.DO.Distinct(cols...))
|
||||
}
|
||||
|
||||
func (s siteCategoryDo) Omit(cols ...field.Expr) *siteCategoryDo {
|
||||
return s.withDO(s.DO.Omit(cols...))
|
||||
}
|
||||
|
||||
func (s siteCategoryDo) Join(table schema.Tabler, on ...field.Expr) *siteCategoryDo {
|
||||
return s.withDO(s.DO.Join(table, on...))
|
||||
}
|
||||
|
||||
func (s siteCategoryDo) LeftJoin(table schema.Tabler, on ...field.Expr) *siteCategoryDo {
|
||||
return s.withDO(s.DO.LeftJoin(table, on...))
|
||||
}
|
||||
|
||||
func (s siteCategoryDo) RightJoin(table schema.Tabler, on ...field.Expr) *siteCategoryDo {
|
||||
return s.withDO(s.DO.RightJoin(table, on...))
|
||||
}
|
||||
|
||||
func (s siteCategoryDo) Group(cols ...field.Expr) *siteCategoryDo {
|
||||
return s.withDO(s.DO.Group(cols...))
|
||||
}
|
||||
|
||||
func (s siteCategoryDo) Having(conds ...gen.Condition) *siteCategoryDo {
|
||||
return s.withDO(s.DO.Having(conds...))
|
||||
}
|
||||
|
||||
func (s siteCategoryDo) Limit(limit int) *siteCategoryDo {
|
||||
return s.withDO(s.DO.Limit(limit))
|
||||
}
|
||||
|
||||
func (s siteCategoryDo) Offset(offset int) *siteCategoryDo {
|
||||
return s.withDO(s.DO.Offset(offset))
|
||||
}
|
||||
|
||||
func (s siteCategoryDo) Scopes(funcs ...func(gen.Dao) gen.Dao) *siteCategoryDo {
|
||||
return s.withDO(s.DO.Scopes(funcs...))
|
||||
}
|
||||
|
||||
func (s siteCategoryDo) Unscoped() *siteCategoryDo {
|
||||
return s.withDO(s.DO.Unscoped())
|
||||
}
|
||||
|
||||
func (s siteCategoryDo) Create(values ...*model.SiteCategory) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return s.DO.Create(values)
|
||||
}
|
||||
|
||||
func (s siteCategoryDo) CreateInBatches(values []*model.SiteCategory, batchSize int) error {
|
||||
return s.DO.CreateInBatches(values, batchSize)
|
||||
}
|
||||
|
||||
// Save : !!! underlying implementation is different with GORM
|
||||
// The method is equivalent to executing the statement: db.Clauses(clause.OnConflict{UpdateAll: true}).Create(values)
|
||||
func (s siteCategoryDo) Save(values ...*model.SiteCategory) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return s.DO.Save(values)
|
||||
}
|
||||
|
||||
func (s siteCategoryDo) First() (*model.SiteCategory, error) {
|
||||
if result, err := s.DO.First(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.SiteCategory), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (s siteCategoryDo) Take() (*model.SiteCategory, error) {
|
||||
if result, err := s.DO.Take(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.SiteCategory), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (s siteCategoryDo) Last() (*model.SiteCategory, error) {
|
||||
if result, err := s.DO.Last(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.SiteCategory), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (s siteCategoryDo) Find() ([]*model.SiteCategory, error) {
|
||||
result, err := s.DO.Find()
|
||||
return result.([]*model.SiteCategory), err
|
||||
}
|
||||
|
||||
func (s siteCategoryDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.SiteCategory, err error) {
|
||||
buf := make([]*model.SiteCategory, 0, batchSize)
|
||||
err = s.DO.FindInBatches(&buf, batchSize, func(tx gen.Dao, batch int) error {
|
||||
defer func() { results = append(results, buf...) }()
|
||||
return fc(tx, batch)
|
||||
})
|
||||
return results, err
|
||||
}
|
||||
|
||||
func (s siteCategoryDo) FindInBatches(result *[]*model.SiteCategory, batchSize int, fc func(tx gen.Dao, batch int) error) error {
|
||||
return s.DO.FindInBatches(result, batchSize, fc)
|
||||
}
|
||||
|
||||
func (s siteCategoryDo) Attrs(attrs ...field.AssignExpr) *siteCategoryDo {
|
||||
return s.withDO(s.DO.Attrs(attrs...))
|
||||
}
|
||||
|
||||
func (s siteCategoryDo) Assign(attrs ...field.AssignExpr) *siteCategoryDo {
|
||||
return s.withDO(s.DO.Assign(attrs...))
|
||||
}
|
||||
|
||||
func (s siteCategoryDo) Joins(fields ...field.RelationField) *siteCategoryDo {
|
||||
for _, _f := range fields {
|
||||
s = *s.withDO(s.DO.Joins(_f))
|
||||
}
|
||||
return &s
|
||||
}
|
||||
|
||||
func (s siteCategoryDo) Preload(fields ...field.RelationField) *siteCategoryDo {
|
||||
for _, _f := range fields {
|
||||
s = *s.withDO(s.DO.Preload(_f))
|
||||
}
|
||||
return &s
|
||||
}
|
||||
|
||||
func (s siteCategoryDo) FirstOrInit() (*model.SiteCategory, error) {
|
||||
if result, err := s.DO.FirstOrInit(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.SiteCategory), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (s siteCategoryDo) FirstOrCreate() (*model.SiteCategory, error) {
|
||||
if result, err := s.DO.FirstOrCreate(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*model.SiteCategory), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (s siteCategoryDo) FindByPage(offset int, limit int) (result []*model.SiteCategory, count int64, err error) {
|
||||
result, err = s.Offset(offset).Limit(limit).Find()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if size := len(result); 0 < limit && 0 < size && size < limit {
|
||||
count = int64(size + offset)
|
||||
return
|
||||
}
|
||||
|
||||
count, err = s.Offset(-1).Limit(-1).Count()
|
||||
return
|
||||
}
|
||||
|
||||
func (s siteCategoryDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) {
|
||||
count, err = s.Count()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = s.Offset(offset).Limit(limit).Scan(result)
|
||||
return
|
||||
}
|
||||
|
||||
func (s siteCategoryDo) Scan(result interface{}) (err error) {
|
||||
return s.DO.Scan(result)
|
||||
}
|
||||
|
||||
func (s siteCategoryDo) Delete(models ...*model.SiteCategory) (result gen.ResultInfo, err error) {
|
||||
return s.DO.Delete(models)
|
||||
}
|
||||
|
||||
func (s *siteCategoryDo) withDO(do gen.Dao) *siteCategoryDo {
|
||||
s.DO = *do.(*gen.DO)
|
||||
return s
|
||||
}
|
|
@ -34,12 +34,12 @@ func newSite(db *gorm.DB, opts ...gen.DOOption) site {
|
|||
_site.DeletedAt = field.NewField(tableName, "deleted_at")
|
||||
_site.Path = field.NewString(tableName, "path")
|
||||
_site.Advanced = field.NewBool(tableName, "advanced")
|
||||
_site.SiteCategoryID = field.NewUint64(tableName, "site_category_id")
|
||||
_site.EnvGroupID = field.NewUint64(tableName, "env_group_id")
|
||||
_site.SyncNodeIDs = field.NewField(tableName, "sync_node_ids")
|
||||
_site.SiteCategory = siteBelongsToSiteCategory{
|
||||
_site.EnvGroup = siteBelongsToEnvGroup{
|
||||
db: db.Session(&gorm.Session{}),
|
||||
|
||||
RelationField: field.NewRelation("SiteCategory", "model.SiteCategory"),
|
||||
RelationField: field.NewRelation("EnvGroup", "model.EnvGroup"),
|
||||
}
|
||||
|
||||
_site.fillFieldMap()
|
||||
|
@ -50,16 +50,16 @@ func newSite(db *gorm.DB, opts ...gen.DOOption) site {
|
|||
type site struct {
|
||||
siteDo
|
||||
|
||||
ALL field.Asterisk
|
||||
ID field.Uint64
|
||||
CreatedAt field.Time
|
||||
UpdatedAt field.Time
|
||||
DeletedAt field.Field
|
||||
Path field.String
|
||||
Advanced field.Bool
|
||||
SiteCategoryID field.Uint64
|
||||
SyncNodeIDs field.Field
|
||||
SiteCategory siteBelongsToSiteCategory
|
||||
ALL field.Asterisk
|
||||
ID field.Uint64
|
||||
CreatedAt field.Time
|
||||
UpdatedAt field.Time
|
||||
DeletedAt field.Field
|
||||
Path field.String
|
||||
Advanced field.Bool
|
||||
EnvGroupID field.Uint64
|
||||
SyncNodeIDs field.Field
|
||||
EnvGroup siteBelongsToEnvGroup
|
||||
|
||||
fieldMap map[string]field.Expr
|
||||
}
|
||||
|
@ -82,7 +82,7 @@ func (s *site) updateTableName(table string) *site {
|
|||
s.DeletedAt = field.NewField(table, "deleted_at")
|
||||
s.Path = field.NewString(table, "path")
|
||||
s.Advanced = field.NewBool(table, "advanced")
|
||||
s.SiteCategoryID = field.NewUint64(table, "site_category_id")
|
||||
s.EnvGroupID = field.NewUint64(table, "env_group_id")
|
||||
s.SyncNodeIDs = field.NewField(table, "sync_node_ids")
|
||||
|
||||
s.fillFieldMap()
|
||||
|
@ -107,7 +107,7 @@ func (s *site) fillFieldMap() {
|
|||
s.fieldMap["deleted_at"] = s.DeletedAt
|
||||
s.fieldMap["path"] = s.Path
|
||||
s.fieldMap["advanced"] = s.Advanced
|
||||
s.fieldMap["site_category_id"] = s.SiteCategoryID
|
||||
s.fieldMap["env_group_id"] = s.EnvGroupID
|
||||
s.fieldMap["sync_node_ids"] = s.SyncNodeIDs
|
||||
|
||||
}
|
||||
|
@ -122,13 +122,13 @@ func (s site) replaceDB(db *gorm.DB) site {
|
|||
return s
|
||||
}
|
||||
|
||||
type siteBelongsToSiteCategory struct {
|
||||
type siteBelongsToEnvGroup struct {
|
||||
db *gorm.DB
|
||||
|
||||
field.RelationField
|
||||
}
|
||||
|
||||
func (a siteBelongsToSiteCategory) Where(conds ...field.Expr) *siteBelongsToSiteCategory {
|
||||
func (a siteBelongsToEnvGroup) Where(conds ...field.Expr) *siteBelongsToEnvGroup {
|
||||
if len(conds) == 0 {
|
||||
return &a
|
||||
}
|
||||
|
@ -141,27 +141,27 @@ func (a siteBelongsToSiteCategory) Where(conds ...field.Expr) *siteBelongsToSite
|
|||
return &a
|
||||
}
|
||||
|
||||
func (a siteBelongsToSiteCategory) WithContext(ctx context.Context) *siteBelongsToSiteCategory {
|
||||
func (a siteBelongsToEnvGroup) WithContext(ctx context.Context) *siteBelongsToEnvGroup {
|
||||
a.db = a.db.WithContext(ctx)
|
||||
return &a
|
||||
}
|
||||
|
||||
func (a siteBelongsToSiteCategory) Session(session *gorm.Session) *siteBelongsToSiteCategory {
|
||||
func (a siteBelongsToEnvGroup) Session(session *gorm.Session) *siteBelongsToEnvGroup {
|
||||
a.db = a.db.Session(session)
|
||||
return &a
|
||||
}
|
||||
|
||||
func (a siteBelongsToSiteCategory) Model(m *model.Site) *siteBelongsToSiteCategoryTx {
|
||||
return &siteBelongsToSiteCategoryTx{a.db.Model(m).Association(a.Name())}
|
||||
func (a siteBelongsToEnvGroup) Model(m *model.Site) *siteBelongsToEnvGroupTx {
|
||||
return &siteBelongsToEnvGroupTx{a.db.Model(m).Association(a.Name())}
|
||||
}
|
||||
|
||||
type siteBelongsToSiteCategoryTx struct{ tx *gorm.Association }
|
||||
type siteBelongsToEnvGroupTx struct{ tx *gorm.Association }
|
||||
|
||||
func (a siteBelongsToSiteCategoryTx) Find() (result *model.SiteCategory, err error) {
|
||||
func (a siteBelongsToEnvGroupTx) Find() (result *model.EnvGroup, err error) {
|
||||
return result, a.tx.Find(&result)
|
||||
}
|
||||
|
||||
func (a siteBelongsToSiteCategoryTx) Append(values ...*model.SiteCategory) (err error) {
|
||||
func (a siteBelongsToEnvGroupTx) Append(values ...*model.EnvGroup) (err error) {
|
||||
targetValues := make([]interface{}, len(values))
|
||||
for i, v := range values {
|
||||
targetValues[i] = v
|
||||
|
@ -169,7 +169,7 @@ func (a siteBelongsToSiteCategoryTx) Append(values ...*model.SiteCategory) (err
|
|||
return a.tx.Append(targetValues...)
|
||||
}
|
||||
|
||||
func (a siteBelongsToSiteCategoryTx) Replace(values ...*model.SiteCategory) (err error) {
|
||||
func (a siteBelongsToEnvGroupTx) Replace(values ...*model.EnvGroup) (err error) {
|
||||
targetValues := make([]interface{}, len(values))
|
||||
for i, v := range values {
|
||||
targetValues[i] = v
|
||||
|
@ -177,7 +177,7 @@ func (a siteBelongsToSiteCategoryTx) Replace(values ...*model.SiteCategory) (err
|
|||
return a.tx.Replace(targetValues...)
|
||||
}
|
||||
|
||||
func (a siteBelongsToSiteCategoryTx) Delete(values ...*model.SiteCategory) (err error) {
|
||||
func (a siteBelongsToEnvGroupTx) Delete(values ...*model.EnvGroup) (err error) {
|
||||
targetValues := make([]interface{}, len(values))
|
||||
for i, v := range values {
|
||||
targetValues[i] = v
|
||||
|
@ -185,11 +185,11 @@ func (a siteBelongsToSiteCategoryTx) Delete(values ...*model.SiteCategory) (err
|
|||
return a.tx.Delete(targetValues...)
|
||||
}
|
||||
|
||||
func (a siteBelongsToSiteCategoryTx) Clear() error {
|
||||
func (a siteBelongsToEnvGroupTx) Clear() error {
|
||||
return a.tx.Clear()
|
||||
}
|
||||
|
||||
func (a siteBelongsToSiteCategoryTx) Count() int64 {
|
||||
func (a siteBelongsToEnvGroupTx) Count() int64 {
|
||||
return a.tx.Count()
|
||||
}
|
||||
|
||||
|
|
|
@ -34,7 +34,13 @@ func newStream(db *gorm.DB, opts ...gen.DOOption) stream {
|
|||
_stream.DeletedAt = field.NewField(tableName, "deleted_at")
|
||||
_stream.Path = field.NewString(tableName, "path")
|
||||
_stream.Advanced = field.NewBool(tableName, "advanced")
|
||||
_stream.EnvGroupID = field.NewUint64(tableName, "env_group_id")
|
||||
_stream.SyncNodeIDs = field.NewField(tableName, "sync_node_ids")
|
||||
_stream.EnvGroup = streamBelongsToEnvGroup{
|
||||
db: db.Session(&gorm.Session{}),
|
||||
|
||||
RelationField: field.NewRelation("EnvGroup", "model.EnvGroup"),
|
||||
}
|
||||
|
||||
_stream.fillFieldMap()
|
||||
|
||||
|
@ -51,7 +57,9 @@ type stream struct {
|
|||
DeletedAt field.Field
|
||||
Path field.String
|
||||
Advanced field.Bool
|
||||
EnvGroupID field.Uint64
|
||||
SyncNodeIDs field.Field
|
||||
EnvGroup streamBelongsToEnvGroup
|
||||
|
||||
fieldMap map[string]field.Expr
|
||||
}
|
||||
|
@ -74,6 +82,7 @@ func (s *stream) updateTableName(table string) *stream {
|
|||
s.DeletedAt = field.NewField(table, "deleted_at")
|
||||
s.Path = field.NewString(table, "path")
|
||||
s.Advanced = field.NewBool(table, "advanced")
|
||||
s.EnvGroupID = field.NewUint64(table, "env_group_id")
|
||||
s.SyncNodeIDs = field.NewField(table, "sync_node_ids")
|
||||
|
||||
s.fillFieldMap()
|
||||
|
@ -91,14 +100,16 @@ func (s *stream) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
|
|||
}
|
||||
|
||||
func (s *stream) fillFieldMap() {
|
||||
s.fieldMap = make(map[string]field.Expr, 7)
|
||||
s.fieldMap = make(map[string]field.Expr, 9)
|
||||
s.fieldMap["id"] = s.ID
|
||||
s.fieldMap["created_at"] = s.CreatedAt
|
||||
s.fieldMap["updated_at"] = s.UpdatedAt
|
||||
s.fieldMap["deleted_at"] = s.DeletedAt
|
||||
s.fieldMap["path"] = s.Path
|
||||
s.fieldMap["advanced"] = s.Advanced
|
||||
s.fieldMap["env_group_id"] = s.EnvGroupID
|
||||
s.fieldMap["sync_node_ids"] = s.SyncNodeIDs
|
||||
|
||||
}
|
||||
|
||||
func (s stream) clone(db *gorm.DB) stream {
|
||||
|
@ -111,6 +122,77 @@ func (s stream) replaceDB(db *gorm.DB) stream {
|
|||
return s
|
||||
}
|
||||
|
||||
type streamBelongsToEnvGroup struct {
|
||||
db *gorm.DB
|
||||
|
||||
field.RelationField
|
||||
}
|
||||
|
||||
func (a streamBelongsToEnvGroup) Where(conds ...field.Expr) *streamBelongsToEnvGroup {
|
||||
if len(conds) == 0 {
|
||||
return &a
|
||||
}
|
||||
|
||||
exprs := make([]clause.Expression, 0, len(conds))
|
||||
for _, cond := range conds {
|
||||
exprs = append(exprs, cond.BeCond().(clause.Expression))
|
||||
}
|
||||
a.db = a.db.Clauses(clause.Where{Exprs: exprs})
|
||||
return &a
|
||||
}
|
||||
|
||||
func (a streamBelongsToEnvGroup) WithContext(ctx context.Context) *streamBelongsToEnvGroup {
|
||||
a.db = a.db.WithContext(ctx)
|
||||
return &a
|
||||
}
|
||||
|
||||
func (a streamBelongsToEnvGroup) Session(session *gorm.Session) *streamBelongsToEnvGroup {
|
||||
a.db = a.db.Session(session)
|
||||
return &a
|
||||
}
|
||||
|
||||
func (a streamBelongsToEnvGroup) Model(m *model.Stream) *streamBelongsToEnvGroupTx {
|
||||
return &streamBelongsToEnvGroupTx{a.db.Model(m).Association(a.Name())}
|
||||
}
|
||||
|
||||
type streamBelongsToEnvGroupTx struct{ tx *gorm.Association }
|
||||
|
||||
func (a streamBelongsToEnvGroupTx) Find() (result *model.EnvGroup, err error) {
|
||||
return result, a.tx.Find(&result)
|
||||
}
|
||||
|
||||
func (a streamBelongsToEnvGroupTx) Append(values ...*model.EnvGroup) (err error) {
|
||||
targetValues := make([]interface{}, len(values))
|
||||
for i, v := range values {
|
||||
targetValues[i] = v
|
||||
}
|
||||
return a.tx.Append(targetValues...)
|
||||
}
|
||||
|
||||
func (a streamBelongsToEnvGroupTx) Replace(values ...*model.EnvGroup) (err error) {
|
||||
targetValues := make([]interface{}, len(values))
|
||||
for i, v := range values {
|
||||
targetValues[i] = v
|
||||
}
|
||||
return a.tx.Replace(targetValues...)
|
||||
}
|
||||
|
||||
func (a streamBelongsToEnvGroupTx) Delete(values ...*model.EnvGroup) (err error) {
|
||||
targetValues := make([]interface{}, len(values))
|
||||
for i, v := range values {
|
||||
targetValues[i] = v
|
||||
}
|
||||
return a.tx.Delete(targetValues...)
|
||||
}
|
||||
|
||||
func (a streamBelongsToEnvGroupTx) Clear() error {
|
||||
return a.tx.Clear()
|
||||
}
|
||||
|
||||
func (a streamBelongsToEnvGroupTx) Count() int64 {
|
||||
return a.tx.Count()
|
||||
}
|
||||
|
||||
type streamDo struct{ gen.DO }
|
||||
|
||||
// FirstByID Where("id=@id")
|
||||
|
|
|
@ -142,7 +142,7 @@ func (u userDo) DeleteByID(id uint64) (err error) {
|
|||
|
||||
var generateSQL strings.Builder
|
||||
params = append(params, id)
|
||||
generateSQL.WriteString("update auths set deleted_at=strftime('%Y-%m-%d %H:%M:%S','now') where id=? ")
|
||||
generateSQL.WriteString("update users set deleted_at=strftime('%Y-%m-%d %H:%M:%S','now') where id=? ")
|
||||
|
||||
var executeSQL *gorm.DB
|
||||
executeSQL = u.UnderlyingDB().Exec(generateSQL.String(), params...) // ignore_security_alert
|
Loading…
Add table
Add a link
Reference in a new issue