472 lines
12 KiB
Go
472 lines
12 KiB
Go
// 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 queries
|
|
|
|
import (
|
|
"context"
|
|
|
|
"gorm.io/gorm"
|
|
"gorm.io/gorm/clause"
|
|
"gorm.io/gorm/schema"
|
|
|
|
"gorm.io/gen"
|
|
"gorm.io/gen/field"
|
|
|
|
"gorm.io/plugin/dbresolver"
|
|
|
|
"platform/web/models"
|
|
)
|
|
|
|
func newClient(db *gorm.DB, opts ...gen.DOOption) client {
|
|
_client := client{}
|
|
|
|
_client.clientDo.UseDB(db, opts...)
|
|
_client.clientDo.UseModel(&models.Client{})
|
|
|
|
tableName := _client.clientDo.TableName()
|
|
_client.ALL = field.NewAsterisk(tableName)
|
|
_client.ID = field.NewInt32(tableName, "id")
|
|
_client.CreatedAt = field.NewTime(tableName, "created_at")
|
|
_client.UpdatedAt = field.NewTime(tableName, "updated_at")
|
|
_client.DeletedAt = field.NewField(tableName, "deleted_at")
|
|
_client.ClientID = field.NewString(tableName, "client_id")
|
|
_client.ClientSecret = field.NewString(tableName, "client_secret")
|
|
_client.RedirectURI = field.NewString(tableName, "redirect_uri")
|
|
_client.Spec = field.NewInt(tableName, "spec")
|
|
_client.Name = field.NewString(tableName, "name")
|
|
_client.Icon = field.NewString(tableName, "icon")
|
|
_client.Status = field.NewInt(tableName, "status")
|
|
_client.Type = field.NewInt(tableName, "type")
|
|
_client.Permissions = clientManyToManyPermissions{
|
|
db: db.Session(&gorm.Session{}),
|
|
|
|
RelationField: field.NewRelation("Permissions", "models.Permission"),
|
|
Parent: struct {
|
|
field.RelationField
|
|
}{
|
|
RelationField: field.NewRelation("Permissions.Parent", "models.Permission"),
|
|
},
|
|
Children: struct {
|
|
field.RelationField
|
|
}{
|
|
RelationField: field.NewRelation("Permissions.Children", "models.Permission"),
|
|
},
|
|
}
|
|
|
|
_client.fillFieldMap()
|
|
|
|
return _client
|
|
}
|
|
|
|
type client struct {
|
|
clientDo
|
|
|
|
ALL field.Asterisk
|
|
ID field.Int32
|
|
CreatedAt field.Time
|
|
UpdatedAt field.Time
|
|
DeletedAt field.Field
|
|
ClientID field.String
|
|
ClientSecret field.String
|
|
RedirectURI field.String
|
|
Spec field.Int
|
|
Name field.String
|
|
Icon field.String
|
|
Status field.Int
|
|
Type field.Int
|
|
Permissions clientManyToManyPermissions
|
|
|
|
fieldMap map[string]field.Expr
|
|
}
|
|
|
|
func (c client) Table(newTableName string) *client {
|
|
c.clientDo.UseTable(newTableName)
|
|
return c.updateTableName(newTableName)
|
|
}
|
|
|
|
func (c client) As(alias string) *client {
|
|
c.clientDo.DO = *(c.clientDo.As(alias).(*gen.DO))
|
|
return c.updateTableName(alias)
|
|
}
|
|
|
|
func (c *client) updateTableName(table string) *client {
|
|
c.ALL = field.NewAsterisk(table)
|
|
c.ID = field.NewInt32(table, "id")
|
|
c.CreatedAt = field.NewTime(table, "created_at")
|
|
c.UpdatedAt = field.NewTime(table, "updated_at")
|
|
c.DeletedAt = field.NewField(table, "deleted_at")
|
|
c.ClientID = field.NewString(table, "client_id")
|
|
c.ClientSecret = field.NewString(table, "client_secret")
|
|
c.RedirectURI = field.NewString(table, "redirect_uri")
|
|
c.Spec = field.NewInt(table, "spec")
|
|
c.Name = field.NewString(table, "name")
|
|
c.Icon = field.NewString(table, "icon")
|
|
c.Status = field.NewInt(table, "status")
|
|
c.Type = field.NewInt(table, "type")
|
|
|
|
c.fillFieldMap()
|
|
|
|
return c
|
|
}
|
|
|
|
func (c *client) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
|
|
_f, ok := c.fieldMap[fieldName]
|
|
if !ok || _f == nil {
|
|
return nil, false
|
|
}
|
|
_oe, ok := _f.(field.OrderExpr)
|
|
return _oe, ok
|
|
}
|
|
|
|
func (c *client) fillFieldMap() {
|
|
c.fieldMap = make(map[string]field.Expr, 13)
|
|
c.fieldMap["id"] = c.ID
|
|
c.fieldMap["created_at"] = c.CreatedAt
|
|
c.fieldMap["updated_at"] = c.UpdatedAt
|
|
c.fieldMap["deleted_at"] = c.DeletedAt
|
|
c.fieldMap["client_id"] = c.ClientID
|
|
c.fieldMap["client_secret"] = c.ClientSecret
|
|
c.fieldMap["redirect_uri"] = c.RedirectURI
|
|
c.fieldMap["spec"] = c.Spec
|
|
c.fieldMap["name"] = c.Name
|
|
c.fieldMap["icon"] = c.Icon
|
|
c.fieldMap["status"] = c.Status
|
|
c.fieldMap["type"] = c.Type
|
|
|
|
}
|
|
|
|
func (c client) clone(db *gorm.DB) client {
|
|
c.clientDo.ReplaceConnPool(db.Statement.ConnPool)
|
|
c.Permissions.db = db.Session(&gorm.Session{Initialized: true})
|
|
c.Permissions.db.Statement.ConnPool = db.Statement.ConnPool
|
|
return c
|
|
}
|
|
|
|
func (c client) replaceDB(db *gorm.DB) client {
|
|
c.clientDo.ReplaceDB(db)
|
|
c.Permissions.db = db.Session(&gorm.Session{})
|
|
return c
|
|
}
|
|
|
|
type clientManyToManyPermissions struct {
|
|
db *gorm.DB
|
|
|
|
field.RelationField
|
|
|
|
Parent struct {
|
|
field.RelationField
|
|
}
|
|
Children struct {
|
|
field.RelationField
|
|
}
|
|
}
|
|
|
|
func (a clientManyToManyPermissions) Where(conds ...field.Expr) *clientManyToManyPermissions {
|
|
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 clientManyToManyPermissions) WithContext(ctx context.Context) *clientManyToManyPermissions {
|
|
a.db = a.db.WithContext(ctx)
|
|
return &a
|
|
}
|
|
|
|
func (a clientManyToManyPermissions) Session(session *gorm.Session) *clientManyToManyPermissions {
|
|
a.db = a.db.Session(session)
|
|
return &a
|
|
}
|
|
|
|
func (a clientManyToManyPermissions) Model(m *models.Client) *clientManyToManyPermissionsTx {
|
|
return &clientManyToManyPermissionsTx{a.db.Model(m).Association(a.Name())}
|
|
}
|
|
|
|
func (a clientManyToManyPermissions) Unscoped() *clientManyToManyPermissions {
|
|
a.db = a.db.Unscoped()
|
|
return &a
|
|
}
|
|
|
|
type clientManyToManyPermissionsTx struct{ tx *gorm.Association }
|
|
|
|
func (a clientManyToManyPermissionsTx) Find() (result []*models.Permission, err error) {
|
|
return result, a.tx.Find(&result)
|
|
}
|
|
|
|
func (a clientManyToManyPermissionsTx) Append(values ...*models.Permission) (err error) {
|
|
targetValues := make([]interface{}, len(values))
|
|
for i, v := range values {
|
|
targetValues[i] = v
|
|
}
|
|
return a.tx.Append(targetValues...)
|
|
}
|
|
|
|
func (a clientManyToManyPermissionsTx) Replace(values ...*models.Permission) (err error) {
|
|
targetValues := make([]interface{}, len(values))
|
|
for i, v := range values {
|
|
targetValues[i] = v
|
|
}
|
|
return a.tx.Replace(targetValues...)
|
|
}
|
|
|
|
func (a clientManyToManyPermissionsTx) Delete(values ...*models.Permission) (err error) {
|
|
targetValues := make([]interface{}, len(values))
|
|
for i, v := range values {
|
|
targetValues[i] = v
|
|
}
|
|
return a.tx.Delete(targetValues...)
|
|
}
|
|
|
|
func (a clientManyToManyPermissionsTx) Clear() error {
|
|
return a.tx.Clear()
|
|
}
|
|
|
|
func (a clientManyToManyPermissionsTx) Count() int64 {
|
|
return a.tx.Count()
|
|
}
|
|
|
|
func (a clientManyToManyPermissionsTx) Unscoped() *clientManyToManyPermissionsTx {
|
|
a.tx = a.tx.Unscoped()
|
|
return &a
|
|
}
|
|
|
|
type clientDo struct{ gen.DO }
|
|
|
|
func (c clientDo) Debug() *clientDo {
|
|
return c.withDO(c.DO.Debug())
|
|
}
|
|
|
|
func (c clientDo) WithContext(ctx context.Context) *clientDo {
|
|
return c.withDO(c.DO.WithContext(ctx))
|
|
}
|
|
|
|
func (c clientDo) ReadDB() *clientDo {
|
|
return c.Clauses(dbresolver.Read)
|
|
}
|
|
|
|
func (c clientDo) WriteDB() *clientDo {
|
|
return c.Clauses(dbresolver.Write)
|
|
}
|
|
|
|
func (c clientDo) Session(config *gorm.Session) *clientDo {
|
|
return c.withDO(c.DO.Session(config))
|
|
}
|
|
|
|
func (c clientDo) Clauses(conds ...clause.Expression) *clientDo {
|
|
return c.withDO(c.DO.Clauses(conds...))
|
|
}
|
|
|
|
func (c clientDo) Returning(value interface{}, columns ...string) *clientDo {
|
|
return c.withDO(c.DO.Returning(value, columns...))
|
|
}
|
|
|
|
func (c clientDo) Not(conds ...gen.Condition) *clientDo {
|
|
return c.withDO(c.DO.Not(conds...))
|
|
}
|
|
|
|
func (c clientDo) Or(conds ...gen.Condition) *clientDo {
|
|
return c.withDO(c.DO.Or(conds...))
|
|
}
|
|
|
|
func (c clientDo) Select(conds ...field.Expr) *clientDo {
|
|
return c.withDO(c.DO.Select(conds...))
|
|
}
|
|
|
|
func (c clientDo) Where(conds ...gen.Condition) *clientDo {
|
|
return c.withDO(c.DO.Where(conds...))
|
|
}
|
|
|
|
func (c clientDo) Order(conds ...field.Expr) *clientDo {
|
|
return c.withDO(c.DO.Order(conds...))
|
|
}
|
|
|
|
func (c clientDo) Distinct(cols ...field.Expr) *clientDo {
|
|
return c.withDO(c.DO.Distinct(cols...))
|
|
}
|
|
|
|
func (c clientDo) Omit(cols ...field.Expr) *clientDo {
|
|
return c.withDO(c.DO.Omit(cols...))
|
|
}
|
|
|
|
func (c clientDo) Join(table schema.Tabler, on ...field.Expr) *clientDo {
|
|
return c.withDO(c.DO.Join(table, on...))
|
|
}
|
|
|
|
func (c clientDo) LeftJoin(table schema.Tabler, on ...field.Expr) *clientDo {
|
|
return c.withDO(c.DO.LeftJoin(table, on...))
|
|
}
|
|
|
|
func (c clientDo) RightJoin(table schema.Tabler, on ...field.Expr) *clientDo {
|
|
return c.withDO(c.DO.RightJoin(table, on...))
|
|
}
|
|
|
|
func (c clientDo) Group(cols ...field.Expr) *clientDo {
|
|
return c.withDO(c.DO.Group(cols...))
|
|
}
|
|
|
|
func (c clientDo) Having(conds ...gen.Condition) *clientDo {
|
|
return c.withDO(c.DO.Having(conds...))
|
|
}
|
|
|
|
func (c clientDo) Limit(limit int) *clientDo {
|
|
return c.withDO(c.DO.Limit(limit))
|
|
}
|
|
|
|
func (c clientDo) Offset(offset int) *clientDo {
|
|
return c.withDO(c.DO.Offset(offset))
|
|
}
|
|
|
|
func (c clientDo) Scopes(funcs ...func(gen.Dao) gen.Dao) *clientDo {
|
|
return c.withDO(c.DO.Scopes(funcs...))
|
|
}
|
|
|
|
func (c clientDo) Unscoped() *clientDo {
|
|
return c.withDO(c.DO.Unscoped())
|
|
}
|
|
|
|
func (c clientDo) Create(values ...*models.Client) error {
|
|
if len(values) == 0 {
|
|
return nil
|
|
}
|
|
return c.DO.Create(values)
|
|
}
|
|
|
|
func (c clientDo) CreateInBatches(values []*models.Client, batchSize int) error {
|
|
return c.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 (c clientDo) Save(values ...*models.Client) error {
|
|
if len(values) == 0 {
|
|
return nil
|
|
}
|
|
return c.DO.Save(values)
|
|
}
|
|
|
|
func (c clientDo) First() (*models.Client, error) {
|
|
if result, err := c.DO.First(); err != nil {
|
|
return nil, err
|
|
} else {
|
|
return result.(*models.Client), nil
|
|
}
|
|
}
|
|
|
|
func (c clientDo) Take() (*models.Client, error) {
|
|
if result, err := c.DO.Take(); err != nil {
|
|
return nil, err
|
|
} else {
|
|
return result.(*models.Client), nil
|
|
}
|
|
}
|
|
|
|
func (c clientDo) Last() (*models.Client, error) {
|
|
if result, err := c.DO.Last(); err != nil {
|
|
return nil, err
|
|
} else {
|
|
return result.(*models.Client), nil
|
|
}
|
|
}
|
|
|
|
func (c clientDo) Find() ([]*models.Client, error) {
|
|
result, err := c.DO.Find()
|
|
return result.([]*models.Client), err
|
|
}
|
|
|
|
func (c clientDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*models.Client, err error) {
|
|
buf := make([]*models.Client, 0, batchSize)
|
|
err = c.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 (c clientDo) FindInBatches(result *[]*models.Client, batchSize int, fc func(tx gen.Dao, batch int) error) error {
|
|
return c.DO.FindInBatches(result, batchSize, fc)
|
|
}
|
|
|
|
func (c clientDo) Attrs(attrs ...field.AssignExpr) *clientDo {
|
|
return c.withDO(c.DO.Attrs(attrs...))
|
|
}
|
|
|
|
func (c clientDo) Assign(attrs ...field.AssignExpr) *clientDo {
|
|
return c.withDO(c.DO.Assign(attrs...))
|
|
}
|
|
|
|
func (c clientDo) Joins(fields ...field.RelationField) *clientDo {
|
|
for _, _f := range fields {
|
|
c = *c.withDO(c.DO.Joins(_f))
|
|
}
|
|
return &c
|
|
}
|
|
|
|
func (c clientDo) Preload(fields ...field.RelationField) *clientDo {
|
|
for _, _f := range fields {
|
|
c = *c.withDO(c.DO.Preload(_f))
|
|
}
|
|
return &c
|
|
}
|
|
|
|
func (c clientDo) FirstOrInit() (*models.Client, error) {
|
|
if result, err := c.DO.FirstOrInit(); err != nil {
|
|
return nil, err
|
|
} else {
|
|
return result.(*models.Client), nil
|
|
}
|
|
}
|
|
|
|
func (c clientDo) FirstOrCreate() (*models.Client, error) {
|
|
if result, err := c.DO.FirstOrCreate(); err != nil {
|
|
return nil, err
|
|
} else {
|
|
return result.(*models.Client), nil
|
|
}
|
|
}
|
|
|
|
func (c clientDo) FindByPage(offset int, limit int) (result []*models.Client, count int64, err error) {
|
|
result, err = c.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 = c.Offset(-1).Limit(-1).Count()
|
|
return
|
|
}
|
|
|
|
func (c clientDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) {
|
|
count, err = c.Count()
|
|
if err != nil {
|
|
return
|
|
}
|
|
|
|
err = c.Offset(offset).Limit(limit).Scan(result)
|
|
return
|
|
}
|
|
|
|
func (c clientDo) Scan(result interface{}) (err error) {
|
|
return c.DO.Scan(result)
|
|
}
|
|
|
|
func (c clientDo) Delete(models ...*models.Client) (result gen.ResultInfo, err error) {
|
|
return c.DO.Delete(models)
|
|
}
|
|
|
|
func (c *clientDo) withDO(do gen.Dao) *clientDo {
|
|
c.DO = *do.(*gen.DO)
|
|
return c
|
|
}
|