376 lines
10 KiB
Go
376 lines
10 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.ClientID = field.NewString(tableName, "client_id")
|
||
_client.ClientSecret = field.NewString(tableName, "client_secret")
|
||
_client.RedirectURI = field.NewString(tableName, "redirect_uri")
|
||
_client.GrantCode = field.NewBool(tableName, "grant_code")
|
||
_client.GrantClient = field.NewBool(tableName, "grant_client")
|
||
_client.GrantRefresh = field.NewBool(tableName, "grant_refresh")
|
||
_client.Spec = field.NewInt32(tableName, "spec")
|
||
_client.Name = field.NewString(tableName, "name")
|
||
_client.Icon = field.NewString(tableName, "icon")
|
||
_client.Status = field.NewInt32(tableName, "status")
|
||
_client.CreatedAt = field.NewField(tableName, "created_at")
|
||
_client.UpdatedAt = field.NewField(tableName, "updated_at")
|
||
_client.DeletedAt = field.NewField(tableName, "deleted_at")
|
||
_client.GrantPassword = field.NewBool(tableName, "grant_password")
|
||
|
||
_client.fillFieldMap()
|
||
|
||
return _client
|
||
}
|
||
|
||
type client struct {
|
||
clientDo
|
||
|
||
ALL field.Asterisk
|
||
ID field.Int32 // 客户端ID
|
||
ClientID field.String // OAuth2客户端标识符
|
||
ClientSecret field.String // OAuth2客户端密钥
|
||
RedirectURI field.String // OAuth2 重定向URI
|
||
GrantCode field.Bool // 允许授权码授予
|
||
GrantClient field.Bool // 允许客户端凭证授予
|
||
GrantRefresh field.Bool // 允许刷新令牌授予
|
||
Spec field.Int32 // 安全规范:0-web,1-native,2-browser
|
||
Name field.String // 名称
|
||
Icon field.String // 图标URL
|
||
Status field.Int32 // 状态:1-正常,0-禁用
|
||
CreatedAt field.Field // 创建时间
|
||
UpdatedAt field.Field // 更新时间
|
||
DeletedAt field.Field // 删除时间
|
||
GrantPassword field.Bool
|
||
|
||
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.ClientID = field.NewString(table, "client_id")
|
||
c.ClientSecret = field.NewString(table, "client_secret")
|
||
c.RedirectURI = field.NewString(table, "redirect_uri")
|
||
c.GrantCode = field.NewBool(table, "grant_code")
|
||
c.GrantClient = field.NewBool(table, "grant_client")
|
||
c.GrantRefresh = field.NewBool(table, "grant_refresh")
|
||
c.Spec = field.NewInt32(table, "spec")
|
||
c.Name = field.NewString(table, "name")
|
||
c.Icon = field.NewString(table, "icon")
|
||
c.Status = field.NewInt32(table, "status")
|
||
c.CreatedAt = field.NewField(table, "created_at")
|
||
c.UpdatedAt = field.NewField(table, "updated_at")
|
||
c.DeletedAt = field.NewField(table, "deleted_at")
|
||
c.GrantPassword = field.NewBool(table, "grant_password")
|
||
|
||
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, 15)
|
||
c.fieldMap["id"] = c.ID
|
||
c.fieldMap["client_id"] = c.ClientID
|
||
c.fieldMap["client_secret"] = c.ClientSecret
|
||
c.fieldMap["redirect_uri"] = c.RedirectURI
|
||
c.fieldMap["grant_code"] = c.GrantCode
|
||
c.fieldMap["grant_client"] = c.GrantClient
|
||
c.fieldMap["grant_refresh"] = c.GrantRefresh
|
||
c.fieldMap["spec"] = c.Spec
|
||
c.fieldMap["name"] = c.Name
|
||
c.fieldMap["icon"] = c.Icon
|
||
c.fieldMap["status"] = c.Status
|
||
c.fieldMap["created_at"] = c.CreatedAt
|
||
c.fieldMap["updated_at"] = c.UpdatedAt
|
||
c.fieldMap["deleted_at"] = c.DeletedAt
|
||
c.fieldMap["grant_password"] = c.GrantPassword
|
||
}
|
||
|
||
func (c client) clone(db *gorm.DB) client {
|
||
c.clientDo.ReplaceConnPool(db.Statement.ConnPool)
|
||
return c
|
||
}
|
||
|
||
func (c client) replaceDB(db *gorm.DB) client {
|
||
c.clientDo.ReplaceDB(db)
|
||
return c
|
||
}
|
||
|
||
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
|
||
}
|