123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339 |
- // 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"
- "gorm.io/gorm"
- "gorm.io/gorm/clause"
- "gorm.io/gorm/schema"
- "gorm.io/gen"
- "gorm.io/gen/field"
- "gorm.io/plugin/dbresolver"
- "gadmin/internal/gorm/model"
- )
- func newCache(db *gorm.DB, opts ...gen.DOOption) cache {
- _cache := cache{}
- _cache.cacheDo.UseDB(db, opts...)
- _cache.cacheDo.UseModel(&model.Cache{})
- tableName := _cache.cacheDo.TableName()
- _cache.ALL = field.NewAsterisk(tableName)
- _cache.ID = field.NewInt64(tableName, "id")
- _cache.Key = field.NewString(tableName, "key")
- _cache.Value = field.NewString(tableName, "value")
- _cache.ExpiAt = field.NewInt64(tableName, "expi_at")
- _cache.CreatedAt = field.NewTime(tableName, "created_at")
- _cache.fillFieldMap()
- return _cache
- }
- type cache struct {
- cacheDo
- ALL field.Asterisk
- ID field.Int64
- Key field.String
- Value field.String
- ExpiAt field.Int64 // 过期时间
- CreatedAt field.Time // 创建时间
- fieldMap map[string]field.Expr
- }
- func (c cache) Table(newTableName string) *cache {
- c.cacheDo.UseTable(newTableName)
- return c.updateTableName(newTableName)
- }
- func (c cache) As(alias string) *cache {
- c.cacheDo.DO = *(c.cacheDo.As(alias).(*gen.DO))
- return c.updateTableName(alias)
- }
- func (c *cache) updateTableName(table string) *cache {
- c.ALL = field.NewAsterisk(table)
- c.ID = field.NewInt64(table, "id")
- c.Key = field.NewString(table, "key")
- c.Value = field.NewString(table, "value")
- c.ExpiAt = field.NewInt64(table, "expi_at")
- c.CreatedAt = field.NewTime(table, "created_at")
- c.fillFieldMap()
- return c
- }
- func (c *cache) 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 *cache) fillFieldMap() {
- c.fieldMap = make(map[string]field.Expr, 5)
- c.fieldMap["id"] = c.ID
- c.fieldMap["key"] = c.Key
- c.fieldMap["value"] = c.Value
- c.fieldMap["expi_at"] = c.ExpiAt
- c.fieldMap["created_at"] = c.CreatedAt
- }
- func (c cache) clone(db *gorm.DB) cache {
- c.cacheDo.ReplaceConnPool(db.Statement.ConnPool)
- return c
- }
- func (c cache) replaceDB(db *gorm.DB) cache {
- c.cacheDo.ReplaceDB(db)
- return c
- }
- type cacheDo struct{ gen.DO }
- func (c cacheDo) Debug() *cacheDo {
- return c.withDO(c.DO.Debug())
- }
- func (c cacheDo) WithContext(ctx context.Context) *cacheDo {
- return c.withDO(c.DO.WithContext(ctx))
- }
- func (c cacheDo) ReadDB() *cacheDo {
- return c.Clauses(dbresolver.Read)
- }
- func (c cacheDo) WriteDB() *cacheDo {
- return c.Clauses(dbresolver.Write)
- }
- func (c cacheDo) Session(config *gorm.Session) *cacheDo {
- return c.withDO(c.DO.Session(config))
- }
- func (c cacheDo) Clauses(conds ...clause.Expression) *cacheDo {
- return c.withDO(c.DO.Clauses(conds...))
- }
- func (c cacheDo) Returning(value interface{}, columns ...string) *cacheDo {
- return c.withDO(c.DO.Returning(value, columns...))
- }
- func (c cacheDo) Not(conds ...gen.Condition) *cacheDo {
- return c.withDO(c.DO.Not(conds...))
- }
- func (c cacheDo) Or(conds ...gen.Condition) *cacheDo {
- return c.withDO(c.DO.Or(conds...))
- }
- func (c cacheDo) Select(conds ...field.Expr) *cacheDo {
- return c.withDO(c.DO.Select(conds...))
- }
- func (c cacheDo) Where(conds ...gen.Condition) *cacheDo {
- return c.withDO(c.DO.Where(conds...))
- }
- func (c cacheDo) Exists(subquery interface{ UnderlyingDB() *gorm.DB }) *cacheDo {
- return c.Where(field.CompareSubQuery(field.ExistsOp, nil, subquery.UnderlyingDB()))
- }
- func (c cacheDo) Order(conds ...field.Expr) *cacheDo {
- return c.withDO(c.DO.Order(conds...))
- }
- func (c cacheDo) Distinct(cols ...field.Expr) *cacheDo {
- return c.withDO(c.DO.Distinct(cols...))
- }
- func (c cacheDo) Omit(cols ...field.Expr) *cacheDo {
- return c.withDO(c.DO.Omit(cols...))
- }
- func (c cacheDo) Join(table schema.Tabler, on ...field.Expr) *cacheDo {
- return c.withDO(c.DO.Join(table, on...))
- }
- func (c cacheDo) LeftJoin(table schema.Tabler, on ...field.Expr) *cacheDo {
- return c.withDO(c.DO.LeftJoin(table, on...))
- }
- func (c cacheDo) RightJoin(table schema.Tabler, on ...field.Expr) *cacheDo {
- return c.withDO(c.DO.RightJoin(table, on...))
- }
- func (c cacheDo) Group(cols ...field.Expr) *cacheDo {
- return c.withDO(c.DO.Group(cols...))
- }
- func (c cacheDo) Having(conds ...gen.Condition) *cacheDo {
- return c.withDO(c.DO.Having(conds...))
- }
- func (c cacheDo) Limit(limit int) *cacheDo {
- return c.withDO(c.DO.Limit(limit))
- }
- func (c cacheDo) Offset(offset int) *cacheDo {
- return c.withDO(c.DO.Offset(offset))
- }
- func (c cacheDo) Scopes(funcs ...func(gen.Dao) gen.Dao) *cacheDo {
- return c.withDO(c.DO.Scopes(funcs...))
- }
- func (c cacheDo) Unscoped() *cacheDo {
- return c.withDO(c.DO.Unscoped())
- }
- func (c cacheDo) Create(values ...*model.Cache) error {
- if len(values) == 0 {
- return nil
- }
- return c.DO.Create(values)
- }
- func (c cacheDo) CreateInBatches(values []*model.Cache, 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 cacheDo) Save(values ...*model.Cache) error {
- if len(values) == 0 {
- return nil
- }
- return c.DO.Save(values)
- }
- func (c cacheDo) First() (*model.Cache, error) {
- if result, err := c.DO.First(); err != nil {
- return nil, err
- } else {
- return result.(*model.Cache), nil
- }
- }
- func (c cacheDo) Take() (*model.Cache, error) {
- if result, err := c.DO.Take(); err != nil {
- return nil, err
- } else {
- return result.(*model.Cache), nil
- }
- }
- func (c cacheDo) Last() (*model.Cache, error) {
- if result, err := c.DO.Last(); err != nil {
- return nil, err
- } else {
- return result.(*model.Cache), nil
- }
- }
- func (c cacheDo) Find() ([]*model.Cache, error) {
- result, err := c.DO.Find()
- return result.([]*model.Cache), err
- }
- func (c cacheDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.Cache, err error) {
- buf := make([]*model.Cache, 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 cacheDo) FindInBatches(result *[]*model.Cache, batchSize int, fc func(tx gen.Dao, batch int) error) error {
- return c.DO.FindInBatches(result, batchSize, fc)
- }
- func (c cacheDo) Attrs(attrs ...field.AssignExpr) *cacheDo {
- return c.withDO(c.DO.Attrs(attrs...))
- }
- func (c cacheDo) Assign(attrs ...field.AssignExpr) *cacheDo {
- return c.withDO(c.DO.Assign(attrs...))
- }
- func (c cacheDo) Joins(fields ...field.RelationField) *cacheDo {
- for _, _f := range fields {
- c = *c.withDO(c.DO.Joins(_f))
- }
- return &c
- }
- func (c cacheDo) Preload(fields ...field.RelationField) *cacheDo {
- for _, _f := range fields {
- c = *c.withDO(c.DO.Preload(_f))
- }
- return &c
- }
- func (c cacheDo) FirstOrInit() (*model.Cache, error) {
- if result, err := c.DO.FirstOrInit(); err != nil {
- return nil, err
- } else {
- return result.(*model.Cache), nil
- }
- }
- func (c cacheDo) FirstOrCreate() (*model.Cache, error) {
- if result, err := c.DO.FirstOrCreate(); err != nil {
- return nil, err
- } else {
- return result.(*model.Cache), nil
- }
- }
- func (c cacheDo) FindByPage(offset int, limit int) (result []*model.Cache, 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 cacheDo) 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 cacheDo) Scan(result interface{}) (err error) {
- return c.DO.Scan(result)
- }
- func (c cacheDo) Delete(models ...*model.Cache) (result gen.ResultInfo, err error) {
- return c.DO.Delete(models)
- }
- func (c *cacheDo) withDO(do gen.Dao) *cacheDo {
- c.DO = *do.(*gen.DO)
- return c
- }
|