Files
quyun/backend_v1/database/models/user_posts.query.gen.go
Rogee 24bd161df9
Some checks failed
build quyun / Build (push) Has been cancelled
feat: add backend_v1 migration
2025-12-19 14:46:58 +08:00

482 lines
13 KiB
Go

// Code generated by go.ipao.vip/gen. DO NOT EDIT.
// Code generated by go.ipao.vip/gen. DO NOT EDIT.
// Code generated by go.ipao.vip/gen. DO NOT EDIT.
package models
import (
"context"
"gorm.io/gorm"
"gorm.io/gorm/clause"
"gorm.io/gorm/schema"
"go.ipao.vip/gen"
"go.ipao.vip/gen/field"
"gorm.io/plugin/dbresolver"
)
func newUserPost(db *gorm.DB, opts ...gen.DOOption) userPostQuery {
_userPostQuery := userPostQuery{}
_userPostQuery.userPostQueryDo.UseDB(db, opts...)
_userPostQuery.userPostQueryDo.UseModel(&UserPost{})
tableName := _userPostQuery.userPostQueryDo.TableName()
_userPostQuery.ALL = field.NewAsterisk(tableName)
_userPostQuery.ID = field.NewInt64(tableName, "id")
_userPostQuery.CreatedAt = field.NewTime(tableName, "created_at")
_userPostQuery.UpdatedAt = field.NewTime(tableName, "updated_at")
_userPostQuery.UserID = field.NewInt64(tableName, "user_id")
_userPostQuery.PostID = field.NewInt64(tableName, "post_id")
_userPostQuery.Price = field.NewInt64(tableName, "price")
_userPostQuery.fillFieldMap()
return _userPostQuery
}
type userPostQuery struct {
userPostQueryDo userPostQueryDo
ALL field.Asterisk
ID field.Int64
CreatedAt field.Time
UpdatedAt field.Time
UserID field.Int64
PostID field.Int64
Price field.Int64
fieldMap map[string]field.Expr
}
func (u userPostQuery) Table(newTableName string) *userPostQuery {
u.userPostQueryDo.UseTable(newTableName)
return u.updateTableName(newTableName)
}
func (u userPostQuery) As(alias string) *userPostQuery {
u.userPostQueryDo.DO = *(u.userPostQueryDo.As(alias).(*gen.DO))
return u.updateTableName(alias)
}
func (u *userPostQuery) updateTableName(table string) *userPostQuery {
u.ALL = field.NewAsterisk(table)
u.ID = field.NewInt64(table, "id")
u.CreatedAt = field.NewTime(table, "created_at")
u.UpdatedAt = field.NewTime(table, "updated_at")
u.UserID = field.NewInt64(table, "user_id")
u.PostID = field.NewInt64(table, "post_id")
u.Price = field.NewInt64(table, "price")
u.fillFieldMap()
return u
}
func (u *userPostQuery) QueryContext(ctx context.Context) (*userPostQuery, *userPostQueryDo) {
return u, u.userPostQueryDo.WithContext(ctx)
}
func (u *userPostQuery) WithContext(ctx context.Context) *userPostQueryDo {
return u.userPostQueryDo.WithContext(ctx)
}
func (u userPostQuery) TableName() string { return u.userPostQueryDo.TableName() }
func (u userPostQuery) Alias() string { return u.userPostQueryDo.Alias() }
func (u userPostQuery) Columns(cols ...field.Expr) gen.Columns {
return u.userPostQueryDo.Columns(cols...)
}
func (u *userPostQuery) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
_f, ok := u.fieldMap[fieldName]
if !ok || _f == nil {
return nil, false
}
_oe, ok := _f.(field.OrderExpr)
return _oe, ok
}
func (u *userPostQuery) fillFieldMap() {
u.fieldMap = make(map[string]field.Expr, 6)
u.fieldMap["id"] = u.ID
u.fieldMap["created_at"] = u.CreatedAt
u.fieldMap["updated_at"] = u.UpdatedAt
u.fieldMap["user_id"] = u.UserID
u.fieldMap["post_id"] = u.PostID
u.fieldMap["price"] = u.Price
}
func (u userPostQuery) clone(db *gorm.DB) userPostQuery {
u.userPostQueryDo.ReplaceConnPool(db.Statement.ConnPool)
return u
}
func (u userPostQuery) replaceDB(db *gorm.DB) userPostQuery {
u.userPostQueryDo.ReplaceDB(db)
return u
}
type userPostQueryDo struct{ gen.DO }
func (u userPostQueryDo) Debug() *userPostQueryDo {
return u.withDO(u.DO.Debug())
}
func (u userPostQueryDo) WithContext(ctx context.Context) *userPostQueryDo {
return u.withDO(u.DO.WithContext(ctx))
}
func (u userPostQueryDo) ReadDB() *userPostQueryDo {
return u.Clauses(dbresolver.Read)
}
func (u userPostQueryDo) WriteDB() *userPostQueryDo {
return u.Clauses(dbresolver.Write)
}
func (u userPostQueryDo) Session(config *gorm.Session) *userPostQueryDo {
return u.withDO(u.DO.Session(config))
}
func (u userPostQueryDo) Clauses(conds ...clause.Expression) *userPostQueryDo {
return u.withDO(u.DO.Clauses(conds...))
}
func (u userPostQueryDo) Returning(value interface{}, columns ...string) *userPostQueryDo {
return u.withDO(u.DO.Returning(value, columns...))
}
func (u userPostQueryDo) Not(conds ...gen.Condition) *userPostQueryDo {
return u.withDO(u.DO.Not(conds...))
}
func (u userPostQueryDo) Or(conds ...gen.Condition) *userPostQueryDo {
return u.withDO(u.DO.Or(conds...))
}
func (u userPostQueryDo) Select(conds ...field.Expr) *userPostQueryDo {
return u.withDO(u.DO.Select(conds...))
}
func (u userPostQueryDo) Where(conds ...gen.Condition) *userPostQueryDo {
return u.withDO(u.DO.Where(conds...))
}
func (u userPostQueryDo) Order(conds ...field.Expr) *userPostQueryDo {
return u.withDO(u.DO.Order(conds...))
}
func (u userPostQueryDo) Distinct(cols ...field.Expr) *userPostQueryDo {
return u.withDO(u.DO.Distinct(cols...))
}
func (u userPostQueryDo) Omit(cols ...field.Expr) *userPostQueryDo {
return u.withDO(u.DO.Omit(cols...))
}
func (u userPostQueryDo) Join(table schema.Tabler, on ...field.Expr) *userPostQueryDo {
return u.withDO(u.DO.Join(table, on...))
}
func (u userPostQueryDo) LeftJoin(table schema.Tabler, on ...field.Expr) *userPostQueryDo {
return u.withDO(u.DO.LeftJoin(table, on...))
}
func (u userPostQueryDo) RightJoin(table schema.Tabler, on ...field.Expr) *userPostQueryDo {
return u.withDO(u.DO.RightJoin(table, on...))
}
func (u userPostQueryDo) Group(cols ...field.Expr) *userPostQueryDo {
return u.withDO(u.DO.Group(cols...))
}
func (u userPostQueryDo) Having(conds ...gen.Condition) *userPostQueryDo {
return u.withDO(u.DO.Having(conds...))
}
func (u userPostQueryDo) Limit(limit int) *userPostQueryDo {
return u.withDO(u.DO.Limit(limit))
}
func (u userPostQueryDo) Offset(offset int) *userPostQueryDo {
return u.withDO(u.DO.Offset(offset))
}
func (u userPostQueryDo) Scopes(funcs ...func(gen.Dao) gen.Dao) *userPostQueryDo {
return u.withDO(u.DO.Scopes(funcs...))
}
func (u userPostQueryDo) Unscoped() *userPostQueryDo {
return u.withDO(u.DO.Unscoped())
}
func (u userPostQueryDo) Create(values ...*UserPost) error {
if len(values) == 0 {
return nil
}
return u.DO.Create(values)
}
func (u userPostQueryDo) CreateInBatches(values []*UserPost, batchSize int) error {
return u.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 (u userPostQueryDo) Save(values ...*UserPost) error {
if len(values) == 0 {
return nil
}
return u.DO.Save(values)
}
func (u userPostQueryDo) First() (*UserPost, error) {
if result, err := u.DO.First(); err != nil {
return nil, err
} else {
return result.(*UserPost), nil
}
}
func (u userPostQueryDo) Take() (*UserPost, error) {
if result, err := u.DO.Take(); err != nil {
return nil, err
} else {
return result.(*UserPost), nil
}
}
func (u userPostQueryDo) Last() (*UserPost, error) {
if result, err := u.DO.Last(); err != nil {
return nil, err
} else {
return result.(*UserPost), nil
}
}
func (u userPostQueryDo) Find() ([]*UserPost, error) {
result, err := u.DO.Find()
return result.([]*UserPost), err
}
func (u userPostQueryDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*UserPost, err error) {
buf := make([]*UserPost, 0, batchSize)
err = u.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 (u userPostQueryDo) FindInBatches(result *[]*UserPost, batchSize int, fc func(tx gen.Dao, batch int) error) error {
return u.DO.FindInBatches(result, batchSize, fc)
}
func (u userPostQueryDo) Attrs(attrs ...field.AssignExpr) *userPostQueryDo {
return u.withDO(u.DO.Attrs(attrs...))
}
func (u userPostQueryDo) Assign(attrs ...field.AssignExpr) *userPostQueryDo {
return u.withDO(u.DO.Assign(attrs...))
}
func (u userPostQueryDo) Joins(fields ...field.RelationField) *userPostQueryDo {
for _, _f := range fields {
u = *u.withDO(u.DO.Joins(_f))
}
return &u
}
func (u userPostQueryDo) Preload(fields ...field.RelationField) *userPostQueryDo {
for _, _f := range fields {
u = *u.withDO(u.DO.Preload(_f))
}
return &u
}
func (u userPostQueryDo) FirstOrInit() (*UserPost, error) {
if result, err := u.DO.FirstOrInit(); err != nil {
return nil, err
} else {
return result.(*UserPost), nil
}
}
func (u userPostQueryDo) FirstOrCreate() (*UserPost, error) {
if result, err := u.DO.FirstOrCreate(); err != nil {
return nil, err
} else {
return result.(*UserPost), nil
}
}
func (u userPostQueryDo) FindByPage(offset int, limit int) (result []*UserPost, count int64, err error) {
result, err = u.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 = u.Offset(-1).Limit(-1).Count()
return
}
func (u userPostQueryDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) {
count, err = u.Count()
if err != nil {
return
}
err = u.Offset(offset).Limit(limit).Scan(result)
return
}
func (u userPostQueryDo) Scan(result interface{}) (err error) {
return u.DO.Scan(result)
}
func (u userPostQueryDo) Delete(models ...*UserPost) (result gen.ResultInfo, err error) {
return u.DO.Delete(models)
}
// ForceDelete performs a permanent delete (ignores soft-delete) for current scope.
func (u userPostQueryDo) ForceDelete() (gen.ResultInfo, error) {
return u.Unscoped().Delete()
}
// Inc increases the given column by step for current scope.
func (u userPostQueryDo) Inc(column field.Expr, step int64) (gen.ResultInfo, error) {
// column = column + step
e := field.NewUnsafeFieldRaw("?+?", column.RawExpr(), step)
return u.DO.UpdateColumn(column, e)
}
// Dec decreases the given column by step for current scope.
func (u userPostQueryDo) Dec(column field.Expr, step int64) (gen.ResultInfo, error) {
// column = column - step
e := field.NewUnsafeFieldRaw("?-?", column.RawExpr(), step)
return u.DO.UpdateColumn(column, e)
}
// Sum returns SUM(column) for current scope.
func (u userPostQueryDo) Sum(column field.Expr) (float64, error) {
var _v float64
agg := field.NewUnsafeFieldRaw("SUM(?)", column.RawExpr())
if err := u.Select(agg).Scan(&_v); err != nil {
return 0, err
}
return _v, nil
}
// Avg returns AVG(column) for current scope.
func (u userPostQueryDo) Avg(column field.Expr) (float64, error) {
var _v float64
agg := field.NewUnsafeFieldRaw("AVG(?)", column.RawExpr())
if err := u.Select(agg).Scan(&_v); err != nil {
return 0, err
}
return _v, nil
}
// Min returns MIN(column) for current scope.
func (u userPostQueryDo) Min(column field.Expr) (float64, error) {
var _v float64
agg := field.NewUnsafeFieldRaw("MIN(?)", column.RawExpr())
if err := u.Select(agg).Scan(&_v); err != nil {
return 0, err
}
return _v, nil
}
// Max returns MAX(column) for current scope.
func (u userPostQueryDo) Max(column field.Expr) (float64, error) {
var _v float64
agg := field.NewUnsafeFieldRaw("MAX(?)", column.RawExpr())
if err := u.Select(agg).Scan(&_v); err != nil {
return 0, err
}
return _v, nil
}
// PluckMap returns a map[key]value for selected key/value expressions within current scope.
func (u userPostQueryDo) PluckMap(key, val field.Expr) (map[interface{}]interface{}, error) {
do := u.Select(key, val)
rows, err := do.DO.Rows()
if err != nil {
return nil, err
}
defer rows.Close()
mm := make(map[interface{}]interface{})
for rows.Next() {
var k interface{}
var v interface{}
if err := rows.Scan(&k, &v); err != nil {
return nil, err
}
mm[k] = v
}
return mm, rows.Err()
}
// Exists returns true if any record matches the given conditions.
func (u userPostQueryDo) Exists(conds ...gen.Condition) (bool, error) {
cnt, err := u.Where(conds...).Count()
if err != nil {
return false, err
}
return cnt > 0, nil
}
// PluckIDs returns all primary key values under current scope.
func (u userPostQueryDo) PluckIDs() ([]int64, error) {
ids := make([]int64, 0, 16)
pk := field.NewInt64(u.TableName(), "id")
if err := u.DO.Pluck(pk, &ids); err != nil {
return nil, err
}
return ids, nil
}
// GetByID finds a single record by primary key.
func (u userPostQueryDo) GetByID(id int64) (*UserPost, error) {
pk := field.NewInt64(u.TableName(), "id")
return u.Where(pk.Eq(id)).First()
}
// GetByIDs finds records by primary key list.
func (u userPostQueryDo) GetByIDs(ids ...int64) ([]*UserPost, error) {
if len(ids) == 0 {
return []*UserPost{}, nil
}
pk := field.NewInt64(u.TableName(), "id")
return u.Where(pk.In(ids...)).Find()
}
// DeleteByID deletes records by primary key.
func (u userPostQueryDo) DeleteByID(id int64) (gen.ResultInfo, error) {
pk := field.NewInt64(u.TableName(), "id")
return u.Where(pk.Eq(id)).Delete()
}
// DeleteByIDs deletes records by a list of primary keys.
func (u userPostQueryDo) DeleteByIDs(ids ...int64) (gen.ResultInfo, error) {
if len(ids) == 0 {
return gen.ResultInfo{RowsAffected: 0, Error: nil}, nil
}
pk := field.NewInt64(u.TableName(), "id")
return u.Where(pk.In(ids...)).Delete()
}
func (u *userPostQueryDo) withDO(do gen.Dao) *userPostQueryDo {
u.DO = *do.(*gen.DO)
return u
}