pending
This commit is contained in:
65
backend/database/models/content_access.gen.go
Normal file
65
backend/database/models/content_access.gen.go
Normal file
@@ -0,0 +1,65 @@
|
||||
// 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"
|
||||
"time"
|
||||
|
||||
"quyun/v2/pkg/consts"
|
||||
|
||||
"go.ipao.vip/gen"
|
||||
)
|
||||
|
||||
const TableNameContentAccess = "content_access"
|
||||
|
||||
// ContentAccess mapped from table <content_access>
|
||||
type ContentAccess struct {
|
||||
ID int64 `gorm:"column:id;type:bigint;primaryKey;autoIncrement:true" json:"id"`
|
||||
TenantID int64 `gorm:"column:tenant_id;type:bigint;not null" json:"tenant_id"`
|
||||
UserID int64 `gorm:"column:user_id;type:bigint;not null" json:"user_id"`
|
||||
ContentID int64 `gorm:"column:content_id;type:bigint;not null" json:"content_id"`
|
||||
OrderID int64 `gorm:"column:order_id;type:bigint" json:"order_id"`
|
||||
Status consts.ContentAccessStatus `gorm:"column:status;type:character varying(16);not null;default:active" json:"status"`
|
||||
RevokedAt time.Time `gorm:"column:revoked_at;type:timestamp with time zone" json:"revoked_at"`
|
||||
CreatedAt time.Time `gorm:"column:created_at;type:timestamp with time zone;not null;default:now()" json:"created_at"`
|
||||
UpdatedAt time.Time `gorm:"column:updated_at;type:timestamp with time zone;not null;default:now()" json:"updated_at"`
|
||||
}
|
||||
|
||||
// Quick operations without importing query package
|
||||
// Update applies changed fields to the database using the default DB.
|
||||
func (m *ContentAccess) Update(ctx context.Context) (gen.ResultInfo, error) {
|
||||
return Q.ContentAccess.WithContext(ctx).Updates(m)
|
||||
}
|
||||
|
||||
// Save upserts the model using the default DB.
|
||||
func (m *ContentAccess) Save(ctx context.Context) error {
|
||||
return Q.ContentAccess.WithContext(ctx).Save(m)
|
||||
}
|
||||
|
||||
// Create inserts the model using the default DB.
|
||||
func (m *ContentAccess) Create(ctx context.Context) error {
|
||||
return Q.ContentAccess.WithContext(ctx).Create(m)
|
||||
}
|
||||
|
||||
// Delete removes the row represented by the model using the default DB.
|
||||
func (m *ContentAccess) Delete(ctx context.Context) (gen.ResultInfo, error) {
|
||||
return Q.ContentAccess.WithContext(ctx).Delete(m)
|
||||
}
|
||||
|
||||
// ForceDelete permanently deletes the row (ignores soft delete) using the default DB.
|
||||
func (m *ContentAccess) ForceDelete(ctx context.Context) (gen.ResultInfo, error) {
|
||||
return Q.ContentAccess.WithContext(ctx).Unscoped().Delete(m)
|
||||
}
|
||||
|
||||
// Reload reloads the model from database by its primary key and overwrites current fields.
|
||||
func (m *ContentAccess) Reload(ctx context.Context) error {
|
||||
fresh, err := Q.ContentAccess.WithContext(ctx).GetByID(m.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
*m = *fresh
|
||||
return nil
|
||||
}
|
||||
493
backend/database/models/content_access.query.gen.go
Normal file
493
backend/database/models/content_access.query.gen.go
Normal file
@@ -0,0 +1,493 @@
|
||||
// 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 newContentAccess(db *gorm.DB, opts ...gen.DOOption) contentAccessQuery {
|
||||
_contentAccessQuery := contentAccessQuery{}
|
||||
|
||||
_contentAccessQuery.contentAccessQueryDo.UseDB(db, opts...)
|
||||
_contentAccessQuery.contentAccessQueryDo.UseModel(&ContentAccess{})
|
||||
|
||||
tableName := _contentAccessQuery.contentAccessQueryDo.TableName()
|
||||
_contentAccessQuery.ALL = field.NewAsterisk(tableName)
|
||||
_contentAccessQuery.ID = field.NewInt64(tableName, "id")
|
||||
_contentAccessQuery.TenantID = field.NewInt64(tableName, "tenant_id")
|
||||
_contentAccessQuery.UserID = field.NewInt64(tableName, "user_id")
|
||||
_contentAccessQuery.ContentID = field.NewInt64(tableName, "content_id")
|
||||
_contentAccessQuery.OrderID = field.NewInt64(tableName, "order_id")
|
||||
_contentAccessQuery.Status = field.NewField(tableName, "status")
|
||||
_contentAccessQuery.RevokedAt = field.NewTime(tableName, "revoked_at")
|
||||
_contentAccessQuery.CreatedAt = field.NewTime(tableName, "created_at")
|
||||
_contentAccessQuery.UpdatedAt = field.NewTime(tableName, "updated_at")
|
||||
|
||||
_contentAccessQuery.fillFieldMap()
|
||||
|
||||
return _contentAccessQuery
|
||||
}
|
||||
|
||||
type contentAccessQuery struct {
|
||||
contentAccessQueryDo contentAccessQueryDo
|
||||
|
||||
ALL field.Asterisk
|
||||
ID field.Int64
|
||||
TenantID field.Int64
|
||||
UserID field.Int64
|
||||
ContentID field.Int64
|
||||
OrderID field.Int64
|
||||
Status field.Field
|
||||
RevokedAt field.Time
|
||||
CreatedAt field.Time
|
||||
UpdatedAt field.Time
|
||||
|
||||
fieldMap map[string]field.Expr
|
||||
}
|
||||
|
||||
func (c contentAccessQuery) Table(newTableName string) *contentAccessQuery {
|
||||
c.contentAccessQueryDo.UseTable(newTableName)
|
||||
return c.updateTableName(newTableName)
|
||||
}
|
||||
|
||||
func (c contentAccessQuery) As(alias string) *contentAccessQuery {
|
||||
c.contentAccessQueryDo.DO = *(c.contentAccessQueryDo.As(alias).(*gen.DO))
|
||||
return c.updateTableName(alias)
|
||||
}
|
||||
|
||||
func (c *contentAccessQuery) updateTableName(table string) *contentAccessQuery {
|
||||
c.ALL = field.NewAsterisk(table)
|
||||
c.ID = field.NewInt64(table, "id")
|
||||
c.TenantID = field.NewInt64(table, "tenant_id")
|
||||
c.UserID = field.NewInt64(table, "user_id")
|
||||
c.ContentID = field.NewInt64(table, "content_id")
|
||||
c.OrderID = field.NewInt64(table, "order_id")
|
||||
c.Status = field.NewField(table, "status")
|
||||
c.RevokedAt = field.NewTime(table, "revoked_at")
|
||||
c.CreatedAt = field.NewTime(table, "created_at")
|
||||
c.UpdatedAt = field.NewTime(table, "updated_at")
|
||||
|
||||
c.fillFieldMap()
|
||||
|
||||
return c
|
||||
}
|
||||
|
||||
func (c *contentAccessQuery) QueryContext(ctx context.Context) (*contentAccessQuery, *contentAccessQueryDo) {
|
||||
return c, c.contentAccessQueryDo.WithContext(ctx)
|
||||
}
|
||||
|
||||
func (c *contentAccessQuery) WithContext(ctx context.Context) *contentAccessQueryDo {
|
||||
return c.contentAccessQueryDo.WithContext(ctx)
|
||||
}
|
||||
|
||||
func (c contentAccessQuery) TableName() string { return c.contentAccessQueryDo.TableName() }
|
||||
|
||||
func (c contentAccessQuery) Alias() string { return c.contentAccessQueryDo.Alias() }
|
||||
|
||||
func (c contentAccessQuery) Columns(cols ...field.Expr) gen.Columns {
|
||||
return c.contentAccessQueryDo.Columns(cols...)
|
||||
}
|
||||
|
||||
func (c *contentAccessQuery) 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 *contentAccessQuery) fillFieldMap() {
|
||||
c.fieldMap = make(map[string]field.Expr, 9)
|
||||
c.fieldMap["id"] = c.ID
|
||||
c.fieldMap["tenant_id"] = c.TenantID
|
||||
c.fieldMap["user_id"] = c.UserID
|
||||
c.fieldMap["content_id"] = c.ContentID
|
||||
c.fieldMap["order_id"] = c.OrderID
|
||||
c.fieldMap["status"] = c.Status
|
||||
c.fieldMap["revoked_at"] = c.RevokedAt
|
||||
c.fieldMap["created_at"] = c.CreatedAt
|
||||
c.fieldMap["updated_at"] = c.UpdatedAt
|
||||
}
|
||||
|
||||
func (c contentAccessQuery) clone(db *gorm.DB) contentAccessQuery {
|
||||
c.contentAccessQueryDo.ReplaceConnPool(db.Statement.ConnPool)
|
||||
return c
|
||||
}
|
||||
|
||||
func (c contentAccessQuery) replaceDB(db *gorm.DB) contentAccessQuery {
|
||||
c.contentAccessQueryDo.ReplaceDB(db)
|
||||
return c
|
||||
}
|
||||
|
||||
type contentAccessQueryDo struct{ gen.DO }
|
||||
|
||||
func (c contentAccessQueryDo) Debug() *contentAccessQueryDo {
|
||||
return c.withDO(c.DO.Debug())
|
||||
}
|
||||
|
||||
func (c contentAccessQueryDo) WithContext(ctx context.Context) *contentAccessQueryDo {
|
||||
return c.withDO(c.DO.WithContext(ctx))
|
||||
}
|
||||
|
||||
func (c contentAccessQueryDo) ReadDB() *contentAccessQueryDo {
|
||||
return c.Clauses(dbresolver.Read)
|
||||
}
|
||||
|
||||
func (c contentAccessQueryDo) WriteDB() *contentAccessQueryDo {
|
||||
return c.Clauses(dbresolver.Write)
|
||||
}
|
||||
|
||||
func (c contentAccessQueryDo) Session(config *gorm.Session) *contentAccessQueryDo {
|
||||
return c.withDO(c.DO.Session(config))
|
||||
}
|
||||
|
||||
func (c contentAccessQueryDo) Clauses(conds ...clause.Expression) *contentAccessQueryDo {
|
||||
return c.withDO(c.DO.Clauses(conds...))
|
||||
}
|
||||
|
||||
func (c contentAccessQueryDo) Returning(value interface{}, columns ...string) *contentAccessQueryDo {
|
||||
return c.withDO(c.DO.Returning(value, columns...))
|
||||
}
|
||||
|
||||
func (c contentAccessQueryDo) Not(conds ...gen.Condition) *contentAccessQueryDo {
|
||||
return c.withDO(c.DO.Not(conds...))
|
||||
}
|
||||
|
||||
func (c contentAccessQueryDo) Or(conds ...gen.Condition) *contentAccessQueryDo {
|
||||
return c.withDO(c.DO.Or(conds...))
|
||||
}
|
||||
|
||||
func (c contentAccessQueryDo) Select(conds ...field.Expr) *contentAccessQueryDo {
|
||||
return c.withDO(c.DO.Select(conds...))
|
||||
}
|
||||
|
||||
func (c contentAccessQueryDo) Where(conds ...gen.Condition) *contentAccessQueryDo {
|
||||
return c.withDO(c.DO.Where(conds...))
|
||||
}
|
||||
|
||||
func (c contentAccessQueryDo) Order(conds ...field.Expr) *contentAccessQueryDo {
|
||||
return c.withDO(c.DO.Order(conds...))
|
||||
}
|
||||
|
||||
func (c contentAccessQueryDo) Distinct(cols ...field.Expr) *contentAccessQueryDo {
|
||||
return c.withDO(c.DO.Distinct(cols...))
|
||||
}
|
||||
|
||||
func (c contentAccessQueryDo) Omit(cols ...field.Expr) *contentAccessQueryDo {
|
||||
return c.withDO(c.DO.Omit(cols...))
|
||||
}
|
||||
|
||||
func (c contentAccessQueryDo) Join(table schema.Tabler, on ...field.Expr) *contentAccessQueryDo {
|
||||
return c.withDO(c.DO.Join(table, on...))
|
||||
}
|
||||
|
||||
func (c contentAccessQueryDo) LeftJoin(table schema.Tabler, on ...field.Expr) *contentAccessQueryDo {
|
||||
return c.withDO(c.DO.LeftJoin(table, on...))
|
||||
}
|
||||
|
||||
func (c contentAccessQueryDo) RightJoin(table schema.Tabler, on ...field.Expr) *contentAccessQueryDo {
|
||||
return c.withDO(c.DO.RightJoin(table, on...))
|
||||
}
|
||||
|
||||
func (c contentAccessQueryDo) Group(cols ...field.Expr) *contentAccessQueryDo {
|
||||
return c.withDO(c.DO.Group(cols...))
|
||||
}
|
||||
|
||||
func (c contentAccessQueryDo) Having(conds ...gen.Condition) *contentAccessQueryDo {
|
||||
return c.withDO(c.DO.Having(conds...))
|
||||
}
|
||||
|
||||
func (c contentAccessQueryDo) Limit(limit int) *contentAccessQueryDo {
|
||||
return c.withDO(c.DO.Limit(limit))
|
||||
}
|
||||
|
||||
func (c contentAccessQueryDo) Offset(offset int) *contentAccessQueryDo {
|
||||
return c.withDO(c.DO.Offset(offset))
|
||||
}
|
||||
|
||||
func (c contentAccessQueryDo) Scopes(funcs ...func(gen.Dao) gen.Dao) *contentAccessQueryDo {
|
||||
return c.withDO(c.DO.Scopes(funcs...))
|
||||
}
|
||||
|
||||
func (c contentAccessQueryDo) Unscoped() *contentAccessQueryDo {
|
||||
return c.withDO(c.DO.Unscoped())
|
||||
}
|
||||
|
||||
func (c contentAccessQueryDo) Create(values ...*ContentAccess) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return c.DO.Create(values)
|
||||
}
|
||||
|
||||
func (c contentAccessQueryDo) CreateInBatches(values []*ContentAccess, 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 contentAccessQueryDo) Save(values ...*ContentAccess) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return c.DO.Save(values)
|
||||
}
|
||||
|
||||
func (c contentAccessQueryDo) First() (*ContentAccess, error) {
|
||||
if result, err := c.DO.First(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*ContentAccess), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (c contentAccessQueryDo) Take() (*ContentAccess, error) {
|
||||
if result, err := c.DO.Take(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*ContentAccess), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (c contentAccessQueryDo) Last() (*ContentAccess, error) {
|
||||
if result, err := c.DO.Last(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*ContentAccess), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (c contentAccessQueryDo) Find() ([]*ContentAccess, error) {
|
||||
result, err := c.DO.Find()
|
||||
return result.([]*ContentAccess), err
|
||||
}
|
||||
|
||||
func (c contentAccessQueryDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*ContentAccess, err error) {
|
||||
buf := make([]*ContentAccess, 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 contentAccessQueryDo) FindInBatches(result *[]*ContentAccess, batchSize int, fc func(tx gen.Dao, batch int) error) error {
|
||||
return c.DO.FindInBatches(result, batchSize, fc)
|
||||
}
|
||||
|
||||
func (c contentAccessQueryDo) Attrs(attrs ...field.AssignExpr) *contentAccessQueryDo {
|
||||
return c.withDO(c.DO.Attrs(attrs...))
|
||||
}
|
||||
|
||||
func (c contentAccessQueryDo) Assign(attrs ...field.AssignExpr) *contentAccessQueryDo {
|
||||
return c.withDO(c.DO.Assign(attrs...))
|
||||
}
|
||||
|
||||
func (c contentAccessQueryDo) Joins(fields ...field.RelationField) *contentAccessQueryDo {
|
||||
for _, _f := range fields {
|
||||
c = *c.withDO(c.DO.Joins(_f))
|
||||
}
|
||||
return &c
|
||||
}
|
||||
|
||||
func (c contentAccessQueryDo) Preload(fields ...field.RelationField) *contentAccessQueryDo {
|
||||
for _, _f := range fields {
|
||||
c = *c.withDO(c.DO.Preload(_f))
|
||||
}
|
||||
return &c
|
||||
}
|
||||
|
||||
func (c contentAccessQueryDo) FirstOrInit() (*ContentAccess, error) {
|
||||
if result, err := c.DO.FirstOrInit(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*ContentAccess), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (c contentAccessQueryDo) FirstOrCreate() (*ContentAccess, error) {
|
||||
if result, err := c.DO.FirstOrCreate(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*ContentAccess), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (c contentAccessQueryDo) FindByPage(offset int, limit int) (result []*ContentAccess, 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 contentAccessQueryDo) 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 contentAccessQueryDo) Scan(result interface{}) (err error) {
|
||||
return c.DO.Scan(result)
|
||||
}
|
||||
|
||||
func (c contentAccessQueryDo) Delete(models ...*ContentAccess) (result gen.ResultInfo, err error) {
|
||||
return c.DO.Delete(models)
|
||||
}
|
||||
|
||||
// ForceDelete performs a permanent delete (ignores soft-delete) for current scope.
|
||||
func (c contentAccessQueryDo) ForceDelete() (gen.ResultInfo, error) {
|
||||
return c.Unscoped().Delete()
|
||||
}
|
||||
|
||||
// Inc increases the given column by step for current scope.
|
||||
func (c contentAccessQueryDo) Inc(column field.Expr, step int64) (gen.ResultInfo, error) {
|
||||
// column = column + step
|
||||
e := field.NewUnsafeFieldRaw("?+?", column.RawExpr(), step)
|
||||
return c.DO.UpdateColumn(column, e)
|
||||
}
|
||||
|
||||
// Dec decreases the given column by step for current scope.
|
||||
func (c contentAccessQueryDo) Dec(column field.Expr, step int64) (gen.ResultInfo, error) {
|
||||
// column = column - step
|
||||
e := field.NewUnsafeFieldRaw("?-?", column.RawExpr(), step)
|
||||
return c.DO.UpdateColumn(column, e)
|
||||
}
|
||||
|
||||
// Sum returns SUM(column) for current scope.
|
||||
func (c contentAccessQueryDo) Sum(column field.Expr) (float64, error) {
|
||||
var _v float64
|
||||
agg := field.NewUnsafeFieldRaw("SUM(?)", column.RawExpr())
|
||||
if err := c.Select(agg).Scan(&_v); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return _v, nil
|
||||
}
|
||||
|
||||
// Avg returns AVG(column) for current scope.
|
||||
func (c contentAccessQueryDo) Avg(column field.Expr) (float64, error) {
|
||||
var _v float64
|
||||
agg := field.NewUnsafeFieldRaw("AVG(?)", column.RawExpr())
|
||||
if err := c.Select(agg).Scan(&_v); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return _v, nil
|
||||
}
|
||||
|
||||
// Min returns MIN(column) for current scope.
|
||||
func (c contentAccessQueryDo) Min(column field.Expr) (float64, error) {
|
||||
var _v float64
|
||||
agg := field.NewUnsafeFieldRaw("MIN(?)", column.RawExpr())
|
||||
if err := c.Select(agg).Scan(&_v); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return _v, nil
|
||||
}
|
||||
|
||||
// Max returns MAX(column) for current scope.
|
||||
func (c contentAccessQueryDo) Max(column field.Expr) (float64, error) {
|
||||
var _v float64
|
||||
agg := field.NewUnsafeFieldRaw("MAX(?)", column.RawExpr())
|
||||
if err := c.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 (c contentAccessQueryDo) PluckMap(key, val field.Expr) (map[interface{}]interface{}, error) {
|
||||
do := c.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 (c contentAccessQueryDo) Exists(conds ...gen.Condition) (bool, error) {
|
||||
cnt, err := c.Where(conds...).Count()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
return cnt > 0, nil
|
||||
}
|
||||
|
||||
// PluckIDs returns all primary key values under current scope.
|
||||
func (c contentAccessQueryDo) PluckIDs() ([]int64, error) {
|
||||
ids := make([]int64, 0, 16)
|
||||
pk := field.NewInt64(c.TableName(), "id")
|
||||
if err := c.DO.Pluck(pk, &ids); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return ids, nil
|
||||
}
|
||||
|
||||
// GetByID finds a single record by primary key.
|
||||
func (c contentAccessQueryDo) GetByID(id int64) (*ContentAccess, error) {
|
||||
pk := field.NewInt64(c.TableName(), "id")
|
||||
return c.Where(pk.Eq(id)).First()
|
||||
}
|
||||
|
||||
// GetByIDs finds records by primary key list.
|
||||
func (c contentAccessQueryDo) GetByIDs(ids ...int64) ([]*ContentAccess, error) {
|
||||
if len(ids) == 0 {
|
||||
return []*ContentAccess{}, nil
|
||||
}
|
||||
pk := field.NewInt64(c.TableName(), "id")
|
||||
return c.Where(pk.In(ids...)).Find()
|
||||
}
|
||||
|
||||
// DeleteByID deletes records by primary key.
|
||||
func (c contentAccessQueryDo) DeleteByID(id int64) (gen.ResultInfo, error) {
|
||||
pk := field.NewInt64(c.TableName(), "id")
|
||||
return c.Where(pk.Eq(id)).Delete()
|
||||
}
|
||||
|
||||
// DeleteByIDs deletes records by a list of primary keys.
|
||||
func (c contentAccessQueryDo) DeleteByIDs(ids ...int64) (gen.ResultInfo, error) {
|
||||
if len(ids) == 0 {
|
||||
return gen.ResultInfo{RowsAffected: 0, Error: nil}, nil
|
||||
}
|
||||
pk := field.NewInt64(c.TableName(), "id")
|
||||
return c.Where(pk.In(ids...)).Delete()
|
||||
}
|
||||
|
||||
func (c *contentAccessQueryDo) withDO(do gen.Dao) *contentAccessQueryDo {
|
||||
c.DO = *do.(*gen.DO)
|
||||
return c
|
||||
}
|
||||
65
backend/database/models/content_assets.gen.go
Normal file
65
backend/database/models/content_assets.gen.go
Normal file
@@ -0,0 +1,65 @@
|
||||
// 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"
|
||||
"time"
|
||||
|
||||
"quyun/v2/pkg/consts"
|
||||
|
||||
"go.ipao.vip/gen"
|
||||
)
|
||||
|
||||
const TableNameContentAsset = "content_assets"
|
||||
|
||||
// ContentAsset mapped from table <content_assets>
|
||||
type ContentAsset struct {
|
||||
ID int64 `gorm:"column:id;type:bigint;primaryKey;autoIncrement:true" json:"id"`
|
||||
TenantID int64 `gorm:"column:tenant_id;type:bigint;not null" json:"tenant_id"`
|
||||
UserID int64 `gorm:"column:user_id;type:bigint;not null" json:"user_id"`
|
||||
ContentID int64 `gorm:"column:content_id;type:bigint;not null" json:"content_id"`
|
||||
AssetID int64 `gorm:"column:asset_id;type:bigint;not null" json:"asset_id"`
|
||||
Role consts.ContentAssetRole `gorm:"column:role;type:character varying(32);not null;default:main" json:"role"`
|
||||
Sort int32 `gorm:"column:sort;type:integer;not null" json:"sort"`
|
||||
CreatedAt time.Time `gorm:"column:created_at;type:timestamp with time zone;not null;default:now()" json:"created_at"`
|
||||
UpdatedAt time.Time `gorm:"column:updated_at;type:timestamp with time zone;not null;default:now()" json:"updated_at"`
|
||||
}
|
||||
|
||||
// Quick operations without importing query package
|
||||
// Update applies changed fields to the database using the default DB.
|
||||
func (m *ContentAsset) Update(ctx context.Context) (gen.ResultInfo, error) {
|
||||
return Q.ContentAsset.WithContext(ctx).Updates(m)
|
||||
}
|
||||
|
||||
// Save upserts the model using the default DB.
|
||||
func (m *ContentAsset) Save(ctx context.Context) error {
|
||||
return Q.ContentAsset.WithContext(ctx).Save(m)
|
||||
}
|
||||
|
||||
// Create inserts the model using the default DB.
|
||||
func (m *ContentAsset) Create(ctx context.Context) error {
|
||||
return Q.ContentAsset.WithContext(ctx).Create(m)
|
||||
}
|
||||
|
||||
// Delete removes the row represented by the model using the default DB.
|
||||
func (m *ContentAsset) Delete(ctx context.Context) (gen.ResultInfo, error) {
|
||||
return Q.ContentAsset.WithContext(ctx).Delete(m)
|
||||
}
|
||||
|
||||
// ForceDelete permanently deletes the row (ignores soft delete) using the default DB.
|
||||
func (m *ContentAsset) ForceDelete(ctx context.Context) (gen.ResultInfo, error) {
|
||||
return Q.ContentAsset.WithContext(ctx).Unscoped().Delete(m)
|
||||
}
|
||||
|
||||
// Reload reloads the model from database by its primary key and overwrites current fields.
|
||||
func (m *ContentAsset) Reload(ctx context.Context) error {
|
||||
fresh, err := Q.ContentAsset.WithContext(ctx).GetByID(m.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
*m = *fresh
|
||||
return nil
|
||||
}
|
||||
493
backend/database/models/content_assets.query.gen.go
Normal file
493
backend/database/models/content_assets.query.gen.go
Normal file
@@ -0,0 +1,493 @@
|
||||
// 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 newContentAsset(db *gorm.DB, opts ...gen.DOOption) contentAssetQuery {
|
||||
_contentAssetQuery := contentAssetQuery{}
|
||||
|
||||
_contentAssetQuery.contentAssetQueryDo.UseDB(db, opts...)
|
||||
_contentAssetQuery.contentAssetQueryDo.UseModel(&ContentAsset{})
|
||||
|
||||
tableName := _contentAssetQuery.contentAssetQueryDo.TableName()
|
||||
_contentAssetQuery.ALL = field.NewAsterisk(tableName)
|
||||
_contentAssetQuery.ID = field.NewInt64(tableName, "id")
|
||||
_contentAssetQuery.TenantID = field.NewInt64(tableName, "tenant_id")
|
||||
_contentAssetQuery.UserID = field.NewInt64(tableName, "user_id")
|
||||
_contentAssetQuery.ContentID = field.NewInt64(tableName, "content_id")
|
||||
_contentAssetQuery.AssetID = field.NewInt64(tableName, "asset_id")
|
||||
_contentAssetQuery.Role = field.NewField(tableName, "role")
|
||||
_contentAssetQuery.Sort = field.NewInt32(tableName, "sort")
|
||||
_contentAssetQuery.CreatedAt = field.NewTime(tableName, "created_at")
|
||||
_contentAssetQuery.UpdatedAt = field.NewTime(tableName, "updated_at")
|
||||
|
||||
_contentAssetQuery.fillFieldMap()
|
||||
|
||||
return _contentAssetQuery
|
||||
}
|
||||
|
||||
type contentAssetQuery struct {
|
||||
contentAssetQueryDo contentAssetQueryDo
|
||||
|
||||
ALL field.Asterisk
|
||||
ID field.Int64
|
||||
TenantID field.Int64
|
||||
UserID field.Int64
|
||||
ContentID field.Int64
|
||||
AssetID field.Int64
|
||||
Role field.Field
|
||||
Sort field.Int32
|
||||
CreatedAt field.Time
|
||||
UpdatedAt field.Time
|
||||
|
||||
fieldMap map[string]field.Expr
|
||||
}
|
||||
|
||||
func (c contentAssetQuery) Table(newTableName string) *contentAssetQuery {
|
||||
c.contentAssetQueryDo.UseTable(newTableName)
|
||||
return c.updateTableName(newTableName)
|
||||
}
|
||||
|
||||
func (c contentAssetQuery) As(alias string) *contentAssetQuery {
|
||||
c.contentAssetQueryDo.DO = *(c.contentAssetQueryDo.As(alias).(*gen.DO))
|
||||
return c.updateTableName(alias)
|
||||
}
|
||||
|
||||
func (c *contentAssetQuery) updateTableName(table string) *contentAssetQuery {
|
||||
c.ALL = field.NewAsterisk(table)
|
||||
c.ID = field.NewInt64(table, "id")
|
||||
c.TenantID = field.NewInt64(table, "tenant_id")
|
||||
c.UserID = field.NewInt64(table, "user_id")
|
||||
c.ContentID = field.NewInt64(table, "content_id")
|
||||
c.AssetID = field.NewInt64(table, "asset_id")
|
||||
c.Role = field.NewField(table, "role")
|
||||
c.Sort = field.NewInt32(table, "sort")
|
||||
c.CreatedAt = field.NewTime(table, "created_at")
|
||||
c.UpdatedAt = field.NewTime(table, "updated_at")
|
||||
|
||||
c.fillFieldMap()
|
||||
|
||||
return c
|
||||
}
|
||||
|
||||
func (c *contentAssetQuery) QueryContext(ctx context.Context) (*contentAssetQuery, *contentAssetQueryDo) {
|
||||
return c, c.contentAssetQueryDo.WithContext(ctx)
|
||||
}
|
||||
|
||||
func (c *contentAssetQuery) WithContext(ctx context.Context) *contentAssetQueryDo {
|
||||
return c.contentAssetQueryDo.WithContext(ctx)
|
||||
}
|
||||
|
||||
func (c contentAssetQuery) TableName() string { return c.contentAssetQueryDo.TableName() }
|
||||
|
||||
func (c contentAssetQuery) Alias() string { return c.contentAssetQueryDo.Alias() }
|
||||
|
||||
func (c contentAssetQuery) Columns(cols ...field.Expr) gen.Columns {
|
||||
return c.contentAssetQueryDo.Columns(cols...)
|
||||
}
|
||||
|
||||
func (c *contentAssetQuery) 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 *contentAssetQuery) fillFieldMap() {
|
||||
c.fieldMap = make(map[string]field.Expr, 9)
|
||||
c.fieldMap["id"] = c.ID
|
||||
c.fieldMap["tenant_id"] = c.TenantID
|
||||
c.fieldMap["user_id"] = c.UserID
|
||||
c.fieldMap["content_id"] = c.ContentID
|
||||
c.fieldMap["asset_id"] = c.AssetID
|
||||
c.fieldMap["role"] = c.Role
|
||||
c.fieldMap["sort"] = c.Sort
|
||||
c.fieldMap["created_at"] = c.CreatedAt
|
||||
c.fieldMap["updated_at"] = c.UpdatedAt
|
||||
}
|
||||
|
||||
func (c contentAssetQuery) clone(db *gorm.DB) contentAssetQuery {
|
||||
c.contentAssetQueryDo.ReplaceConnPool(db.Statement.ConnPool)
|
||||
return c
|
||||
}
|
||||
|
||||
func (c contentAssetQuery) replaceDB(db *gorm.DB) contentAssetQuery {
|
||||
c.contentAssetQueryDo.ReplaceDB(db)
|
||||
return c
|
||||
}
|
||||
|
||||
type contentAssetQueryDo struct{ gen.DO }
|
||||
|
||||
func (c contentAssetQueryDo) Debug() *contentAssetQueryDo {
|
||||
return c.withDO(c.DO.Debug())
|
||||
}
|
||||
|
||||
func (c contentAssetQueryDo) WithContext(ctx context.Context) *contentAssetQueryDo {
|
||||
return c.withDO(c.DO.WithContext(ctx))
|
||||
}
|
||||
|
||||
func (c contentAssetQueryDo) ReadDB() *contentAssetQueryDo {
|
||||
return c.Clauses(dbresolver.Read)
|
||||
}
|
||||
|
||||
func (c contentAssetQueryDo) WriteDB() *contentAssetQueryDo {
|
||||
return c.Clauses(dbresolver.Write)
|
||||
}
|
||||
|
||||
func (c contentAssetQueryDo) Session(config *gorm.Session) *contentAssetQueryDo {
|
||||
return c.withDO(c.DO.Session(config))
|
||||
}
|
||||
|
||||
func (c contentAssetQueryDo) Clauses(conds ...clause.Expression) *contentAssetQueryDo {
|
||||
return c.withDO(c.DO.Clauses(conds...))
|
||||
}
|
||||
|
||||
func (c contentAssetQueryDo) Returning(value interface{}, columns ...string) *contentAssetQueryDo {
|
||||
return c.withDO(c.DO.Returning(value, columns...))
|
||||
}
|
||||
|
||||
func (c contentAssetQueryDo) Not(conds ...gen.Condition) *contentAssetQueryDo {
|
||||
return c.withDO(c.DO.Not(conds...))
|
||||
}
|
||||
|
||||
func (c contentAssetQueryDo) Or(conds ...gen.Condition) *contentAssetQueryDo {
|
||||
return c.withDO(c.DO.Or(conds...))
|
||||
}
|
||||
|
||||
func (c contentAssetQueryDo) Select(conds ...field.Expr) *contentAssetQueryDo {
|
||||
return c.withDO(c.DO.Select(conds...))
|
||||
}
|
||||
|
||||
func (c contentAssetQueryDo) Where(conds ...gen.Condition) *contentAssetQueryDo {
|
||||
return c.withDO(c.DO.Where(conds...))
|
||||
}
|
||||
|
||||
func (c contentAssetQueryDo) Order(conds ...field.Expr) *contentAssetQueryDo {
|
||||
return c.withDO(c.DO.Order(conds...))
|
||||
}
|
||||
|
||||
func (c contentAssetQueryDo) Distinct(cols ...field.Expr) *contentAssetQueryDo {
|
||||
return c.withDO(c.DO.Distinct(cols...))
|
||||
}
|
||||
|
||||
func (c contentAssetQueryDo) Omit(cols ...field.Expr) *contentAssetQueryDo {
|
||||
return c.withDO(c.DO.Omit(cols...))
|
||||
}
|
||||
|
||||
func (c contentAssetQueryDo) Join(table schema.Tabler, on ...field.Expr) *contentAssetQueryDo {
|
||||
return c.withDO(c.DO.Join(table, on...))
|
||||
}
|
||||
|
||||
func (c contentAssetQueryDo) LeftJoin(table schema.Tabler, on ...field.Expr) *contentAssetQueryDo {
|
||||
return c.withDO(c.DO.LeftJoin(table, on...))
|
||||
}
|
||||
|
||||
func (c contentAssetQueryDo) RightJoin(table schema.Tabler, on ...field.Expr) *contentAssetQueryDo {
|
||||
return c.withDO(c.DO.RightJoin(table, on...))
|
||||
}
|
||||
|
||||
func (c contentAssetQueryDo) Group(cols ...field.Expr) *contentAssetQueryDo {
|
||||
return c.withDO(c.DO.Group(cols...))
|
||||
}
|
||||
|
||||
func (c contentAssetQueryDo) Having(conds ...gen.Condition) *contentAssetQueryDo {
|
||||
return c.withDO(c.DO.Having(conds...))
|
||||
}
|
||||
|
||||
func (c contentAssetQueryDo) Limit(limit int) *contentAssetQueryDo {
|
||||
return c.withDO(c.DO.Limit(limit))
|
||||
}
|
||||
|
||||
func (c contentAssetQueryDo) Offset(offset int) *contentAssetQueryDo {
|
||||
return c.withDO(c.DO.Offset(offset))
|
||||
}
|
||||
|
||||
func (c contentAssetQueryDo) Scopes(funcs ...func(gen.Dao) gen.Dao) *contentAssetQueryDo {
|
||||
return c.withDO(c.DO.Scopes(funcs...))
|
||||
}
|
||||
|
||||
func (c contentAssetQueryDo) Unscoped() *contentAssetQueryDo {
|
||||
return c.withDO(c.DO.Unscoped())
|
||||
}
|
||||
|
||||
func (c contentAssetQueryDo) Create(values ...*ContentAsset) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return c.DO.Create(values)
|
||||
}
|
||||
|
||||
func (c contentAssetQueryDo) CreateInBatches(values []*ContentAsset, 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 contentAssetQueryDo) Save(values ...*ContentAsset) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return c.DO.Save(values)
|
||||
}
|
||||
|
||||
func (c contentAssetQueryDo) First() (*ContentAsset, error) {
|
||||
if result, err := c.DO.First(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*ContentAsset), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (c contentAssetQueryDo) Take() (*ContentAsset, error) {
|
||||
if result, err := c.DO.Take(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*ContentAsset), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (c contentAssetQueryDo) Last() (*ContentAsset, error) {
|
||||
if result, err := c.DO.Last(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*ContentAsset), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (c contentAssetQueryDo) Find() ([]*ContentAsset, error) {
|
||||
result, err := c.DO.Find()
|
||||
return result.([]*ContentAsset), err
|
||||
}
|
||||
|
||||
func (c contentAssetQueryDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*ContentAsset, err error) {
|
||||
buf := make([]*ContentAsset, 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 contentAssetQueryDo) FindInBatches(result *[]*ContentAsset, batchSize int, fc func(tx gen.Dao, batch int) error) error {
|
||||
return c.DO.FindInBatches(result, batchSize, fc)
|
||||
}
|
||||
|
||||
func (c contentAssetQueryDo) Attrs(attrs ...field.AssignExpr) *contentAssetQueryDo {
|
||||
return c.withDO(c.DO.Attrs(attrs...))
|
||||
}
|
||||
|
||||
func (c contentAssetQueryDo) Assign(attrs ...field.AssignExpr) *contentAssetQueryDo {
|
||||
return c.withDO(c.DO.Assign(attrs...))
|
||||
}
|
||||
|
||||
func (c contentAssetQueryDo) Joins(fields ...field.RelationField) *contentAssetQueryDo {
|
||||
for _, _f := range fields {
|
||||
c = *c.withDO(c.DO.Joins(_f))
|
||||
}
|
||||
return &c
|
||||
}
|
||||
|
||||
func (c contentAssetQueryDo) Preload(fields ...field.RelationField) *contentAssetQueryDo {
|
||||
for _, _f := range fields {
|
||||
c = *c.withDO(c.DO.Preload(_f))
|
||||
}
|
||||
return &c
|
||||
}
|
||||
|
||||
func (c contentAssetQueryDo) FirstOrInit() (*ContentAsset, error) {
|
||||
if result, err := c.DO.FirstOrInit(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*ContentAsset), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (c contentAssetQueryDo) FirstOrCreate() (*ContentAsset, error) {
|
||||
if result, err := c.DO.FirstOrCreate(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*ContentAsset), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (c contentAssetQueryDo) FindByPage(offset int, limit int) (result []*ContentAsset, 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 contentAssetQueryDo) 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 contentAssetQueryDo) Scan(result interface{}) (err error) {
|
||||
return c.DO.Scan(result)
|
||||
}
|
||||
|
||||
func (c contentAssetQueryDo) Delete(models ...*ContentAsset) (result gen.ResultInfo, err error) {
|
||||
return c.DO.Delete(models)
|
||||
}
|
||||
|
||||
// ForceDelete performs a permanent delete (ignores soft-delete) for current scope.
|
||||
func (c contentAssetQueryDo) ForceDelete() (gen.ResultInfo, error) {
|
||||
return c.Unscoped().Delete()
|
||||
}
|
||||
|
||||
// Inc increases the given column by step for current scope.
|
||||
func (c contentAssetQueryDo) Inc(column field.Expr, step int64) (gen.ResultInfo, error) {
|
||||
// column = column + step
|
||||
e := field.NewUnsafeFieldRaw("?+?", column.RawExpr(), step)
|
||||
return c.DO.UpdateColumn(column, e)
|
||||
}
|
||||
|
||||
// Dec decreases the given column by step for current scope.
|
||||
func (c contentAssetQueryDo) Dec(column field.Expr, step int64) (gen.ResultInfo, error) {
|
||||
// column = column - step
|
||||
e := field.NewUnsafeFieldRaw("?-?", column.RawExpr(), step)
|
||||
return c.DO.UpdateColumn(column, e)
|
||||
}
|
||||
|
||||
// Sum returns SUM(column) for current scope.
|
||||
func (c contentAssetQueryDo) Sum(column field.Expr) (float64, error) {
|
||||
var _v float64
|
||||
agg := field.NewUnsafeFieldRaw("SUM(?)", column.RawExpr())
|
||||
if err := c.Select(agg).Scan(&_v); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return _v, nil
|
||||
}
|
||||
|
||||
// Avg returns AVG(column) for current scope.
|
||||
func (c contentAssetQueryDo) Avg(column field.Expr) (float64, error) {
|
||||
var _v float64
|
||||
agg := field.NewUnsafeFieldRaw("AVG(?)", column.RawExpr())
|
||||
if err := c.Select(agg).Scan(&_v); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return _v, nil
|
||||
}
|
||||
|
||||
// Min returns MIN(column) for current scope.
|
||||
func (c contentAssetQueryDo) Min(column field.Expr) (float64, error) {
|
||||
var _v float64
|
||||
agg := field.NewUnsafeFieldRaw("MIN(?)", column.RawExpr())
|
||||
if err := c.Select(agg).Scan(&_v); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return _v, nil
|
||||
}
|
||||
|
||||
// Max returns MAX(column) for current scope.
|
||||
func (c contentAssetQueryDo) Max(column field.Expr) (float64, error) {
|
||||
var _v float64
|
||||
agg := field.NewUnsafeFieldRaw("MAX(?)", column.RawExpr())
|
||||
if err := c.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 (c contentAssetQueryDo) PluckMap(key, val field.Expr) (map[interface{}]interface{}, error) {
|
||||
do := c.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 (c contentAssetQueryDo) Exists(conds ...gen.Condition) (bool, error) {
|
||||
cnt, err := c.Where(conds...).Count()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
return cnt > 0, nil
|
||||
}
|
||||
|
||||
// PluckIDs returns all primary key values under current scope.
|
||||
func (c contentAssetQueryDo) PluckIDs() ([]int64, error) {
|
||||
ids := make([]int64, 0, 16)
|
||||
pk := field.NewInt64(c.TableName(), "id")
|
||||
if err := c.DO.Pluck(pk, &ids); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return ids, nil
|
||||
}
|
||||
|
||||
// GetByID finds a single record by primary key.
|
||||
func (c contentAssetQueryDo) GetByID(id int64) (*ContentAsset, error) {
|
||||
pk := field.NewInt64(c.TableName(), "id")
|
||||
return c.Where(pk.Eq(id)).First()
|
||||
}
|
||||
|
||||
// GetByIDs finds records by primary key list.
|
||||
func (c contentAssetQueryDo) GetByIDs(ids ...int64) ([]*ContentAsset, error) {
|
||||
if len(ids) == 0 {
|
||||
return []*ContentAsset{}, nil
|
||||
}
|
||||
pk := field.NewInt64(c.TableName(), "id")
|
||||
return c.Where(pk.In(ids...)).Find()
|
||||
}
|
||||
|
||||
// DeleteByID deletes records by primary key.
|
||||
func (c contentAssetQueryDo) DeleteByID(id int64) (gen.ResultInfo, error) {
|
||||
pk := field.NewInt64(c.TableName(), "id")
|
||||
return c.Where(pk.Eq(id)).Delete()
|
||||
}
|
||||
|
||||
// DeleteByIDs deletes records by a list of primary keys.
|
||||
func (c contentAssetQueryDo) DeleteByIDs(ids ...int64) (gen.ResultInfo, error) {
|
||||
if len(ids) == 0 {
|
||||
return gen.ResultInfo{RowsAffected: 0, Error: nil}, nil
|
||||
}
|
||||
pk := field.NewInt64(c.TableName(), "id")
|
||||
return c.Where(pk.In(ids...)).Delete()
|
||||
}
|
||||
|
||||
func (c *contentAssetQueryDo) withDO(do gen.Dao) *contentAssetQueryDo {
|
||||
c.DO = *do.(*gen.DO)
|
||||
return c
|
||||
}
|
||||
68
backend/database/models/content_prices.gen.go
Normal file
68
backend/database/models/content_prices.gen.go
Normal file
@@ -0,0 +1,68 @@
|
||||
// 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"
|
||||
"time"
|
||||
|
||||
"quyun/v2/pkg/consts"
|
||||
|
||||
"go.ipao.vip/gen"
|
||||
)
|
||||
|
||||
const TableNameContentPrice = "content_prices"
|
||||
|
||||
// ContentPrice mapped from table <content_prices>
|
||||
type ContentPrice struct {
|
||||
ID int64 `gorm:"column:id;type:bigint;primaryKey;autoIncrement:true" json:"id"`
|
||||
TenantID int64 `gorm:"column:tenant_id;type:bigint;not null" json:"tenant_id"`
|
||||
UserID int64 `gorm:"column:user_id;type:bigint;not null" json:"user_id"`
|
||||
ContentID int64 `gorm:"column:content_id;type:bigint;not null" json:"content_id"`
|
||||
Currency consts.Currency `gorm:"column:currency;type:character varying(16);not null;default:CNY" json:"currency"`
|
||||
PriceAmount int64 `gorm:"column:price_amount;type:bigint;not null" json:"price_amount"`
|
||||
DiscountType consts.DiscountType `gorm:"column:discount_type;type:character varying(16);not null;default:none" json:"discount_type"`
|
||||
DiscountValue int64 `gorm:"column:discount_value;type:bigint;not null" json:"discount_value"`
|
||||
DiscountStartAt time.Time `gorm:"column:discount_start_at;type:timestamp with time zone" json:"discount_start_at"`
|
||||
DiscountEndAt time.Time `gorm:"column:discount_end_at;type:timestamp with time zone" json:"discount_end_at"`
|
||||
CreatedAt time.Time `gorm:"column:created_at;type:timestamp with time zone;not null;default:now()" json:"created_at"`
|
||||
UpdatedAt time.Time `gorm:"column:updated_at;type:timestamp with time zone;not null;default:now()" json:"updated_at"`
|
||||
}
|
||||
|
||||
// Quick operations without importing query package
|
||||
// Update applies changed fields to the database using the default DB.
|
||||
func (m *ContentPrice) Update(ctx context.Context) (gen.ResultInfo, error) {
|
||||
return Q.ContentPrice.WithContext(ctx).Updates(m)
|
||||
}
|
||||
|
||||
// Save upserts the model using the default DB.
|
||||
func (m *ContentPrice) Save(ctx context.Context) error {
|
||||
return Q.ContentPrice.WithContext(ctx).Save(m)
|
||||
}
|
||||
|
||||
// Create inserts the model using the default DB.
|
||||
func (m *ContentPrice) Create(ctx context.Context) error {
|
||||
return Q.ContentPrice.WithContext(ctx).Create(m)
|
||||
}
|
||||
|
||||
// Delete removes the row represented by the model using the default DB.
|
||||
func (m *ContentPrice) Delete(ctx context.Context) (gen.ResultInfo, error) {
|
||||
return Q.ContentPrice.WithContext(ctx).Delete(m)
|
||||
}
|
||||
|
||||
// ForceDelete permanently deletes the row (ignores soft delete) using the default DB.
|
||||
func (m *ContentPrice) ForceDelete(ctx context.Context) (gen.ResultInfo, error) {
|
||||
return Q.ContentPrice.WithContext(ctx).Unscoped().Delete(m)
|
||||
}
|
||||
|
||||
// Reload reloads the model from database by its primary key and overwrites current fields.
|
||||
func (m *ContentPrice) Reload(ctx context.Context) error {
|
||||
fresh, err := Q.ContentPrice.WithContext(ctx).GetByID(m.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
*m = *fresh
|
||||
return nil
|
||||
}
|
||||
505
backend/database/models/content_prices.query.gen.go
Normal file
505
backend/database/models/content_prices.query.gen.go
Normal file
@@ -0,0 +1,505 @@
|
||||
// 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 newContentPrice(db *gorm.DB, opts ...gen.DOOption) contentPriceQuery {
|
||||
_contentPriceQuery := contentPriceQuery{}
|
||||
|
||||
_contentPriceQuery.contentPriceQueryDo.UseDB(db, opts...)
|
||||
_contentPriceQuery.contentPriceQueryDo.UseModel(&ContentPrice{})
|
||||
|
||||
tableName := _contentPriceQuery.contentPriceQueryDo.TableName()
|
||||
_contentPriceQuery.ALL = field.NewAsterisk(tableName)
|
||||
_contentPriceQuery.ID = field.NewInt64(tableName, "id")
|
||||
_contentPriceQuery.TenantID = field.NewInt64(tableName, "tenant_id")
|
||||
_contentPriceQuery.UserID = field.NewInt64(tableName, "user_id")
|
||||
_contentPriceQuery.ContentID = field.NewInt64(tableName, "content_id")
|
||||
_contentPriceQuery.Currency = field.NewField(tableName, "currency")
|
||||
_contentPriceQuery.PriceAmount = field.NewInt64(tableName, "price_amount")
|
||||
_contentPriceQuery.DiscountType = field.NewField(tableName, "discount_type")
|
||||
_contentPriceQuery.DiscountValue = field.NewInt64(tableName, "discount_value")
|
||||
_contentPriceQuery.DiscountStartAt = field.NewTime(tableName, "discount_start_at")
|
||||
_contentPriceQuery.DiscountEndAt = field.NewTime(tableName, "discount_end_at")
|
||||
_contentPriceQuery.CreatedAt = field.NewTime(tableName, "created_at")
|
||||
_contentPriceQuery.UpdatedAt = field.NewTime(tableName, "updated_at")
|
||||
|
||||
_contentPriceQuery.fillFieldMap()
|
||||
|
||||
return _contentPriceQuery
|
||||
}
|
||||
|
||||
type contentPriceQuery struct {
|
||||
contentPriceQueryDo contentPriceQueryDo
|
||||
|
||||
ALL field.Asterisk
|
||||
ID field.Int64
|
||||
TenantID field.Int64
|
||||
UserID field.Int64
|
||||
ContentID field.Int64
|
||||
Currency field.Field
|
||||
PriceAmount field.Int64
|
||||
DiscountType field.Field
|
||||
DiscountValue field.Int64
|
||||
DiscountStartAt field.Time
|
||||
DiscountEndAt field.Time
|
||||
CreatedAt field.Time
|
||||
UpdatedAt field.Time
|
||||
|
||||
fieldMap map[string]field.Expr
|
||||
}
|
||||
|
||||
func (c contentPriceQuery) Table(newTableName string) *contentPriceQuery {
|
||||
c.contentPriceQueryDo.UseTable(newTableName)
|
||||
return c.updateTableName(newTableName)
|
||||
}
|
||||
|
||||
func (c contentPriceQuery) As(alias string) *contentPriceQuery {
|
||||
c.contentPriceQueryDo.DO = *(c.contentPriceQueryDo.As(alias).(*gen.DO))
|
||||
return c.updateTableName(alias)
|
||||
}
|
||||
|
||||
func (c *contentPriceQuery) updateTableName(table string) *contentPriceQuery {
|
||||
c.ALL = field.NewAsterisk(table)
|
||||
c.ID = field.NewInt64(table, "id")
|
||||
c.TenantID = field.NewInt64(table, "tenant_id")
|
||||
c.UserID = field.NewInt64(table, "user_id")
|
||||
c.ContentID = field.NewInt64(table, "content_id")
|
||||
c.Currency = field.NewField(table, "currency")
|
||||
c.PriceAmount = field.NewInt64(table, "price_amount")
|
||||
c.DiscountType = field.NewField(table, "discount_type")
|
||||
c.DiscountValue = field.NewInt64(table, "discount_value")
|
||||
c.DiscountStartAt = field.NewTime(table, "discount_start_at")
|
||||
c.DiscountEndAt = field.NewTime(table, "discount_end_at")
|
||||
c.CreatedAt = field.NewTime(table, "created_at")
|
||||
c.UpdatedAt = field.NewTime(table, "updated_at")
|
||||
|
||||
c.fillFieldMap()
|
||||
|
||||
return c
|
||||
}
|
||||
|
||||
func (c *contentPriceQuery) QueryContext(ctx context.Context) (*contentPriceQuery, *contentPriceQueryDo) {
|
||||
return c, c.contentPriceQueryDo.WithContext(ctx)
|
||||
}
|
||||
|
||||
func (c *contentPriceQuery) WithContext(ctx context.Context) *contentPriceQueryDo {
|
||||
return c.contentPriceQueryDo.WithContext(ctx)
|
||||
}
|
||||
|
||||
func (c contentPriceQuery) TableName() string { return c.contentPriceQueryDo.TableName() }
|
||||
|
||||
func (c contentPriceQuery) Alias() string { return c.contentPriceQueryDo.Alias() }
|
||||
|
||||
func (c contentPriceQuery) Columns(cols ...field.Expr) gen.Columns {
|
||||
return c.contentPriceQueryDo.Columns(cols...)
|
||||
}
|
||||
|
||||
func (c *contentPriceQuery) 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 *contentPriceQuery) fillFieldMap() {
|
||||
c.fieldMap = make(map[string]field.Expr, 12)
|
||||
c.fieldMap["id"] = c.ID
|
||||
c.fieldMap["tenant_id"] = c.TenantID
|
||||
c.fieldMap["user_id"] = c.UserID
|
||||
c.fieldMap["content_id"] = c.ContentID
|
||||
c.fieldMap["currency"] = c.Currency
|
||||
c.fieldMap["price_amount"] = c.PriceAmount
|
||||
c.fieldMap["discount_type"] = c.DiscountType
|
||||
c.fieldMap["discount_value"] = c.DiscountValue
|
||||
c.fieldMap["discount_start_at"] = c.DiscountStartAt
|
||||
c.fieldMap["discount_end_at"] = c.DiscountEndAt
|
||||
c.fieldMap["created_at"] = c.CreatedAt
|
||||
c.fieldMap["updated_at"] = c.UpdatedAt
|
||||
}
|
||||
|
||||
func (c contentPriceQuery) clone(db *gorm.DB) contentPriceQuery {
|
||||
c.contentPriceQueryDo.ReplaceConnPool(db.Statement.ConnPool)
|
||||
return c
|
||||
}
|
||||
|
||||
func (c contentPriceQuery) replaceDB(db *gorm.DB) contentPriceQuery {
|
||||
c.contentPriceQueryDo.ReplaceDB(db)
|
||||
return c
|
||||
}
|
||||
|
||||
type contentPriceQueryDo struct{ gen.DO }
|
||||
|
||||
func (c contentPriceQueryDo) Debug() *contentPriceQueryDo {
|
||||
return c.withDO(c.DO.Debug())
|
||||
}
|
||||
|
||||
func (c contentPriceQueryDo) WithContext(ctx context.Context) *contentPriceQueryDo {
|
||||
return c.withDO(c.DO.WithContext(ctx))
|
||||
}
|
||||
|
||||
func (c contentPriceQueryDo) ReadDB() *contentPriceQueryDo {
|
||||
return c.Clauses(dbresolver.Read)
|
||||
}
|
||||
|
||||
func (c contentPriceQueryDo) WriteDB() *contentPriceQueryDo {
|
||||
return c.Clauses(dbresolver.Write)
|
||||
}
|
||||
|
||||
func (c contentPriceQueryDo) Session(config *gorm.Session) *contentPriceQueryDo {
|
||||
return c.withDO(c.DO.Session(config))
|
||||
}
|
||||
|
||||
func (c contentPriceQueryDo) Clauses(conds ...clause.Expression) *contentPriceQueryDo {
|
||||
return c.withDO(c.DO.Clauses(conds...))
|
||||
}
|
||||
|
||||
func (c contentPriceQueryDo) Returning(value interface{}, columns ...string) *contentPriceQueryDo {
|
||||
return c.withDO(c.DO.Returning(value, columns...))
|
||||
}
|
||||
|
||||
func (c contentPriceQueryDo) Not(conds ...gen.Condition) *contentPriceQueryDo {
|
||||
return c.withDO(c.DO.Not(conds...))
|
||||
}
|
||||
|
||||
func (c contentPriceQueryDo) Or(conds ...gen.Condition) *contentPriceQueryDo {
|
||||
return c.withDO(c.DO.Or(conds...))
|
||||
}
|
||||
|
||||
func (c contentPriceQueryDo) Select(conds ...field.Expr) *contentPriceQueryDo {
|
||||
return c.withDO(c.DO.Select(conds...))
|
||||
}
|
||||
|
||||
func (c contentPriceQueryDo) Where(conds ...gen.Condition) *contentPriceQueryDo {
|
||||
return c.withDO(c.DO.Where(conds...))
|
||||
}
|
||||
|
||||
func (c contentPriceQueryDo) Order(conds ...field.Expr) *contentPriceQueryDo {
|
||||
return c.withDO(c.DO.Order(conds...))
|
||||
}
|
||||
|
||||
func (c contentPriceQueryDo) Distinct(cols ...field.Expr) *contentPriceQueryDo {
|
||||
return c.withDO(c.DO.Distinct(cols...))
|
||||
}
|
||||
|
||||
func (c contentPriceQueryDo) Omit(cols ...field.Expr) *contentPriceQueryDo {
|
||||
return c.withDO(c.DO.Omit(cols...))
|
||||
}
|
||||
|
||||
func (c contentPriceQueryDo) Join(table schema.Tabler, on ...field.Expr) *contentPriceQueryDo {
|
||||
return c.withDO(c.DO.Join(table, on...))
|
||||
}
|
||||
|
||||
func (c contentPriceQueryDo) LeftJoin(table schema.Tabler, on ...field.Expr) *contentPriceQueryDo {
|
||||
return c.withDO(c.DO.LeftJoin(table, on...))
|
||||
}
|
||||
|
||||
func (c contentPriceQueryDo) RightJoin(table schema.Tabler, on ...field.Expr) *contentPriceQueryDo {
|
||||
return c.withDO(c.DO.RightJoin(table, on...))
|
||||
}
|
||||
|
||||
func (c contentPriceQueryDo) Group(cols ...field.Expr) *contentPriceQueryDo {
|
||||
return c.withDO(c.DO.Group(cols...))
|
||||
}
|
||||
|
||||
func (c contentPriceQueryDo) Having(conds ...gen.Condition) *contentPriceQueryDo {
|
||||
return c.withDO(c.DO.Having(conds...))
|
||||
}
|
||||
|
||||
func (c contentPriceQueryDo) Limit(limit int) *contentPriceQueryDo {
|
||||
return c.withDO(c.DO.Limit(limit))
|
||||
}
|
||||
|
||||
func (c contentPriceQueryDo) Offset(offset int) *contentPriceQueryDo {
|
||||
return c.withDO(c.DO.Offset(offset))
|
||||
}
|
||||
|
||||
func (c contentPriceQueryDo) Scopes(funcs ...func(gen.Dao) gen.Dao) *contentPriceQueryDo {
|
||||
return c.withDO(c.DO.Scopes(funcs...))
|
||||
}
|
||||
|
||||
func (c contentPriceQueryDo) Unscoped() *contentPriceQueryDo {
|
||||
return c.withDO(c.DO.Unscoped())
|
||||
}
|
||||
|
||||
func (c contentPriceQueryDo) Create(values ...*ContentPrice) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return c.DO.Create(values)
|
||||
}
|
||||
|
||||
func (c contentPriceQueryDo) CreateInBatches(values []*ContentPrice, 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 contentPriceQueryDo) Save(values ...*ContentPrice) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return c.DO.Save(values)
|
||||
}
|
||||
|
||||
func (c contentPriceQueryDo) First() (*ContentPrice, error) {
|
||||
if result, err := c.DO.First(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*ContentPrice), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (c contentPriceQueryDo) Take() (*ContentPrice, error) {
|
||||
if result, err := c.DO.Take(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*ContentPrice), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (c contentPriceQueryDo) Last() (*ContentPrice, error) {
|
||||
if result, err := c.DO.Last(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*ContentPrice), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (c contentPriceQueryDo) Find() ([]*ContentPrice, error) {
|
||||
result, err := c.DO.Find()
|
||||
return result.([]*ContentPrice), err
|
||||
}
|
||||
|
||||
func (c contentPriceQueryDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*ContentPrice, err error) {
|
||||
buf := make([]*ContentPrice, 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 contentPriceQueryDo) FindInBatches(result *[]*ContentPrice, batchSize int, fc func(tx gen.Dao, batch int) error) error {
|
||||
return c.DO.FindInBatches(result, batchSize, fc)
|
||||
}
|
||||
|
||||
func (c contentPriceQueryDo) Attrs(attrs ...field.AssignExpr) *contentPriceQueryDo {
|
||||
return c.withDO(c.DO.Attrs(attrs...))
|
||||
}
|
||||
|
||||
func (c contentPriceQueryDo) Assign(attrs ...field.AssignExpr) *contentPriceQueryDo {
|
||||
return c.withDO(c.DO.Assign(attrs...))
|
||||
}
|
||||
|
||||
func (c contentPriceQueryDo) Joins(fields ...field.RelationField) *contentPriceQueryDo {
|
||||
for _, _f := range fields {
|
||||
c = *c.withDO(c.DO.Joins(_f))
|
||||
}
|
||||
return &c
|
||||
}
|
||||
|
||||
func (c contentPriceQueryDo) Preload(fields ...field.RelationField) *contentPriceQueryDo {
|
||||
for _, _f := range fields {
|
||||
c = *c.withDO(c.DO.Preload(_f))
|
||||
}
|
||||
return &c
|
||||
}
|
||||
|
||||
func (c contentPriceQueryDo) FirstOrInit() (*ContentPrice, error) {
|
||||
if result, err := c.DO.FirstOrInit(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*ContentPrice), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (c contentPriceQueryDo) FirstOrCreate() (*ContentPrice, error) {
|
||||
if result, err := c.DO.FirstOrCreate(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*ContentPrice), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (c contentPriceQueryDo) FindByPage(offset int, limit int) (result []*ContentPrice, 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 contentPriceQueryDo) 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 contentPriceQueryDo) Scan(result interface{}) (err error) {
|
||||
return c.DO.Scan(result)
|
||||
}
|
||||
|
||||
func (c contentPriceQueryDo) Delete(models ...*ContentPrice) (result gen.ResultInfo, err error) {
|
||||
return c.DO.Delete(models)
|
||||
}
|
||||
|
||||
// ForceDelete performs a permanent delete (ignores soft-delete) for current scope.
|
||||
func (c contentPriceQueryDo) ForceDelete() (gen.ResultInfo, error) {
|
||||
return c.Unscoped().Delete()
|
||||
}
|
||||
|
||||
// Inc increases the given column by step for current scope.
|
||||
func (c contentPriceQueryDo) Inc(column field.Expr, step int64) (gen.ResultInfo, error) {
|
||||
// column = column + step
|
||||
e := field.NewUnsafeFieldRaw("?+?", column.RawExpr(), step)
|
||||
return c.DO.UpdateColumn(column, e)
|
||||
}
|
||||
|
||||
// Dec decreases the given column by step for current scope.
|
||||
func (c contentPriceQueryDo) Dec(column field.Expr, step int64) (gen.ResultInfo, error) {
|
||||
// column = column - step
|
||||
e := field.NewUnsafeFieldRaw("?-?", column.RawExpr(), step)
|
||||
return c.DO.UpdateColumn(column, e)
|
||||
}
|
||||
|
||||
// Sum returns SUM(column) for current scope.
|
||||
func (c contentPriceQueryDo) Sum(column field.Expr) (float64, error) {
|
||||
var _v float64
|
||||
agg := field.NewUnsafeFieldRaw("SUM(?)", column.RawExpr())
|
||||
if err := c.Select(agg).Scan(&_v); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return _v, nil
|
||||
}
|
||||
|
||||
// Avg returns AVG(column) for current scope.
|
||||
func (c contentPriceQueryDo) Avg(column field.Expr) (float64, error) {
|
||||
var _v float64
|
||||
agg := field.NewUnsafeFieldRaw("AVG(?)", column.RawExpr())
|
||||
if err := c.Select(agg).Scan(&_v); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return _v, nil
|
||||
}
|
||||
|
||||
// Min returns MIN(column) for current scope.
|
||||
func (c contentPriceQueryDo) Min(column field.Expr) (float64, error) {
|
||||
var _v float64
|
||||
agg := field.NewUnsafeFieldRaw("MIN(?)", column.RawExpr())
|
||||
if err := c.Select(agg).Scan(&_v); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return _v, nil
|
||||
}
|
||||
|
||||
// Max returns MAX(column) for current scope.
|
||||
func (c contentPriceQueryDo) Max(column field.Expr) (float64, error) {
|
||||
var _v float64
|
||||
agg := field.NewUnsafeFieldRaw("MAX(?)", column.RawExpr())
|
||||
if err := c.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 (c contentPriceQueryDo) PluckMap(key, val field.Expr) (map[interface{}]interface{}, error) {
|
||||
do := c.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 (c contentPriceQueryDo) Exists(conds ...gen.Condition) (bool, error) {
|
||||
cnt, err := c.Where(conds...).Count()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
return cnt > 0, nil
|
||||
}
|
||||
|
||||
// PluckIDs returns all primary key values under current scope.
|
||||
func (c contentPriceQueryDo) PluckIDs() ([]int64, error) {
|
||||
ids := make([]int64, 0, 16)
|
||||
pk := field.NewInt64(c.TableName(), "id")
|
||||
if err := c.DO.Pluck(pk, &ids); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return ids, nil
|
||||
}
|
||||
|
||||
// GetByID finds a single record by primary key.
|
||||
func (c contentPriceQueryDo) GetByID(id int64) (*ContentPrice, error) {
|
||||
pk := field.NewInt64(c.TableName(), "id")
|
||||
return c.Where(pk.Eq(id)).First()
|
||||
}
|
||||
|
||||
// GetByIDs finds records by primary key list.
|
||||
func (c contentPriceQueryDo) GetByIDs(ids ...int64) ([]*ContentPrice, error) {
|
||||
if len(ids) == 0 {
|
||||
return []*ContentPrice{}, nil
|
||||
}
|
||||
pk := field.NewInt64(c.TableName(), "id")
|
||||
return c.Where(pk.In(ids...)).Find()
|
||||
}
|
||||
|
||||
// DeleteByID deletes records by primary key.
|
||||
func (c contentPriceQueryDo) DeleteByID(id int64) (gen.ResultInfo, error) {
|
||||
pk := field.NewInt64(c.TableName(), "id")
|
||||
return c.Where(pk.Eq(id)).Delete()
|
||||
}
|
||||
|
||||
// DeleteByIDs deletes records by a list of primary keys.
|
||||
func (c contentPriceQueryDo) DeleteByIDs(ids ...int64) (gen.ResultInfo, error) {
|
||||
if len(ids) == 0 {
|
||||
return gen.ResultInfo{RowsAffected: 0, Error: nil}, nil
|
||||
}
|
||||
pk := field.NewInt64(c.TableName(), "id")
|
||||
return c.Where(pk.In(ids...)).Delete()
|
||||
}
|
||||
|
||||
func (c *contentPriceQueryDo) withDO(do gen.Dao) *contentPriceQueryDo {
|
||||
c.DO = *do.(*gen.DO)
|
||||
return c
|
||||
}
|
||||
71
backend/database/models/contents.gen.go
Normal file
71
backend/database/models/contents.gen.go
Normal file
@@ -0,0 +1,71 @@
|
||||
// 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"
|
||||
"time"
|
||||
|
||||
"quyun/v2/pkg/consts"
|
||||
|
||||
"go.ipao.vip/gen"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
const TableNameContent = "contents"
|
||||
|
||||
// Content mapped from table <contents>
|
||||
type Content struct {
|
||||
ID int64 `gorm:"column:id;type:bigint;primaryKey;autoIncrement:true" json:"id"`
|
||||
TenantID int64 `gorm:"column:tenant_id;type:bigint;not null" json:"tenant_id"`
|
||||
UserID int64 `gorm:"column:user_id;type:bigint;not null" json:"user_id"`
|
||||
Title string `gorm:"column:title;type:character varying(255);not null" json:"title"`
|
||||
Description string `gorm:"column:description;type:text;not null" json:"description"`
|
||||
Status consts.ContentStatus `gorm:"column:status;type:character varying(32);not null;default:draft" json:"status"`
|
||||
Visibility consts.ContentVisibility `gorm:"column:visibility;type:character varying(32);not null;default:tenant_only" json:"visibility"`
|
||||
PreviewSeconds int32 `gorm:"column:preview_seconds;type:integer;not null;default:60" json:"preview_seconds"`
|
||||
PreviewDownloadable bool `gorm:"column:preview_downloadable;type:boolean;not null" json:"preview_downloadable"`
|
||||
PublishedAt time.Time `gorm:"column:published_at;type:timestamp with time zone" json:"published_at"`
|
||||
DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;type:timestamp with time zone" json:"deleted_at"`
|
||||
CreatedAt time.Time `gorm:"column:created_at;type:timestamp with time zone;not null;default:now()" json:"created_at"`
|
||||
UpdatedAt time.Time `gorm:"column:updated_at;type:timestamp with time zone;not null;default:now()" json:"updated_at"`
|
||||
}
|
||||
|
||||
// Quick operations without importing query package
|
||||
// Update applies changed fields to the database using the default DB.
|
||||
func (m *Content) Update(ctx context.Context) (gen.ResultInfo, error) {
|
||||
return Q.Content.WithContext(ctx).Updates(m)
|
||||
}
|
||||
|
||||
// Save upserts the model using the default DB.
|
||||
func (m *Content) Save(ctx context.Context) error { return Q.Content.WithContext(ctx).Save(m) }
|
||||
|
||||
// Create inserts the model using the default DB.
|
||||
func (m *Content) Create(ctx context.Context) error { return Q.Content.WithContext(ctx).Create(m) }
|
||||
|
||||
// Delete removes the row represented by the model using the default DB.
|
||||
func (m *Content) Delete(ctx context.Context) (gen.ResultInfo, error) {
|
||||
return Q.Content.WithContext(ctx).Delete(m)
|
||||
}
|
||||
|
||||
// ForceDelete permanently deletes the row (ignores soft delete) using the default DB.
|
||||
func (m *Content) ForceDelete(ctx context.Context) (gen.ResultInfo, error) {
|
||||
return Q.Content.WithContext(ctx).Unscoped().Delete(m)
|
||||
}
|
||||
|
||||
// Restore sets deleted_at to NULL for this model's primary key using the default DB.
|
||||
func (m *Content) Restore(ctx context.Context) (gen.ResultInfo, error) {
|
||||
return Q.Content.WithContext(ctx).RestoreByID(m.ID)
|
||||
}
|
||||
|
||||
// Reload reloads the model from database by its primary key and overwrites current fields.
|
||||
func (m *Content) Reload(ctx context.Context) error {
|
||||
fresh, err := Q.Content.WithContext(ctx).GetByID(m.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
*m = *fresh
|
||||
return nil
|
||||
}
|
||||
522
backend/database/models/contents.query.gen.go
Normal file
522
backend/database/models/contents.query.gen.go
Normal file
@@ -0,0 +1,522 @@
|
||||
// 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 newContent(db *gorm.DB, opts ...gen.DOOption) contentQuery {
|
||||
_contentQuery := contentQuery{}
|
||||
|
||||
_contentQuery.contentQueryDo.UseDB(db, opts...)
|
||||
_contentQuery.contentQueryDo.UseModel(&Content{})
|
||||
|
||||
tableName := _contentQuery.contentQueryDo.TableName()
|
||||
_contentQuery.ALL = field.NewAsterisk(tableName)
|
||||
_contentQuery.ID = field.NewInt64(tableName, "id")
|
||||
_contentQuery.TenantID = field.NewInt64(tableName, "tenant_id")
|
||||
_contentQuery.UserID = field.NewInt64(tableName, "user_id")
|
||||
_contentQuery.Title = field.NewString(tableName, "title")
|
||||
_contentQuery.Description = field.NewString(tableName, "description")
|
||||
_contentQuery.Status = field.NewField(tableName, "status")
|
||||
_contentQuery.Visibility = field.NewField(tableName, "visibility")
|
||||
_contentQuery.PreviewSeconds = field.NewInt32(tableName, "preview_seconds")
|
||||
_contentQuery.PreviewDownloadable = field.NewBool(tableName, "preview_downloadable")
|
||||
_contentQuery.PublishedAt = field.NewTime(tableName, "published_at")
|
||||
_contentQuery.DeletedAt = field.NewField(tableName, "deleted_at")
|
||||
_contentQuery.CreatedAt = field.NewTime(tableName, "created_at")
|
||||
_contentQuery.UpdatedAt = field.NewTime(tableName, "updated_at")
|
||||
|
||||
_contentQuery.fillFieldMap()
|
||||
|
||||
return _contentQuery
|
||||
}
|
||||
|
||||
type contentQuery struct {
|
||||
contentQueryDo contentQueryDo
|
||||
|
||||
ALL field.Asterisk
|
||||
ID field.Int64
|
||||
TenantID field.Int64
|
||||
UserID field.Int64
|
||||
Title field.String
|
||||
Description field.String
|
||||
Status field.Field
|
||||
Visibility field.Field
|
||||
PreviewSeconds field.Int32
|
||||
PreviewDownloadable field.Bool
|
||||
PublishedAt field.Time
|
||||
DeletedAt field.Field
|
||||
CreatedAt field.Time
|
||||
UpdatedAt field.Time
|
||||
|
||||
fieldMap map[string]field.Expr
|
||||
}
|
||||
|
||||
func (c contentQuery) Table(newTableName string) *contentQuery {
|
||||
c.contentQueryDo.UseTable(newTableName)
|
||||
return c.updateTableName(newTableName)
|
||||
}
|
||||
|
||||
func (c contentQuery) As(alias string) *contentQuery {
|
||||
c.contentQueryDo.DO = *(c.contentQueryDo.As(alias).(*gen.DO))
|
||||
return c.updateTableName(alias)
|
||||
}
|
||||
|
||||
func (c *contentQuery) updateTableName(table string) *contentQuery {
|
||||
c.ALL = field.NewAsterisk(table)
|
||||
c.ID = field.NewInt64(table, "id")
|
||||
c.TenantID = field.NewInt64(table, "tenant_id")
|
||||
c.UserID = field.NewInt64(table, "user_id")
|
||||
c.Title = field.NewString(table, "title")
|
||||
c.Description = field.NewString(table, "description")
|
||||
c.Status = field.NewField(table, "status")
|
||||
c.Visibility = field.NewField(table, "visibility")
|
||||
c.PreviewSeconds = field.NewInt32(table, "preview_seconds")
|
||||
c.PreviewDownloadable = field.NewBool(table, "preview_downloadable")
|
||||
c.PublishedAt = field.NewTime(table, "published_at")
|
||||
c.DeletedAt = field.NewField(table, "deleted_at")
|
||||
c.CreatedAt = field.NewTime(table, "created_at")
|
||||
c.UpdatedAt = field.NewTime(table, "updated_at")
|
||||
|
||||
c.fillFieldMap()
|
||||
|
||||
return c
|
||||
}
|
||||
|
||||
func (c *contentQuery) QueryContext(ctx context.Context) (*contentQuery, *contentQueryDo) {
|
||||
return c, c.contentQueryDo.WithContext(ctx)
|
||||
}
|
||||
|
||||
func (c *contentQuery) WithContext(ctx context.Context) *contentQueryDo {
|
||||
return c.contentQueryDo.WithContext(ctx)
|
||||
}
|
||||
|
||||
func (c contentQuery) TableName() string { return c.contentQueryDo.TableName() }
|
||||
|
||||
func (c contentQuery) Alias() string { return c.contentQueryDo.Alias() }
|
||||
|
||||
func (c contentQuery) Columns(cols ...field.Expr) gen.Columns {
|
||||
return c.contentQueryDo.Columns(cols...)
|
||||
}
|
||||
|
||||
func (c *contentQuery) 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 *contentQuery) fillFieldMap() {
|
||||
c.fieldMap = make(map[string]field.Expr, 13)
|
||||
c.fieldMap["id"] = c.ID
|
||||
c.fieldMap["tenant_id"] = c.TenantID
|
||||
c.fieldMap["user_id"] = c.UserID
|
||||
c.fieldMap["title"] = c.Title
|
||||
c.fieldMap["description"] = c.Description
|
||||
c.fieldMap["status"] = c.Status
|
||||
c.fieldMap["visibility"] = c.Visibility
|
||||
c.fieldMap["preview_seconds"] = c.PreviewSeconds
|
||||
c.fieldMap["preview_downloadable"] = c.PreviewDownloadable
|
||||
c.fieldMap["published_at"] = c.PublishedAt
|
||||
c.fieldMap["deleted_at"] = c.DeletedAt
|
||||
c.fieldMap["created_at"] = c.CreatedAt
|
||||
c.fieldMap["updated_at"] = c.UpdatedAt
|
||||
}
|
||||
|
||||
func (c contentQuery) clone(db *gorm.DB) contentQuery {
|
||||
c.contentQueryDo.ReplaceConnPool(db.Statement.ConnPool)
|
||||
return c
|
||||
}
|
||||
|
||||
func (c contentQuery) replaceDB(db *gorm.DB) contentQuery {
|
||||
c.contentQueryDo.ReplaceDB(db)
|
||||
return c
|
||||
}
|
||||
|
||||
type contentQueryDo struct{ gen.DO }
|
||||
|
||||
func (c contentQueryDo) Debug() *contentQueryDo {
|
||||
return c.withDO(c.DO.Debug())
|
||||
}
|
||||
|
||||
func (c contentQueryDo) WithContext(ctx context.Context) *contentQueryDo {
|
||||
return c.withDO(c.DO.WithContext(ctx))
|
||||
}
|
||||
|
||||
func (c contentQueryDo) ReadDB() *contentQueryDo {
|
||||
return c.Clauses(dbresolver.Read)
|
||||
}
|
||||
|
||||
func (c contentQueryDo) WriteDB() *contentQueryDo {
|
||||
return c.Clauses(dbresolver.Write)
|
||||
}
|
||||
|
||||
func (c contentQueryDo) Session(config *gorm.Session) *contentQueryDo {
|
||||
return c.withDO(c.DO.Session(config))
|
||||
}
|
||||
|
||||
func (c contentQueryDo) Clauses(conds ...clause.Expression) *contentQueryDo {
|
||||
return c.withDO(c.DO.Clauses(conds...))
|
||||
}
|
||||
|
||||
func (c contentQueryDo) Returning(value interface{}, columns ...string) *contentQueryDo {
|
||||
return c.withDO(c.DO.Returning(value, columns...))
|
||||
}
|
||||
|
||||
func (c contentQueryDo) Not(conds ...gen.Condition) *contentQueryDo {
|
||||
return c.withDO(c.DO.Not(conds...))
|
||||
}
|
||||
|
||||
func (c contentQueryDo) Or(conds ...gen.Condition) *contentQueryDo {
|
||||
return c.withDO(c.DO.Or(conds...))
|
||||
}
|
||||
|
||||
func (c contentQueryDo) Select(conds ...field.Expr) *contentQueryDo {
|
||||
return c.withDO(c.DO.Select(conds...))
|
||||
}
|
||||
|
||||
func (c contentQueryDo) Where(conds ...gen.Condition) *contentQueryDo {
|
||||
return c.withDO(c.DO.Where(conds...))
|
||||
}
|
||||
|
||||
func (c contentQueryDo) Order(conds ...field.Expr) *contentQueryDo {
|
||||
return c.withDO(c.DO.Order(conds...))
|
||||
}
|
||||
|
||||
func (c contentQueryDo) Distinct(cols ...field.Expr) *contentQueryDo {
|
||||
return c.withDO(c.DO.Distinct(cols...))
|
||||
}
|
||||
|
||||
func (c contentQueryDo) Omit(cols ...field.Expr) *contentQueryDo {
|
||||
return c.withDO(c.DO.Omit(cols...))
|
||||
}
|
||||
|
||||
func (c contentQueryDo) Join(table schema.Tabler, on ...field.Expr) *contentQueryDo {
|
||||
return c.withDO(c.DO.Join(table, on...))
|
||||
}
|
||||
|
||||
func (c contentQueryDo) LeftJoin(table schema.Tabler, on ...field.Expr) *contentQueryDo {
|
||||
return c.withDO(c.DO.LeftJoin(table, on...))
|
||||
}
|
||||
|
||||
func (c contentQueryDo) RightJoin(table schema.Tabler, on ...field.Expr) *contentQueryDo {
|
||||
return c.withDO(c.DO.RightJoin(table, on...))
|
||||
}
|
||||
|
||||
func (c contentQueryDo) Group(cols ...field.Expr) *contentQueryDo {
|
||||
return c.withDO(c.DO.Group(cols...))
|
||||
}
|
||||
|
||||
func (c contentQueryDo) Having(conds ...gen.Condition) *contentQueryDo {
|
||||
return c.withDO(c.DO.Having(conds...))
|
||||
}
|
||||
|
||||
func (c contentQueryDo) Limit(limit int) *contentQueryDo {
|
||||
return c.withDO(c.DO.Limit(limit))
|
||||
}
|
||||
|
||||
func (c contentQueryDo) Offset(offset int) *contentQueryDo {
|
||||
return c.withDO(c.DO.Offset(offset))
|
||||
}
|
||||
|
||||
func (c contentQueryDo) Scopes(funcs ...func(gen.Dao) gen.Dao) *contentQueryDo {
|
||||
return c.withDO(c.DO.Scopes(funcs...))
|
||||
}
|
||||
|
||||
func (c contentQueryDo) Unscoped() *contentQueryDo {
|
||||
return c.withDO(c.DO.Unscoped())
|
||||
}
|
||||
|
||||
func (c contentQueryDo) Create(values ...*Content) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return c.DO.Create(values)
|
||||
}
|
||||
|
||||
func (c contentQueryDo) CreateInBatches(values []*Content, 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 contentQueryDo) Save(values ...*Content) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return c.DO.Save(values)
|
||||
}
|
||||
|
||||
func (c contentQueryDo) First() (*Content, error) {
|
||||
if result, err := c.DO.First(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*Content), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (c contentQueryDo) Take() (*Content, error) {
|
||||
if result, err := c.DO.Take(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*Content), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (c contentQueryDo) Last() (*Content, error) {
|
||||
if result, err := c.DO.Last(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*Content), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (c contentQueryDo) Find() ([]*Content, error) {
|
||||
result, err := c.DO.Find()
|
||||
return result.([]*Content), err
|
||||
}
|
||||
|
||||
func (c contentQueryDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*Content, err error) {
|
||||
buf := make([]*Content, 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 contentQueryDo) FindInBatches(result *[]*Content, batchSize int, fc func(tx gen.Dao, batch int) error) error {
|
||||
return c.DO.FindInBatches(result, batchSize, fc)
|
||||
}
|
||||
|
||||
func (c contentQueryDo) Attrs(attrs ...field.AssignExpr) *contentQueryDo {
|
||||
return c.withDO(c.DO.Attrs(attrs...))
|
||||
}
|
||||
|
||||
func (c contentQueryDo) Assign(attrs ...field.AssignExpr) *contentQueryDo {
|
||||
return c.withDO(c.DO.Assign(attrs...))
|
||||
}
|
||||
|
||||
func (c contentQueryDo) Joins(fields ...field.RelationField) *contentQueryDo {
|
||||
for _, _f := range fields {
|
||||
c = *c.withDO(c.DO.Joins(_f))
|
||||
}
|
||||
return &c
|
||||
}
|
||||
|
||||
func (c contentQueryDo) Preload(fields ...field.RelationField) *contentQueryDo {
|
||||
for _, _f := range fields {
|
||||
c = *c.withDO(c.DO.Preload(_f))
|
||||
}
|
||||
return &c
|
||||
}
|
||||
|
||||
func (c contentQueryDo) FirstOrInit() (*Content, error) {
|
||||
if result, err := c.DO.FirstOrInit(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*Content), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (c contentQueryDo) FirstOrCreate() (*Content, error) {
|
||||
if result, err := c.DO.FirstOrCreate(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*Content), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (c contentQueryDo) FindByPage(offset int, limit int) (result []*Content, 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 contentQueryDo) 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 contentQueryDo) Scan(result interface{}) (err error) {
|
||||
return c.DO.Scan(result)
|
||||
}
|
||||
|
||||
func (c contentQueryDo) Delete(models ...*Content) (result gen.ResultInfo, err error) {
|
||||
return c.DO.Delete(models)
|
||||
}
|
||||
|
||||
// ForceDelete performs a permanent delete (ignores soft-delete) for current scope.
|
||||
func (c contentQueryDo) ForceDelete() (gen.ResultInfo, error) {
|
||||
return c.Unscoped().Delete()
|
||||
}
|
||||
|
||||
// Inc increases the given column by step for current scope.
|
||||
func (c contentQueryDo) Inc(column field.Expr, step int64) (gen.ResultInfo, error) {
|
||||
// column = column + step
|
||||
e := field.NewUnsafeFieldRaw("?+?", column.RawExpr(), step)
|
||||
return c.DO.UpdateColumn(column, e)
|
||||
}
|
||||
|
||||
// Dec decreases the given column by step for current scope.
|
||||
func (c contentQueryDo) Dec(column field.Expr, step int64) (gen.ResultInfo, error) {
|
||||
// column = column - step
|
||||
e := field.NewUnsafeFieldRaw("?-?", column.RawExpr(), step)
|
||||
return c.DO.UpdateColumn(column, e)
|
||||
}
|
||||
|
||||
// Sum returns SUM(column) for current scope.
|
||||
func (c contentQueryDo) Sum(column field.Expr) (float64, error) {
|
||||
var _v float64
|
||||
agg := field.NewUnsafeFieldRaw("SUM(?)", column.RawExpr())
|
||||
if err := c.Select(agg).Scan(&_v); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return _v, nil
|
||||
}
|
||||
|
||||
// Avg returns AVG(column) for current scope.
|
||||
func (c contentQueryDo) Avg(column field.Expr) (float64, error) {
|
||||
var _v float64
|
||||
agg := field.NewUnsafeFieldRaw("AVG(?)", column.RawExpr())
|
||||
if err := c.Select(agg).Scan(&_v); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return _v, nil
|
||||
}
|
||||
|
||||
// Min returns MIN(column) for current scope.
|
||||
func (c contentQueryDo) Min(column field.Expr) (float64, error) {
|
||||
var _v float64
|
||||
agg := field.NewUnsafeFieldRaw("MIN(?)", column.RawExpr())
|
||||
if err := c.Select(agg).Scan(&_v); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return _v, nil
|
||||
}
|
||||
|
||||
// Max returns MAX(column) for current scope.
|
||||
func (c contentQueryDo) Max(column field.Expr) (float64, error) {
|
||||
var _v float64
|
||||
agg := field.NewUnsafeFieldRaw("MAX(?)", column.RawExpr())
|
||||
if err := c.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 (c contentQueryDo) PluckMap(key, val field.Expr) (map[interface{}]interface{}, error) {
|
||||
do := c.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 (c contentQueryDo) Exists(conds ...gen.Condition) (bool, error) {
|
||||
cnt, err := c.Where(conds...).Count()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
return cnt > 0, nil
|
||||
}
|
||||
|
||||
// PluckIDs returns all primary key values under current scope.
|
||||
func (c contentQueryDo) PluckIDs() ([]int64, error) {
|
||||
ids := make([]int64, 0, 16)
|
||||
pk := field.NewInt64(c.TableName(), "id")
|
||||
if err := c.DO.Pluck(pk, &ids); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return ids, nil
|
||||
}
|
||||
|
||||
// GetByID finds a single record by primary key.
|
||||
func (c contentQueryDo) GetByID(id int64) (*Content, error) {
|
||||
pk := field.NewInt64(c.TableName(), "id")
|
||||
return c.Where(pk.Eq(id)).First()
|
||||
}
|
||||
|
||||
// GetByIDs finds records by primary key list.
|
||||
func (c contentQueryDo) GetByIDs(ids ...int64) ([]*Content, error) {
|
||||
if len(ids) == 0 {
|
||||
return []*Content{}, nil
|
||||
}
|
||||
pk := field.NewInt64(c.TableName(), "id")
|
||||
return c.Where(pk.In(ids...)).Find()
|
||||
}
|
||||
|
||||
// DeleteByID deletes records by primary key.
|
||||
func (c contentQueryDo) DeleteByID(id int64) (gen.ResultInfo, error) {
|
||||
pk := field.NewInt64(c.TableName(), "id")
|
||||
return c.Where(pk.Eq(id)).Delete()
|
||||
}
|
||||
|
||||
// DeleteByIDs deletes records by a list of primary keys.
|
||||
func (c contentQueryDo) DeleteByIDs(ids ...int64) (gen.ResultInfo, error) {
|
||||
if len(ids) == 0 {
|
||||
return gen.ResultInfo{RowsAffected: 0, Error: nil}, nil
|
||||
}
|
||||
pk := field.NewInt64(c.TableName(), "id")
|
||||
return c.Where(pk.In(ids...)).Delete()
|
||||
}
|
||||
|
||||
// RestoreWhere sets deleted_at to NULL for rows matching current scope + conds.
|
||||
func (c contentQueryDo) RestoreWhere(conds ...gen.Condition) (gen.ResultInfo, error) {
|
||||
col := field.NewField(c.TableName(), "deleted_at")
|
||||
return c.Unscoped().Where(conds...).UpdateColumn(col, nil)
|
||||
}
|
||||
|
||||
// RestoreByID sets deleted_at to NULL for the given primary key.
|
||||
func (c contentQueryDo) RestoreByID(id int64) (gen.ResultInfo, error) {
|
||||
pk := field.NewInt64(c.TableName(), "id")
|
||||
col := field.NewField(c.TableName(), "deleted_at")
|
||||
return c.Unscoped().Where(pk.Eq(id)).UpdateColumn(col, nil)
|
||||
}
|
||||
|
||||
func (c *contentQueryDo) withDO(do gen.Dao) *contentQueryDo {
|
||||
c.DO = *do.(*gen.DO)
|
||||
return c
|
||||
}
|
||||
73
backend/database/models/media_assets.gen.go
Normal file
73
backend/database/models/media_assets.gen.go
Normal file
@@ -0,0 +1,73 @@
|
||||
// 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"
|
||||
"time"
|
||||
|
||||
"quyun/v2/pkg/consts"
|
||||
|
||||
"go.ipao.vip/gen"
|
||||
"go.ipao.vip/gen/types"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
const TableNameMediaAsset = "media_assets"
|
||||
|
||||
// MediaAsset mapped from table <media_assets>
|
||||
type MediaAsset struct {
|
||||
ID int64 `gorm:"column:id;type:bigint;primaryKey;autoIncrement:true" json:"id"`
|
||||
TenantID int64 `gorm:"column:tenant_id;type:bigint;not null" json:"tenant_id"`
|
||||
UserID int64 `gorm:"column:user_id;type:bigint;not null" json:"user_id"`
|
||||
Type consts.MediaAssetType `gorm:"column:type;type:character varying(32);not null;default:video" json:"type"`
|
||||
Status consts.MediaAssetStatus `gorm:"column:status;type:character varying(32);not null;default:uploaded" json:"status"`
|
||||
Provider string `gorm:"column:provider;type:character varying(64);not null" json:"provider"`
|
||||
Bucket string `gorm:"column:bucket;type:character varying(128);not null" json:"bucket"`
|
||||
ObjectKey string `gorm:"column:object_key;type:character varying(512);not null" json:"object_key"`
|
||||
Meta types.JSON `gorm:"column:meta;type:jsonb;not null;default:{}" json:"meta"`
|
||||
DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;type:timestamp with time zone" json:"deleted_at"`
|
||||
CreatedAt time.Time `gorm:"column:created_at;type:timestamp with time zone;not null;default:now()" json:"created_at"`
|
||||
UpdatedAt time.Time `gorm:"column:updated_at;type:timestamp with time zone;not null;default:now()" json:"updated_at"`
|
||||
}
|
||||
|
||||
// Quick operations without importing query package
|
||||
// Update applies changed fields to the database using the default DB.
|
||||
func (m *MediaAsset) Update(ctx context.Context) (gen.ResultInfo, error) {
|
||||
return Q.MediaAsset.WithContext(ctx).Updates(m)
|
||||
}
|
||||
|
||||
// Save upserts the model using the default DB.
|
||||
func (m *MediaAsset) Save(ctx context.Context) error { return Q.MediaAsset.WithContext(ctx).Save(m) }
|
||||
|
||||
// Create inserts the model using the default DB.
|
||||
func (m *MediaAsset) Create(ctx context.Context) error {
|
||||
return Q.MediaAsset.WithContext(ctx).Create(m)
|
||||
}
|
||||
|
||||
// Delete removes the row represented by the model using the default DB.
|
||||
func (m *MediaAsset) Delete(ctx context.Context) (gen.ResultInfo, error) {
|
||||
return Q.MediaAsset.WithContext(ctx).Delete(m)
|
||||
}
|
||||
|
||||
// ForceDelete permanently deletes the row (ignores soft delete) using the default DB.
|
||||
func (m *MediaAsset) ForceDelete(ctx context.Context) (gen.ResultInfo, error) {
|
||||
return Q.MediaAsset.WithContext(ctx).Unscoped().Delete(m)
|
||||
}
|
||||
|
||||
// Restore sets deleted_at to NULL for this model's primary key using the default DB.
|
||||
func (m *MediaAsset) Restore(ctx context.Context) (gen.ResultInfo, error) {
|
||||
return Q.MediaAsset.WithContext(ctx).RestoreByID(m.ID)
|
||||
}
|
||||
|
||||
// Reload reloads the model from database by its primary key and overwrites current fields.
|
||||
func (m *MediaAsset) Reload(ctx context.Context) error {
|
||||
fresh, err := Q.MediaAsset.WithContext(ctx).GetByID(m.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
*m = *fresh
|
||||
return nil
|
||||
}
|
||||
518
backend/database/models/media_assets.query.gen.go
Normal file
518
backend/database/models/media_assets.query.gen.go
Normal file
@@ -0,0 +1,518 @@
|
||||
// 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 newMediaAsset(db *gorm.DB, opts ...gen.DOOption) mediaAssetQuery {
|
||||
_mediaAssetQuery := mediaAssetQuery{}
|
||||
|
||||
_mediaAssetQuery.mediaAssetQueryDo.UseDB(db, opts...)
|
||||
_mediaAssetQuery.mediaAssetQueryDo.UseModel(&MediaAsset{})
|
||||
|
||||
tableName := _mediaAssetQuery.mediaAssetQueryDo.TableName()
|
||||
_mediaAssetQuery.ALL = field.NewAsterisk(tableName)
|
||||
_mediaAssetQuery.ID = field.NewInt64(tableName, "id")
|
||||
_mediaAssetQuery.TenantID = field.NewInt64(tableName, "tenant_id")
|
||||
_mediaAssetQuery.UserID = field.NewInt64(tableName, "user_id")
|
||||
_mediaAssetQuery.Type = field.NewField(tableName, "type")
|
||||
_mediaAssetQuery.Status = field.NewField(tableName, "status")
|
||||
_mediaAssetQuery.Provider = field.NewString(tableName, "provider")
|
||||
_mediaAssetQuery.Bucket = field.NewString(tableName, "bucket")
|
||||
_mediaAssetQuery.ObjectKey = field.NewString(tableName, "object_key")
|
||||
_mediaAssetQuery.Meta = field.NewJSONB(tableName, "meta")
|
||||
_mediaAssetQuery.DeletedAt = field.NewField(tableName, "deleted_at")
|
||||
_mediaAssetQuery.CreatedAt = field.NewTime(tableName, "created_at")
|
||||
_mediaAssetQuery.UpdatedAt = field.NewTime(tableName, "updated_at")
|
||||
|
||||
_mediaAssetQuery.fillFieldMap()
|
||||
|
||||
return _mediaAssetQuery
|
||||
}
|
||||
|
||||
type mediaAssetQuery struct {
|
||||
mediaAssetQueryDo mediaAssetQueryDo
|
||||
|
||||
ALL field.Asterisk
|
||||
ID field.Int64
|
||||
TenantID field.Int64
|
||||
UserID field.Int64
|
||||
Type field.Field
|
||||
Status field.Field
|
||||
Provider field.String
|
||||
Bucket field.String
|
||||
ObjectKey field.String
|
||||
Meta field.JSONB
|
||||
DeletedAt field.Field
|
||||
CreatedAt field.Time
|
||||
UpdatedAt field.Time
|
||||
|
||||
fieldMap map[string]field.Expr
|
||||
}
|
||||
|
||||
func (m mediaAssetQuery) Table(newTableName string) *mediaAssetQuery {
|
||||
m.mediaAssetQueryDo.UseTable(newTableName)
|
||||
return m.updateTableName(newTableName)
|
||||
}
|
||||
|
||||
func (m mediaAssetQuery) As(alias string) *mediaAssetQuery {
|
||||
m.mediaAssetQueryDo.DO = *(m.mediaAssetQueryDo.As(alias).(*gen.DO))
|
||||
return m.updateTableName(alias)
|
||||
}
|
||||
|
||||
func (m *mediaAssetQuery) updateTableName(table string) *mediaAssetQuery {
|
||||
m.ALL = field.NewAsterisk(table)
|
||||
m.ID = field.NewInt64(table, "id")
|
||||
m.TenantID = field.NewInt64(table, "tenant_id")
|
||||
m.UserID = field.NewInt64(table, "user_id")
|
||||
m.Type = field.NewField(table, "type")
|
||||
m.Status = field.NewField(table, "status")
|
||||
m.Provider = field.NewString(table, "provider")
|
||||
m.Bucket = field.NewString(table, "bucket")
|
||||
m.ObjectKey = field.NewString(table, "object_key")
|
||||
m.Meta = field.NewJSONB(table, "meta")
|
||||
m.DeletedAt = field.NewField(table, "deleted_at")
|
||||
m.CreatedAt = field.NewTime(table, "created_at")
|
||||
m.UpdatedAt = field.NewTime(table, "updated_at")
|
||||
|
||||
m.fillFieldMap()
|
||||
|
||||
return m
|
||||
}
|
||||
|
||||
func (m *mediaAssetQuery) QueryContext(ctx context.Context) (*mediaAssetQuery, *mediaAssetQueryDo) {
|
||||
return m, m.mediaAssetQueryDo.WithContext(ctx)
|
||||
}
|
||||
|
||||
func (m *mediaAssetQuery) WithContext(ctx context.Context) *mediaAssetQueryDo {
|
||||
return m.mediaAssetQueryDo.WithContext(ctx)
|
||||
}
|
||||
|
||||
func (m mediaAssetQuery) TableName() string { return m.mediaAssetQueryDo.TableName() }
|
||||
|
||||
func (m mediaAssetQuery) Alias() string { return m.mediaAssetQueryDo.Alias() }
|
||||
|
||||
func (m mediaAssetQuery) Columns(cols ...field.Expr) gen.Columns {
|
||||
return m.mediaAssetQueryDo.Columns(cols...)
|
||||
}
|
||||
|
||||
func (m *mediaAssetQuery) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
|
||||
_f, ok := m.fieldMap[fieldName]
|
||||
if !ok || _f == nil {
|
||||
return nil, false
|
||||
}
|
||||
_oe, ok := _f.(field.OrderExpr)
|
||||
return _oe, ok
|
||||
}
|
||||
|
||||
func (m *mediaAssetQuery) fillFieldMap() {
|
||||
m.fieldMap = make(map[string]field.Expr, 12)
|
||||
m.fieldMap["id"] = m.ID
|
||||
m.fieldMap["tenant_id"] = m.TenantID
|
||||
m.fieldMap["user_id"] = m.UserID
|
||||
m.fieldMap["type"] = m.Type
|
||||
m.fieldMap["status"] = m.Status
|
||||
m.fieldMap["provider"] = m.Provider
|
||||
m.fieldMap["bucket"] = m.Bucket
|
||||
m.fieldMap["object_key"] = m.ObjectKey
|
||||
m.fieldMap["meta"] = m.Meta
|
||||
m.fieldMap["deleted_at"] = m.DeletedAt
|
||||
m.fieldMap["created_at"] = m.CreatedAt
|
||||
m.fieldMap["updated_at"] = m.UpdatedAt
|
||||
}
|
||||
|
||||
func (m mediaAssetQuery) clone(db *gorm.DB) mediaAssetQuery {
|
||||
m.mediaAssetQueryDo.ReplaceConnPool(db.Statement.ConnPool)
|
||||
return m
|
||||
}
|
||||
|
||||
func (m mediaAssetQuery) replaceDB(db *gorm.DB) mediaAssetQuery {
|
||||
m.mediaAssetQueryDo.ReplaceDB(db)
|
||||
return m
|
||||
}
|
||||
|
||||
type mediaAssetQueryDo struct{ gen.DO }
|
||||
|
||||
func (m mediaAssetQueryDo) Debug() *mediaAssetQueryDo {
|
||||
return m.withDO(m.DO.Debug())
|
||||
}
|
||||
|
||||
func (m mediaAssetQueryDo) WithContext(ctx context.Context) *mediaAssetQueryDo {
|
||||
return m.withDO(m.DO.WithContext(ctx))
|
||||
}
|
||||
|
||||
func (m mediaAssetQueryDo) ReadDB() *mediaAssetQueryDo {
|
||||
return m.Clauses(dbresolver.Read)
|
||||
}
|
||||
|
||||
func (m mediaAssetQueryDo) WriteDB() *mediaAssetQueryDo {
|
||||
return m.Clauses(dbresolver.Write)
|
||||
}
|
||||
|
||||
func (m mediaAssetQueryDo) Session(config *gorm.Session) *mediaAssetQueryDo {
|
||||
return m.withDO(m.DO.Session(config))
|
||||
}
|
||||
|
||||
func (m mediaAssetQueryDo) Clauses(conds ...clause.Expression) *mediaAssetQueryDo {
|
||||
return m.withDO(m.DO.Clauses(conds...))
|
||||
}
|
||||
|
||||
func (m mediaAssetQueryDo) Returning(value interface{}, columns ...string) *mediaAssetQueryDo {
|
||||
return m.withDO(m.DO.Returning(value, columns...))
|
||||
}
|
||||
|
||||
func (m mediaAssetQueryDo) Not(conds ...gen.Condition) *mediaAssetQueryDo {
|
||||
return m.withDO(m.DO.Not(conds...))
|
||||
}
|
||||
|
||||
func (m mediaAssetQueryDo) Or(conds ...gen.Condition) *mediaAssetQueryDo {
|
||||
return m.withDO(m.DO.Or(conds...))
|
||||
}
|
||||
|
||||
func (m mediaAssetQueryDo) Select(conds ...field.Expr) *mediaAssetQueryDo {
|
||||
return m.withDO(m.DO.Select(conds...))
|
||||
}
|
||||
|
||||
func (m mediaAssetQueryDo) Where(conds ...gen.Condition) *mediaAssetQueryDo {
|
||||
return m.withDO(m.DO.Where(conds...))
|
||||
}
|
||||
|
||||
func (m mediaAssetQueryDo) Order(conds ...field.Expr) *mediaAssetQueryDo {
|
||||
return m.withDO(m.DO.Order(conds...))
|
||||
}
|
||||
|
||||
func (m mediaAssetQueryDo) Distinct(cols ...field.Expr) *mediaAssetQueryDo {
|
||||
return m.withDO(m.DO.Distinct(cols...))
|
||||
}
|
||||
|
||||
func (m mediaAssetQueryDo) Omit(cols ...field.Expr) *mediaAssetQueryDo {
|
||||
return m.withDO(m.DO.Omit(cols...))
|
||||
}
|
||||
|
||||
func (m mediaAssetQueryDo) Join(table schema.Tabler, on ...field.Expr) *mediaAssetQueryDo {
|
||||
return m.withDO(m.DO.Join(table, on...))
|
||||
}
|
||||
|
||||
func (m mediaAssetQueryDo) LeftJoin(table schema.Tabler, on ...field.Expr) *mediaAssetQueryDo {
|
||||
return m.withDO(m.DO.LeftJoin(table, on...))
|
||||
}
|
||||
|
||||
func (m mediaAssetQueryDo) RightJoin(table schema.Tabler, on ...field.Expr) *mediaAssetQueryDo {
|
||||
return m.withDO(m.DO.RightJoin(table, on...))
|
||||
}
|
||||
|
||||
func (m mediaAssetQueryDo) Group(cols ...field.Expr) *mediaAssetQueryDo {
|
||||
return m.withDO(m.DO.Group(cols...))
|
||||
}
|
||||
|
||||
func (m mediaAssetQueryDo) Having(conds ...gen.Condition) *mediaAssetQueryDo {
|
||||
return m.withDO(m.DO.Having(conds...))
|
||||
}
|
||||
|
||||
func (m mediaAssetQueryDo) Limit(limit int) *mediaAssetQueryDo {
|
||||
return m.withDO(m.DO.Limit(limit))
|
||||
}
|
||||
|
||||
func (m mediaAssetQueryDo) Offset(offset int) *mediaAssetQueryDo {
|
||||
return m.withDO(m.DO.Offset(offset))
|
||||
}
|
||||
|
||||
func (m mediaAssetQueryDo) Scopes(funcs ...func(gen.Dao) gen.Dao) *mediaAssetQueryDo {
|
||||
return m.withDO(m.DO.Scopes(funcs...))
|
||||
}
|
||||
|
||||
func (m mediaAssetQueryDo) Unscoped() *mediaAssetQueryDo {
|
||||
return m.withDO(m.DO.Unscoped())
|
||||
}
|
||||
|
||||
func (m mediaAssetQueryDo) Create(values ...*MediaAsset) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return m.DO.Create(values)
|
||||
}
|
||||
|
||||
func (m mediaAssetQueryDo) CreateInBatches(values []*MediaAsset, batchSize int) error {
|
||||
return m.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 (m mediaAssetQueryDo) Save(values ...*MediaAsset) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return m.DO.Save(values)
|
||||
}
|
||||
|
||||
func (m mediaAssetQueryDo) First() (*MediaAsset, error) {
|
||||
if result, err := m.DO.First(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*MediaAsset), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (m mediaAssetQueryDo) Take() (*MediaAsset, error) {
|
||||
if result, err := m.DO.Take(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*MediaAsset), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (m mediaAssetQueryDo) Last() (*MediaAsset, error) {
|
||||
if result, err := m.DO.Last(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*MediaAsset), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (m mediaAssetQueryDo) Find() ([]*MediaAsset, error) {
|
||||
result, err := m.DO.Find()
|
||||
return result.([]*MediaAsset), err
|
||||
}
|
||||
|
||||
func (m mediaAssetQueryDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*MediaAsset, err error) {
|
||||
buf := make([]*MediaAsset, 0, batchSize)
|
||||
err = m.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 (m mediaAssetQueryDo) FindInBatches(result *[]*MediaAsset, batchSize int, fc func(tx gen.Dao, batch int) error) error {
|
||||
return m.DO.FindInBatches(result, batchSize, fc)
|
||||
}
|
||||
|
||||
func (m mediaAssetQueryDo) Attrs(attrs ...field.AssignExpr) *mediaAssetQueryDo {
|
||||
return m.withDO(m.DO.Attrs(attrs...))
|
||||
}
|
||||
|
||||
func (m mediaAssetQueryDo) Assign(attrs ...field.AssignExpr) *mediaAssetQueryDo {
|
||||
return m.withDO(m.DO.Assign(attrs...))
|
||||
}
|
||||
|
||||
func (m mediaAssetQueryDo) Joins(fields ...field.RelationField) *mediaAssetQueryDo {
|
||||
for _, _f := range fields {
|
||||
m = *m.withDO(m.DO.Joins(_f))
|
||||
}
|
||||
return &m
|
||||
}
|
||||
|
||||
func (m mediaAssetQueryDo) Preload(fields ...field.RelationField) *mediaAssetQueryDo {
|
||||
for _, _f := range fields {
|
||||
m = *m.withDO(m.DO.Preload(_f))
|
||||
}
|
||||
return &m
|
||||
}
|
||||
|
||||
func (m mediaAssetQueryDo) FirstOrInit() (*MediaAsset, error) {
|
||||
if result, err := m.DO.FirstOrInit(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*MediaAsset), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (m mediaAssetQueryDo) FirstOrCreate() (*MediaAsset, error) {
|
||||
if result, err := m.DO.FirstOrCreate(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*MediaAsset), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (m mediaAssetQueryDo) FindByPage(offset int, limit int) (result []*MediaAsset, count int64, err error) {
|
||||
result, err = m.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 = m.Offset(-1).Limit(-1).Count()
|
||||
return
|
||||
}
|
||||
|
||||
func (m mediaAssetQueryDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) {
|
||||
count, err = m.Count()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = m.Offset(offset).Limit(limit).Scan(result)
|
||||
return
|
||||
}
|
||||
|
||||
func (m mediaAssetQueryDo) Scan(result interface{}) (err error) {
|
||||
return m.DO.Scan(result)
|
||||
}
|
||||
|
||||
func (m mediaAssetQueryDo) Delete(models ...*MediaAsset) (result gen.ResultInfo, err error) {
|
||||
return m.DO.Delete(models)
|
||||
}
|
||||
|
||||
// ForceDelete performs a permanent delete (ignores soft-delete) for current scope.
|
||||
func (m mediaAssetQueryDo) ForceDelete() (gen.ResultInfo, error) {
|
||||
return m.Unscoped().Delete()
|
||||
}
|
||||
|
||||
// Inc increases the given column by step for current scope.
|
||||
func (m mediaAssetQueryDo) Inc(column field.Expr, step int64) (gen.ResultInfo, error) {
|
||||
// column = column + step
|
||||
e := field.NewUnsafeFieldRaw("?+?", column.RawExpr(), step)
|
||||
return m.DO.UpdateColumn(column, e)
|
||||
}
|
||||
|
||||
// Dec decreases the given column by step for current scope.
|
||||
func (m mediaAssetQueryDo) Dec(column field.Expr, step int64) (gen.ResultInfo, error) {
|
||||
// column = column - step
|
||||
e := field.NewUnsafeFieldRaw("?-?", column.RawExpr(), step)
|
||||
return m.DO.UpdateColumn(column, e)
|
||||
}
|
||||
|
||||
// Sum returns SUM(column) for current scope.
|
||||
func (m mediaAssetQueryDo) Sum(column field.Expr) (float64, error) {
|
||||
var _v float64
|
||||
agg := field.NewUnsafeFieldRaw("SUM(?)", column.RawExpr())
|
||||
if err := m.Select(agg).Scan(&_v); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return _v, nil
|
||||
}
|
||||
|
||||
// Avg returns AVG(column) for current scope.
|
||||
func (m mediaAssetQueryDo) Avg(column field.Expr) (float64, error) {
|
||||
var _v float64
|
||||
agg := field.NewUnsafeFieldRaw("AVG(?)", column.RawExpr())
|
||||
if err := m.Select(agg).Scan(&_v); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return _v, nil
|
||||
}
|
||||
|
||||
// Min returns MIN(column) for current scope.
|
||||
func (m mediaAssetQueryDo) Min(column field.Expr) (float64, error) {
|
||||
var _v float64
|
||||
agg := field.NewUnsafeFieldRaw("MIN(?)", column.RawExpr())
|
||||
if err := m.Select(agg).Scan(&_v); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return _v, nil
|
||||
}
|
||||
|
||||
// Max returns MAX(column) for current scope.
|
||||
func (m mediaAssetQueryDo) Max(column field.Expr) (float64, error) {
|
||||
var _v float64
|
||||
agg := field.NewUnsafeFieldRaw("MAX(?)", column.RawExpr())
|
||||
if err := m.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 (m mediaAssetQueryDo) PluckMap(key, val field.Expr) (map[interface{}]interface{}, error) {
|
||||
do := m.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 (m mediaAssetQueryDo) Exists(conds ...gen.Condition) (bool, error) {
|
||||
cnt, err := m.Where(conds...).Count()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
return cnt > 0, nil
|
||||
}
|
||||
|
||||
// PluckIDs returns all primary key values under current scope.
|
||||
func (m mediaAssetQueryDo) PluckIDs() ([]int64, error) {
|
||||
ids := make([]int64, 0, 16)
|
||||
pk := field.NewInt64(m.TableName(), "id")
|
||||
if err := m.DO.Pluck(pk, &ids); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return ids, nil
|
||||
}
|
||||
|
||||
// GetByID finds a single record by primary key.
|
||||
func (m mediaAssetQueryDo) GetByID(id int64) (*MediaAsset, error) {
|
||||
pk := field.NewInt64(m.TableName(), "id")
|
||||
return m.Where(pk.Eq(id)).First()
|
||||
}
|
||||
|
||||
// GetByIDs finds records by primary key list.
|
||||
func (m mediaAssetQueryDo) GetByIDs(ids ...int64) ([]*MediaAsset, error) {
|
||||
if len(ids) == 0 {
|
||||
return []*MediaAsset{}, nil
|
||||
}
|
||||
pk := field.NewInt64(m.TableName(), "id")
|
||||
return m.Where(pk.In(ids...)).Find()
|
||||
}
|
||||
|
||||
// DeleteByID deletes records by primary key.
|
||||
func (m mediaAssetQueryDo) DeleteByID(id int64) (gen.ResultInfo, error) {
|
||||
pk := field.NewInt64(m.TableName(), "id")
|
||||
return m.Where(pk.Eq(id)).Delete()
|
||||
}
|
||||
|
||||
// DeleteByIDs deletes records by a list of primary keys.
|
||||
func (m mediaAssetQueryDo) DeleteByIDs(ids ...int64) (gen.ResultInfo, error) {
|
||||
if len(ids) == 0 {
|
||||
return gen.ResultInfo{RowsAffected: 0, Error: nil}, nil
|
||||
}
|
||||
pk := field.NewInt64(m.TableName(), "id")
|
||||
return m.Where(pk.In(ids...)).Delete()
|
||||
}
|
||||
|
||||
// RestoreWhere sets deleted_at to NULL for rows matching current scope + conds.
|
||||
func (m mediaAssetQueryDo) RestoreWhere(conds ...gen.Condition) (gen.ResultInfo, error) {
|
||||
col := field.NewField(m.TableName(), "deleted_at")
|
||||
return m.Unscoped().Where(conds...).UpdateColumn(col, nil)
|
||||
}
|
||||
|
||||
// RestoreByID sets deleted_at to NULL for the given primary key.
|
||||
func (m mediaAssetQueryDo) RestoreByID(id int64) (gen.ResultInfo, error) {
|
||||
pk := field.NewInt64(m.TableName(), "id")
|
||||
col := field.NewField(m.TableName(), "deleted_at")
|
||||
return m.Unscoped().Where(pk.Eq(id)).UpdateColumn(col, nil)
|
||||
}
|
||||
|
||||
func (m *mediaAssetQueryDo) withDO(do gen.Dao) *mediaAssetQueryDo {
|
||||
m.DO = *do.(*gen.DO)
|
||||
return m
|
||||
}
|
||||
@@ -16,14 +16,24 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
Q = new(Query)
|
||||
TenantQuery *tenantQuery
|
||||
TenantUserQuery *tenantUserQuery
|
||||
UserQuery *userQuery
|
||||
Q = new(Query)
|
||||
ContentQuery *contentQuery
|
||||
ContentAccessQuery *contentAccessQuery
|
||||
ContentAssetQuery *contentAssetQuery
|
||||
ContentPriceQuery *contentPriceQuery
|
||||
MediaAssetQuery *mediaAssetQuery
|
||||
TenantQuery *tenantQuery
|
||||
TenantUserQuery *tenantUserQuery
|
||||
UserQuery *userQuery
|
||||
)
|
||||
|
||||
func SetDefault(db *gorm.DB, opts ...gen.DOOption) {
|
||||
*Q = *Use(db, opts...)
|
||||
ContentQuery = &Q.Content
|
||||
ContentAccessQuery = &Q.ContentAccess
|
||||
ContentAssetQuery = &Q.ContentAsset
|
||||
ContentPriceQuery = &Q.ContentPrice
|
||||
MediaAssetQuery = &Q.MediaAsset
|
||||
TenantQuery = &Q.Tenant
|
||||
TenantUserQuery = &Q.TenantUser
|
||||
UserQuery = &Q.User
|
||||
@@ -31,29 +41,44 @@ func SetDefault(db *gorm.DB, opts ...gen.DOOption) {
|
||||
|
||||
func Use(db *gorm.DB, opts ...gen.DOOption) *Query {
|
||||
return &Query{
|
||||
db: db,
|
||||
Tenant: newTenant(db, opts...),
|
||||
TenantUser: newTenantUser(db, opts...),
|
||||
User: newUser(db, opts...),
|
||||
db: db,
|
||||
Content: newContent(db, opts...),
|
||||
ContentAccess: newContentAccess(db, opts...),
|
||||
ContentAsset: newContentAsset(db, opts...),
|
||||
ContentPrice: newContentPrice(db, opts...),
|
||||
MediaAsset: newMediaAsset(db, opts...),
|
||||
Tenant: newTenant(db, opts...),
|
||||
TenantUser: newTenantUser(db, opts...),
|
||||
User: newUser(db, opts...),
|
||||
}
|
||||
}
|
||||
|
||||
type Query struct {
|
||||
db *gorm.DB
|
||||
|
||||
Tenant tenantQuery
|
||||
TenantUser tenantUserQuery
|
||||
User userQuery
|
||||
Content contentQuery
|
||||
ContentAccess contentAccessQuery
|
||||
ContentAsset contentAssetQuery
|
||||
ContentPrice contentPriceQuery
|
||||
MediaAsset mediaAssetQuery
|
||||
Tenant tenantQuery
|
||||
TenantUser tenantUserQuery
|
||||
User userQuery
|
||||
}
|
||||
|
||||
func (q *Query) Available() bool { return q.db != nil }
|
||||
|
||||
func (q *Query) clone(db *gorm.DB) *Query {
|
||||
return &Query{
|
||||
db: db,
|
||||
Tenant: q.Tenant.clone(db),
|
||||
TenantUser: q.TenantUser.clone(db),
|
||||
User: q.User.clone(db),
|
||||
db: db,
|
||||
Content: q.Content.clone(db),
|
||||
ContentAccess: q.ContentAccess.clone(db),
|
||||
ContentAsset: q.ContentAsset.clone(db),
|
||||
ContentPrice: q.ContentPrice.clone(db),
|
||||
MediaAsset: q.MediaAsset.clone(db),
|
||||
Tenant: q.Tenant.clone(db),
|
||||
TenantUser: q.TenantUser.clone(db),
|
||||
User: q.User.clone(db),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,24 +92,39 @@ func (q *Query) WriteDB() *Query {
|
||||
|
||||
func (q *Query) ReplaceDB(db *gorm.DB) *Query {
|
||||
return &Query{
|
||||
db: db,
|
||||
Tenant: q.Tenant.replaceDB(db),
|
||||
TenantUser: q.TenantUser.replaceDB(db),
|
||||
User: q.User.replaceDB(db),
|
||||
db: db,
|
||||
Content: q.Content.replaceDB(db),
|
||||
ContentAccess: q.ContentAccess.replaceDB(db),
|
||||
ContentAsset: q.ContentAsset.replaceDB(db),
|
||||
ContentPrice: q.ContentPrice.replaceDB(db),
|
||||
MediaAsset: q.MediaAsset.replaceDB(db),
|
||||
Tenant: q.Tenant.replaceDB(db),
|
||||
TenantUser: q.TenantUser.replaceDB(db),
|
||||
User: q.User.replaceDB(db),
|
||||
}
|
||||
}
|
||||
|
||||
type queryCtx struct {
|
||||
Tenant *tenantQueryDo
|
||||
TenantUser *tenantUserQueryDo
|
||||
User *userQueryDo
|
||||
Content *contentQueryDo
|
||||
ContentAccess *contentAccessQueryDo
|
||||
ContentAsset *contentAssetQueryDo
|
||||
ContentPrice *contentPriceQueryDo
|
||||
MediaAsset *mediaAssetQueryDo
|
||||
Tenant *tenantQueryDo
|
||||
TenantUser *tenantUserQueryDo
|
||||
User *userQueryDo
|
||||
}
|
||||
|
||||
func (q *Query) WithContext(ctx context.Context) *queryCtx {
|
||||
return &queryCtx{
|
||||
Tenant: q.Tenant.WithContext(ctx),
|
||||
TenantUser: q.TenantUser.WithContext(ctx),
|
||||
User: q.User.WithContext(ctx),
|
||||
Content: q.Content.WithContext(ctx),
|
||||
ContentAccess: q.ContentAccess.WithContext(ctx),
|
||||
ContentAsset: q.ContentAsset.WithContext(ctx),
|
||||
ContentPrice: q.ContentPrice.WithContext(ctx),
|
||||
MediaAsset: q.MediaAsset.WithContext(ctx),
|
||||
Tenant: q.Tenant.WithContext(ctx),
|
||||
TenantUser: q.TenantUser.WithContext(ctx),
|
||||
User: q.User.WithContext(ctx),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user