feat: add content report governance
This commit is contained in:
67
backend/database/models/content_reports.gen.go
Normal file
67
backend/database/models/content_reports.gen.go
Normal file
@@ -0,0 +1,67 @@
|
||||
// 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"
|
||||
|
||||
"go.ipao.vip/gen"
|
||||
)
|
||||
|
||||
const TableNameContentReport = "content_reports"
|
||||
|
||||
// ContentReport mapped from table <content_reports>
|
||||
type ContentReport struct {
|
||||
ID int64 `gorm:"column:id;type:bigint;primaryKey;autoIncrement:true;comment:主键ID。" json:"id"` // 主键ID。
|
||||
TenantID int64 `gorm:"column:tenant_id;type:bigint;not null;comment:租户ID;用途:跨租户筛选与归属;约束:必须存在。" json:"tenant_id"` // 租户ID;用途:跨租户筛选与归属;约束:必须存在。
|
||||
ContentID int64 `gorm:"column:content_id;type:bigint;not null;comment:内容ID;用途:定位被举报内容;约束:必须存在。" json:"content_id"` // 内容ID;用途:定位被举报内容;约束:必须存在。
|
||||
ReporterID int64 `gorm:"column:reporter_id;type:bigint;not null;comment:举报用户ID;用途:追溯举报来源;约束:必须存在。" json:"reporter_id"` // 举报用户ID;用途:追溯举报来源;约束:必须存在。
|
||||
Reason string `gorm:"column:reason;type:character varying(64);not null;comment:举报原因;用途:快速分类;约束:建议前端枚举。" json:"reason"` // 举报原因;用途:快速分类;约束:建议前端枚举。
|
||||
Detail string `gorm:"column:detail;type:text;not null;comment:举报描述;用途:补充说明与证据描述;可为空字符串。" json:"detail"` // 举报描述;用途:补充说明与证据描述;可为空字符串。
|
||||
Status string `gorm:"column:status;type:character varying(32);not null;default:pending;comment:处置状态;用途:pending/approved/rejected;约束:默认 pending。" json:"status"` // 处置状态;用途:pending/approved/rejected;约束:默认 pending。
|
||||
HandledBy int64 `gorm:"column:handled_by;type:bigint;not null;comment:处理人ID;用途:审计追踪;默认 0 表示未处理。" json:"handled_by"` // 处理人ID;用途:审计追踪;默认 0 表示未处理。
|
||||
HandledAction string `gorm:"column:handled_action;type:character varying(32);not null;comment:处理动作;用途:记录处置动作如 block/unpublish/ignore;可为空字符串。" json:"handled_action"` // 处理动作;用途:记录处置动作如 block/unpublish/ignore;可为空字符串。
|
||||
HandledReason string `gorm:"column:handled_reason;type:character varying(255);not null;comment:处理说明;用途:超管处理备注;可为空字符串。" json:"handled_reason"` // 处理说明;用途:超管处理备注;可为空字符串。
|
||||
HandledAt time.Time `gorm:"column:handled_at;type:timestamp with time zone;comment:处理时间;用途:追踪处理时效;未处理为空。" json:"handled_at"` // 处理时间;用途:追踪处理时效;未处理为空。
|
||||
CreatedAt time.Time `gorm:"column:created_at;type:timestamp with time zone;not null;default:now();comment:创建时间;用途:统计与排序。" json:"created_at"` // 创建时间;用途:统计与排序。
|
||||
UpdatedAt time.Time `gorm:"column:updated_at;type:timestamp with time zone;not null;default:now();comment:更新时间;用途:状态变化追踪。" json:"updated_at"` // 更新时间;用途:状态变化追踪。
|
||||
}
|
||||
|
||||
// Quick operations without importing query package
|
||||
// Update applies changed fields to the database using the default DB.
|
||||
func (m *ContentReport) Update(ctx context.Context) (gen.ResultInfo, error) {
|
||||
return Q.ContentReport.WithContext(ctx).Updates(m)
|
||||
}
|
||||
|
||||
// Save upserts the model using the default DB.
|
||||
func (m *ContentReport) Save(ctx context.Context) error {
|
||||
return Q.ContentReport.WithContext(ctx).Save(m)
|
||||
}
|
||||
|
||||
// Create inserts the model using the default DB.
|
||||
func (m *ContentReport) Create(ctx context.Context) error {
|
||||
return Q.ContentReport.WithContext(ctx).Create(m)
|
||||
}
|
||||
|
||||
// Delete removes the row represented by the model using the default DB.
|
||||
func (m *ContentReport) Delete(ctx context.Context) (gen.ResultInfo, error) {
|
||||
return Q.ContentReport.WithContext(ctx).Delete(m)
|
||||
}
|
||||
|
||||
// ForceDelete permanently deletes the row (ignores soft delete) using the default DB.
|
||||
func (m *ContentReport) ForceDelete(ctx context.Context) (gen.ResultInfo, error) {
|
||||
return Q.ContentReport.WithContext(ctx).Unscoped().Delete(m)
|
||||
}
|
||||
|
||||
// Reload reloads the model from database by its primary key and overwrites current fields.
|
||||
func (m *ContentReport) Reload(ctx context.Context) error {
|
||||
fresh, err := Q.ContentReport.WithContext(ctx).GetByID(m.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
*m = *fresh
|
||||
return nil
|
||||
}
|
||||
509
backend/database/models/content_reports.query.gen.go
Normal file
509
backend/database/models/content_reports.query.gen.go
Normal file
@@ -0,0 +1,509 @@
|
||||
// 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 newContentReport(db *gorm.DB, opts ...gen.DOOption) contentReportQuery {
|
||||
_contentReportQuery := contentReportQuery{}
|
||||
|
||||
_contentReportQuery.contentReportQueryDo.UseDB(db, opts...)
|
||||
_contentReportQuery.contentReportQueryDo.UseModel(&ContentReport{})
|
||||
|
||||
tableName := _contentReportQuery.contentReportQueryDo.TableName()
|
||||
_contentReportQuery.ALL = field.NewAsterisk(tableName)
|
||||
_contentReportQuery.ID = field.NewInt64(tableName, "id")
|
||||
_contentReportQuery.TenantID = field.NewInt64(tableName, "tenant_id")
|
||||
_contentReportQuery.ContentID = field.NewInt64(tableName, "content_id")
|
||||
_contentReportQuery.ReporterID = field.NewInt64(tableName, "reporter_id")
|
||||
_contentReportQuery.Reason = field.NewString(tableName, "reason")
|
||||
_contentReportQuery.Detail = field.NewString(tableName, "detail")
|
||||
_contentReportQuery.Status = field.NewString(tableName, "status")
|
||||
_contentReportQuery.HandledBy = field.NewInt64(tableName, "handled_by")
|
||||
_contentReportQuery.HandledAction = field.NewString(tableName, "handled_action")
|
||||
_contentReportQuery.HandledReason = field.NewString(tableName, "handled_reason")
|
||||
_contentReportQuery.HandledAt = field.NewTime(tableName, "handled_at")
|
||||
_contentReportQuery.CreatedAt = field.NewTime(tableName, "created_at")
|
||||
_contentReportQuery.UpdatedAt = field.NewTime(tableName, "updated_at")
|
||||
|
||||
_contentReportQuery.fillFieldMap()
|
||||
|
||||
return _contentReportQuery
|
||||
}
|
||||
|
||||
type contentReportQuery struct {
|
||||
contentReportQueryDo contentReportQueryDo
|
||||
|
||||
ALL field.Asterisk
|
||||
ID field.Int64 // 主键ID。
|
||||
TenantID field.Int64 // 租户ID;用途:跨租户筛选与归属;约束:必须存在。
|
||||
ContentID field.Int64 // 内容ID;用途:定位被举报内容;约束:必须存在。
|
||||
ReporterID field.Int64 // 举报用户ID;用途:追溯举报来源;约束:必须存在。
|
||||
Reason field.String // 举报原因;用途:快速分类;约束:建议前端枚举。
|
||||
Detail field.String // 举报描述;用途:补充说明与证据描述;可为空字符串。
|
||||
Status field.String // 处置状态;用途:pending/approved/rejected;约束:默认 pending。
|
||||
HandledBy field.Int64 // 处理人ID;用途:审计追踪;默认 0 表示未处理。
|
||||
HandledAction field.String // 处理动作;用途:记录处置动作如 block/unpublish/ignore;可为空字符串。
|
||||
HandledReason field.String // 处理说明;用途:超管处理备注;可为空字符串。
|
||||
HandledAt field.Time // 处理时间;用途:追踪处理时效;未处理为空。
|
||||
CreatedAt field.Time // 创建时间;用途:统计与排序。
|
||||
UpdatedAt field.Time // 更新时间;用途:状态变化追踪。
|
||||
|
||||
fieldMap map[string]field.Expr
|
||||
}
|
||||
|
||||
func (c contentReportQuery) Table(newTableName string) *contentReportQuery {
|
||||
c.contentReportQueryDo.UseTable(newTableName)
|
||||
return c.updateTableName(newTableName)
|
||||
}
|
||||
|
||||
func (c contentReportQuery) As(alias string) *contentReportQuery {
|
||||
c.contentReportQueryDo.DO = *(c.contentReportQueryDo.As(alias).(*gen.DO))
|
||||
return c.updateTableName(alias)
|
||||
}
|
||||
|
||||
func (c *contentReportQuery) updateTableName(table string) *contentReportQuery {
|
||||
c.ALL = field.NewAsterisk(table)
|
||||
c.ID = field.NewInt64(table, "id")
|
||||
c.TenantID = field.NewInt64(table, "tenant_id")
|
||||
c.ContentID = field.NewInt64(table, "content_id")
|
||||
c.ReporterID = field.NewInt64(table, "reporter_id")
|
||||
c.Reason = field.NewString(table, "reason")
|
||||
c.Detail = field.NewString(table, "detail")
|
||||
c.Status = field.NewString(table, "status")
|
||||
c.HandledBy = field.NewInt64(table, "handled_by")
|
||||
c.HandledAction = field.NewString(table, "handled_action")
|
||||
c.HandledReason = field.NewString(table, "handled_reason")
|
||||
c.HandledAt = field.NewTime(table, "handled_at")
|
||||
c.CreatedAt = field.NewTime(table, "created_at")
|
||||
c.UpdatedAt = field.NewTime(table, "updated_at")
|
||||
|
||||
c.fillFieldMap()
|
||||
|
||||
return c
|
||||
}
|
||||
|
||||
func (c *contentReportQuery) QueryContext(ctx context.Context) (*contentReportQuery, *contentReportQueryDo) {
|
||||
return c, c.contentReportQueryDo.WithContext(ctx)
|
||||
}
|
||||
|
||||
func (c *contentReportQuery) WithContext(ctx context.Context) *contentReportQueryDo {
|
||||
return c.contentReportQueryDo.WithContext(ctx)
|
||||
}
|
||||
|
||||
func (c contentReportQuery) TableName() string { return c.contentReportQueryDo.TableName() }
|
||||
|
||||
func (c contentReportQuery) Alias() string { return c.contentReportQueryDo.Alias() }
|
||||
|
||||
func (c contentReportQuery) Columns(cols ...field.Expr) gen.Columns {
|
||||
return c.contentReportQueryDo.Columns(cols...)
|
||||
}
|
||||
|
||||
func (c *contentReportQuery) 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 *contentReportQuery) fillFieldMap() {
|
||||
c.fieldMap = make(map[string]field.Expr, 13)
|
||||
c.fieldMap["id"] = c.ID
|
||||
c.fieldMap["tenant_id"] = c.TenantID
|
||||
c.fieldMap["content_id"] = c.ContentID
|
||||
c.fieldMap["reporter_id"] = c.ReporterID
|
||||
c.fieldMap["reason"] = c.Reason
|
||||
c.fieldMap["detail"] = c.Detail
|
||||
c.fieldMap["status"] = c.Status
|
||||
c.fieldMap["handled_by"] = c.HandledBy
|
||||
c.fieldMap["handled_action"] = c.HandledAction
|
||||
c.fieldMap["handled_reason"] = c.HandledReason
|
||||
c.fieldMap["handled_at"] = c.HandledAt
|
||||
c.fieldMap["created_at"] = c.CreatedAt
|
||||
c.fieldMap["updated_at"] = c.UpdatedAt
|
||||
}
|
||||
|
||||
func (c contentReportQuery) clone(db *gorm.DB) contentReportQuery {
|
||||
c.contentReportQueryDo.ReplaceConnPool(db.Statement.ConnPool)
|
||||
return c
|
||||
}
|
||||
|
||||
func (c contentReportQuery) replaceDB(db *gorm.DB) contentReportQuery {
|
||||
c.contentReportQueryDo.ReplaceDB(db)
|
||||
return c
|
||||
}
|
||||
|
||||
type contentReportQueryDo struct{ gen.DO }
|
||||
|
||||
func (c contentReportQueryDo) Debug() *contentReportQueryDo {
|
||||
return c.withDO(c.DO.Debug())
|
||||
}
|
||||
|
||||
func (c contentReportQueryDo) WithContext(ctx context.Context) *contentReportQueryDo {
|
||||
return c.withDO(c.DO.WithContext(ctx))
|
||||
}
|
||||
|
||||
func (c contentReportQueryDo) ReadDB() *contentReportQueryDo {
|
||||
return c.Clauses(dbresolver.Read)
|
||||
}
|
||||
|
||||
func (c contentReportQueryDo) WriteDB() *contentReportQueryDo {
|
||||
return c.Clauses(dbresolver.Write)
|
||||
}
|
||||
|
||||
func (c contentReportQueryDo) Session(config *gorm.Session) *contentReportQueryDo {
|
||||
return c.withDO(c.DO.Session(config))
|
||||
}
|
||||
|
||||
func (c contentReportQueryDo) Clauses(conds ...clause.Expression) *contentReportQueryDo {
|
||||
return c.withDO(c.DO.Clauses(conds...))
|
||||
}
|
||||
|
||||
func (c contentReportQueryDo) Returning(value interface{}, columns ...string) *contentReportQueryDo {
|
||||
return c.withDO(c.DO.Returning(value, columns...))
|
||||
}
|
||||
|
||||
func (c contentReportQueryDo) Not(conds ...gen.Condition) *contentReportQueryDo {
|
||||
return c.withDO(c.DO.Not(conds...))
|
||||
}
|
||||
|
||||
func (c contentReportQueryDo) Or(conds ...gen.Condition) *contentReportQueryDo {
|
||||
return c.withDO(c.DO.Or(conds...))
|
||||
}
|
||||
|
||||
func (c contentReportQueryDo) Select(conds ...field.Expr) *contentReportQueryDo {
|
||||
return c.withDO(c.DO.Select(conds...))
|
||||
}
|
||||
|
||||
func (c contentReportQueryDo) Where(conds ...gen.Condition) *contentReportQueryDo {
|
||||
return c.withDO(c.DO.Where(conds...))
|
||||
}
|
||||
|
||||
func (c contentReportQueryDo) Order(conds ...field.Expr) *contentReportQueryDo {
|
||||
return c.withDO(c.DO.Order(conds...))
|
||||
}
|
||||
|
||||
func (c contentReportQueryDo) Distinct(cols ...field.Expr) *contentReportQueryDo {
|
||||
return c.withDO(c.DO.Distinct(cols...))
|
||||
}
|
||||
|
||||
func (c contentReportQueryDo) Omit(cols ...field.Expr) *contentReportQueryDo {
|
||||
return c.withDO(c.DO.Omit(cols...))
|
||||
}
|
||||
|
||||
func (c contentReportQueryDo) Join(table schema.Tabler, on ...field.Expr) *contentReportQueryDo {
|
||||
return c.withDO(c.DO.Join(table, on...))
|
||||
}
|
||||
|
||||
func (c contentReportQueryDo) LeftJoin(table schema.Tabler, on ...field.Expr) *contentReportQueryDo {
|
||||
return c.withDO(c.DO.LeftJoin(table, on...))
|
||||
}
|
||||
|
||||
func (c contentReportQueryDo) RightJoin(table schema.Tabler, on ...field.Expr) *contentReportQueryDo {
|
||||
return c.withDO(c.DO.RightJoin(table, on...))
|
||||
}
|
||||
|
||||
func (c contentReportQueryDo) Group(cols ...field.Expr) *contentReportQueryDo {
|
||||
return c.withDO(c.DO.Group(cols...))
|
||||
}
|
||||
|
||||
func (c contentReportQueryDo) Having(conds ...gen.Condition) *contentReportQueryDo {
|
||||
return c.withDO(c.DO.Having(conds...))
|
||||
}
|
||||
|
||||
func (c contentReportQueryDo) Limit(limit int) *contentReportQueryDo {
|
||||
return c.withDO(c.DO.Limit(limit))
|
||||
}
|
||||
|
||||
func (c contentReportQueryDo) Offset(offset int) *contentReportQueryDo {
|
||||
return c.withDO(c.DO.Offset(offset))
|
||||
}
|
||||
|
||||
func (c contentReportQueryDo) Scopes(funcs ...func(gen.Dao) gen.Dao) *contentReportQueryDo {
|
||||
return c.withDO(c.DO.Scopes(funcs...))
|
||||
}
|
||||
|
||||
func (c contentReportQueryDo) Unscoped() *contentReportQueryDo {
|
||||
return c.withDO(c.DO.Unscoped())
|
||||
}
|
||||
|
||||
func (c contentReportQueryDo) Create(values ...*ContentReport) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return c.DO.Create(values)
|
||||
}
|
||||
|
||||
func (c contentReportQueryDo) CreateInBatches(values []*ContentReport, 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 contentReportQueryDo) Save(values ...*ContentReport) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return c.DO.Save(values)
|
||||
}
|
||||
|
||||
func (c contentReportQueryDo) First() (*ContentReport, error) {
|
||||
if result, err := c.DO.First(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*ContentReport), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (c contentReportQueryDo) Take() (*ContentReport, error) {
|
||||
if result, err := c.DO.Take(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*ContentReport), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (c contentReportQueryDo) Last() (*ContentReport, error) {
|
||||
if result, err := c.DO.Last(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*ContentReport), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (c contentReportQueryDo) Find() ([]*ContentReport, error) {
|
||||
result, err := c.DO.Find()
|
||||
return result.([]*ContentReport), err
|
||||
}
|
||||
|
||||
func (c contentReportQueryDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*ContentReport, err error) {
|
||||
buf := make([]*ContentReport, 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 contentReportQueryDo) FindInBatches(result *[]*ContentReport, batchSize int, fc func(tx gen.Dao, batch int) error) error {
|
||||
return c.DO.FindInBatches(result, batchSize, fc)
|
||||
}
|
||||
|
||||
func (c contentReportQueryDo) Attrs(attrs ...field.AssignExpr) *contentReportQueryDo {
|
||||
return c.withDO(c.DO.Attrs(attrs...))
|
||||
}
|
||||
|
||||
func (c contentReportQueryDo) Assign(attrs ...field.AssignExpr) *contentReportQueryDo {
|
||||
return c.withDO(c.DO.Assign(attrs...))
|
||||
}
|
||||
|
||||
func (c contentReportQueryDo) Joins(fields ...field.RelationField) *contentReportQueryDo {
|
||||
for _, _f := range fields {
|
||||
c = *c.withDO(c.DO.Joins(_f))
|
||||
}
|
||||
return &c
|
||||
}
|
||||
|
||||
func (c contentReportQueryDo) Preload(fields ...field.RelationField) *contentReportQueryDo {
|
||||
for _, _f := range fields {
|
||||
c = *c.withDO(c.DO.Preload(_f))
|
||||
}
|
||||
return &c
|
||||
}
|
||||
|
||||
func (c contentReportQueryDo) FirstOrInit() (*ContentReport, error) {
|
||||
if result, err := c.DO.FirstOrInit(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*ContentReport), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (c contentReportQueryDo) FirstOrCreate() (*ContentReport, error) {
|
||||
if result, err := c.DO.FirstOrCreate(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*ContentReport), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (c contentReportQueryDo) FindByPage(offset int, limit int) (result []*ContentReport, 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 contentReportQueryDo) 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 contentReportQueryDo) Scan(result interface{}) (err error) {
|
||||
return c.DO.Scan(result)
|
||||
}
|
||||
|
||||
func (c contentReportQueryDo) Delete(models ...*ContentReport) (result gen.ResultInfo, err error) {
|
||||
return c.DO.Delete(models)
|
||||
}
|
||||
|
||||
// ForceDelete performs a permanent delete (ignores soft-delete) for current scope.
|
||||
func (c contentReportQueryDo) ForceDelete() (gen.ResultInfo, error) {
|
||||
return c.Unscoped().Delete()
|
||||
}
|
||||
|
||||
// Inc increases the given column by step for current scope.
|
||||
func (c contentReportQueryDo) 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 contentReportQueryDo) 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 contentReportQueryDo) 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 contentReportQueryDo) 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 contentReportQueryDo) 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 contentReportQueryDo) 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 contentReportQueryDo) 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 contentReportQueryDo) 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 contentReportQueryDo) 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 contentReportQueryDo) GetByID(id int64) (*ContentReport, error) {
|
||||
pk := field.NewInt64(c.TableName(), "id")
|
||||
return c.Where(pk.Eq(id)).First()
|
||||
}
|
||||
|
||||
// GetByIDs finds records by primary key list.
|
||||
func (c contentReportQueryDo) GetByIDs(ids ...int64) ([]*ContentReport, error) {
|
||||
if len(ids) == 0 {
|
||||
return []*ContentReport{}, nil
|
||||
}
|
||||
pk := field.NewInt64(c.TableName(), "id")
|
||||
return c.Where(pk.In(ids...)).Find()
|
||||
}
|
||||
|
||||
// DeleteByID deletes records by primary key.
|
||||
func (c contentReportQueryDo) 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 contentReportQueryDo) 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 *contentReportQueryDo) withDO(do gen.Dao) *contentReportQueryDo {
|
||||
c.DO = *do.(*gen.DO)
|
||||
return c
|
||||
}
|
||||
@@ -40,9 +40,9 @@ type Content struct {
|
||||
DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;type:timestamp with time zone" json:"deleted_at"`
|
||||
Key string `gorm:"column:key;type:character varying(32);comment:Musical key/tone" json:"key"` // Musical key/tone
|
||||
IsPinned bool `gorm:"column:is_pinned;type:boolean;comment:Whether content is pinned/featured" json:"is_pinned"` // Whether content is pinned/featured
|
||||
Author *User `gorm:"foreignKey:UserID;references:ID" json:"author,omitempty"`
|
||||
ContentAssets []*ContentAsset `gorm:"foreignKey:ContentID;references:ID" json:"content_assets,omitempty"`
|
||||
Comments []*Comment `gorm:"foreignKey:ContentID;references:ID" json:"comments,omitempty"`
|
||||
Author *User `gorm:"foreignKey:UserID;references:ID" json:"author,omitempty"`
|
||||
}
|
||||
|
||||
// Quick operations without importing query package
|
||||
|
||||
@@ -46,6 +46,12 @@ func newContent(db *gorm.DB, opts ...gen.DOOption) contentQuery {
|
||||
_contentQuery.DeletedAt = field.NewField(tableName, "deleted_at")
|
||||
_contentQuery.Key = field.NewString(tableName, "key")
|
||||
_contentQuery.IsPinned = field.NewBool(tableName, "is_pinned")
|
||||
_contentQuery.Author = contentQueryBelongsToAuthor{
|
||||
db: db.Session(&gorm.Session{}),
|
||||
|
||||
RelationField: field.NewRelation("Author", "User"),
|
||||
}
|
||||
|
||||
_contentQuery.ContentAssets = contentQueryHasManyContentAssets{
|
||||
db: db.Session(&gorm.Session{}),
|
||||
|
||||
@@ -58,12 +64,6 @@ func newContent(db *gorm.DB, opts ...gen.DOOption) contentQuery {
|
||||
RelationField: field.NewRelation("Comments", "Comment"),
|
||||
}
|
||||
|
||||
_contentQuery.Author = contentQueryBelongsToAuthor{
|
||||
db: db.Session(&gorm.Session{}),
|
||||
|
||||
RelationField: field.NewRelation("Author", "User"),
|
||||
}
|
||||
|
||||
_contentQuery.fillFieldMap()
|
||||
|
||||
return _contentQuery
|
||||
@@ -94,12 +94,12 @@ type contentQuery struct {
|
||||
DeletedAt field.Field
|
||||
Key field.String // Musical key/tone
|
||||
IsPinned field.Bool // Whether content is pinned/featured
|
||||
ContentAssets contentQueryHasManyContentAssets
|
||||
Author contentQueryBelongsToAuthor
|
||||
|
||||
ContentAssets contentQueryHasManyContentAssets
|
||||
|
||||
Comments contentQueryHasManyComments
|
||||
|
||||
Author contentQueryBelongsToAuthor
|
||||
|
||||
fieldMap map[string]field.Expr
|
||||
}
|
||||
|
||||
@@ -195,23 +195,104 @@ func (c *contentQuery) fillFieldMap() {
|
||||
|
||||
func (c contentQuery) clone(db *gorm.DB) contentQuery {
|
||||
c.contentQueryDo.ReplaceConnPool(db.Statement.ConnPool)
|
||||
c.Author.db = db.Session(&gorm.Session{Initialized: true})
|
||||
c.Author.db.Statement.ConnPool = db.Statement.ConnPool
|
||||
c.ContentAssets.db = db.Session(&gorm.Session{Initialized: true})
|
||||
c.ContentAssets.db.Statement.ConnPool = db.Statement.ConnPool
|
||||
c.Comments.db = db.Session(&gorm.Session{Initialized: true})
|
||||
c.Comments.db.Statement.ConnPool = db.Statement.ConnPool
|
||||
c.Author.db = db.Session(&gorm.Session{Initialized: true})
|
||||
c.Author.db.Statement.ConnPool = db.Statement.ConnPool
|
||||
return c
|
||||
}
|
||||
|
||||
func (c contentQuery) replaceDB(db *gorm.DB) contentQuery {
|
||||
c.contentQueryDo.ReplaceDB(db)
|
||||
c.Author.db = db.Session(&gorm.Session{})
|
||||
c.ContentAssets.db = db.Session(&gorm.Session{})
|
||||
c.Comments.db = db.Session(&gorm.Session{})
|
||||
c.Author.db = db.Session(&gorm.Session{})
|
||||
return c
|
||||
}
|
||||
|
||||
type contentQueryBelongsToAuthor struct {
|
||||
db *gorm.DB
|
||||
|
||||
field.RelationField
|
||||
}
|
||||
|
||||
func (a contentQueryBelongsToAuthor) Where(conds ...field.Expr) *contentQueryBelongsToAuthor {
|
||||
if len(conds) == 0 {
|
||||
return &a
|
||||
}
|
||||
|
||||
exprs := make([]clause.Expression, 0, len(conds))
|
||||
for _, cond := range conds {
|
||||
exprs = append(exprs, cond.BeCond().(clause.Expression))
|
||||
}
|
||||
a.db = a.db.Clauses(clause.Where{Exprs: exprs})
|
||||
return &a
|
||||
}
|
||||
|
||||
func (a contentQueryBelongsToAuthor) WithContext(ctx context.Context) *contentQueryBelongsToAuthor {
|
||||
a.db = a.db.WithContext(ctx)
|
||||
return &a
|
||||
}
|
||||
|
||||
func (a contentQueryBelongsToAuthor) Session(session *gorm.Session) *contentQueryBelongsToAuthor {
|
||||
a.db = a.db.Session(session)
|
||||
return &a
|
||||
}
|
||||
|
||||
func (a contentQueryBelongsToAuthor) Model(m *Content) *contentQueryBelongsToAuthorTx {
|
||||
return &contentQueryBelongsToAuthorTx{a.db.Model(m).Association(a.Name())}
|
||||
}
|
||||
|
||||
func (a contentQueryBelongsToAuthor) Unscoped() *contentQueryBelongsToAuthor {
|
||||
a.db = a.db.Unscoped()
|
||||
return &a
|
||||
}
|
||||
|
||||
type contentQueryBelongsToAuthorTx struct{ tx *gorm.Association }
|
||||
|
||||
func (a contentQueryBelongsToAuthorTx) Find() (result *User, err error) {
|
||||
return result, a.tx.Find(&result)
|
||||
}
|
||||
|
||||
func (a contentQueryBelongsToAuthorTx) Append(values ...*User) (err error) {
|
||||
targetValues := make([]interface{}, len(values))
|
||||
for i, v := range values {
|
||||
targetValues[i] = v
|
||||
}
|
||||
return a.tx.Append(targetValues...)
|
||||
}
|
||||
|
||||
func (a contentQueryBelongsToAuthorTx) Replace(values ...*User) (err error) {
|
||||
targetValues := make([]interface{}, len(values))
|
||||
for i, v := range values {
|
||||
targetValues[i] = v
|
||||
}
|
||||
return a.tx.Replace(targetValues...)
|
||||
}
|
||||
|
||||
func (a contentQueryBelongsToAuthorTx) Delete(values ...*User) (err error) {
|
||||
targetValues := make([]interface{}, len(values))
|
||||
for i, v := range values {
|
||||
targetValues[i] = v
|
||||
}
|
||||
return a.tx.Delete(targetValues...)
|
||||
}
|
||||
|
||||
func (a contentQueryBelongsToAuthorTx) Clear() error {
|
||||
return a.tx.Clear()
|
||||
}
|
||||
|
||||
func (a contentQueryBelongsToAuthorTx) Count() int64 {
|
||||
return a.tx.Count()
|
||||
}
|
||||
|
||||
func (a contentQueryBelongsToAuthorTx) Unscoped() *contentQueryBelongsToAuthorTx {
|
||||
a.tx = a.tx.Unscoped()
|
||||
return &a
|
||||
}
|
||||
|
||||
type contentQueryHasManyContentAssets struct {
|
||||
db *gorm.DB
|
||||
|
||||
@@ -374,87 +455,6 @@ func (a contentQueryHasManyCommentsTx) Unscoped() *contentQueryHasManyCommentsTx
|
||||
return &a
|
||||
}
|
||||
|
||||
type contentQueryBelongsToAuthor struct {
|
||||
db *gorm.DB
|
||||
|
||||
field.RelationField
|
||||
}
|
||||
|
||||
func (a contentQueryBelongsToAuthor) Where(conds ...field.Expr) *contentQueryBelongsToAuthor {
|
||||
if len(conds) == 0 {
|
||||
return &a
|
||||
}
|
||||
|
||||
exprs := make([]clause.Expression, 0, len(conds))
|
||||
for _, cond := range conds {
|
||||
exprs = append(exprs, cond.BeCond().(clause.Expression))
|
||||
}
|
||||
a.db = a.db.Clauses(clause.Where{Exprs: exprs})
|
||||
return &a
|
||||
}
|
||||
|
||||
func (a contentQueryBelongsToAuthor) WithContext(ctx context.Context) *contentQueryBelongsToAuthor {
|
||||
a.db = a.db.WithContext(ctx)
|
||||
return &a
|
||||
}
|
||||
|
||||
func (a contentQueryBelongsToAuthor) Session(session *gorm.Session) *contentQueryBelongsToAuthor {
|
||||
a.db = a.db.Session(session)
|
||||
return &a
|
||||
}
|
||||
|
||||
func (a contentQueryBelongsToAuthor) Model(m *Content) *contentQueryBelongsToAuthorTx {
|
||||
return &contentQueryBelongsToAuthorTx{a.db.Model(m).Association(a.Name())}
|
||||
}
|
||||
|
||||
func (a contentQueryBelongsToAuthor) Unscoped() *contentQueryBelongsToAuthor {
|
||||
a.db = a.db.Unscoped()
|
||||
return &a
|
||||
}
|
||||
|
||||
type contentQueryBelongsToAuthorTx struct{ tx *gorm.Association }
|
||||
|
||||
func (a contentQueryBelongsToAuthorTx) Find() (result *User, err error) {
|
||||
return result, a.tx.Find(&result)
|
||||
}
|
||||
|
||||
func (a contentQueryBelongsToAuthorTx) Append(values ...*User) (err error) {
|
||||
targetValues := make([]interface{}, len(values))
|
||||
for i, v := range values {
|
||||
targetValues[i] = v
|
||||
}
|
||||
return a.tx.Append(targetValues...)
|
||||
}
|
||||
|
||||
func (a contentQueryBelongsToAuthorTx) Replace(values ...*User) (err error) {
|
||||
targetValues := make([]interface{}, len(values))
|
||||
for i, v := range values {
|
||||
targetValues[i] = v
|
||||
}
|
||||
return a.tx.Replace(targetValues...)
|
||||
}
|
||||
|
||||
func (a contentQueryBelongsToAuthorTx) Delete(values ...*User) (err error) {
|
||||
targetValues := make([]interface{}, len(values))
|
||||
for i, v := range values {
|
||||
targetValues[i] = v
|
||||
}
|
||||
return a.tx.Delete(targetValues...)
|
||||
}
|
||||
|
||||
func (a contentQueryBelongsToAuthorTx) Clear() error {
|
||||
return a.tx.Clear()
|
||||
}
|
||||
|
||||
func (a contentQueryBelongsToAuthorTx) Count() int64 {
|
||||
return a.tx.Count()
|
||||
}
|
||||
|
||||
func (a contentQueryBelongsToAuthorTx) Unscoped() *contentQueryBelongsToAuthorTx {
|
||||
a.tx = a.tx.Unscoped()
|
||||
return &a
|
||||
}
|
||||
|
||||
type contentQueryDo struct{ gen.DO }
|
||||
|
||||
func (c contentQueryDo) Debug() *contentQueryDo {
|
||||
|
||||
@@ -23,6 +23,7 @@ var (
|
||||
ContentAccessQuery *contentAccessQuery
|
||||
ContentAssetQuery *contentAssetQuery
|
||||
ContentPriceQuery *contentPriceQuery
|
||||
ContentReportQuery *contentReportQuery
|
||||
CouponQuery *couponQuery
|
||||
MediaAssetQuery *mediaAssetQuery
|
||||
NotificationQuery *notificationQuery
|
||||
@@ -50,6 +51,7 @@ func SetDefault(db *gorm.DB, opts ...gen.DOOption) {
|
||||
ContentAccessQuery = &Q.ContentAccess
|
||||
ContentAssetQuery = &Q.ContentAsset
|
||||
ContentPriceQuery = &Q.ContentPrice
|
||||
ContentReportQuery = &Q.ContentReport
|
||||
CouponQuery = &Q.Coupon
|
||||
MediaAssetQuery = &Q.MediaAsset
|
||||
NotificationQuery = &Q.Notification
|
||||
@@ -78,6 +80,7 @@ func Use(db *gorm.DB, opts ...gen.DOOption) *Query {
|
||||
ContentAccess: newContentAccess(db, opts...),
|
||||
ContentAsset: newContentAsset(db, opts...),
|
||||
ContentPrice: newContentPrice(db, opts...),
|
||||
ContentReport: newContentReport(db, opts...),
|
||||
Coupon: newCoupon(db, opts...),
|
||||
MediaAsset: newMediaAsset(db, opts...),
|
||||
Notification: newNotification(db, opts...),
|
||||
@@ -107,6 +110,7 @@ type Query struct {
|
||||
ContentAccess contentAccessQuery
|
||||
ContentAsset contentAssetQuery
|
||||
ContentPrice contentPriceQuery
|
||||
ContentReport contentReportQuery
|
||||
Coupon couponQuery
|
||||
MediaAsset mediaAssetQuery
|
||||
Notification notificationQuery
|
||||
@@ -137,6 +141,7 @@ func (q *Query) clone(db *gorm.DB) *Query {
|
||||
ContentAccess: q.ContentAccess.clone(db),
|
||||
ContentAsset: q.ContentAsset.clone(db),
|
||||
ContentPrice: q.ContentPrice.clone(db),
|
||||
ContentReport: q.ContentReport.clone(db),
|
||||
Coupon: q.Coupon.clone(db),
|
||||
MediaAsset: q.MediaAsset.clone(db),
|
||||
Notification: q.Notification.clone(db),
|
||||
@@ -174,6 +179,7 @@ func (q *Query) ReplaceDB(db *gorm.DB) *Query {
|
||||
ContentAccess: q.ContentAccess.replaceDB(db),
|
||||
ContentAsset: q.ContentAsset.replaceDB(db),
|
||||
ContentPrice: q.ContentPrice.replaceDB(db),
|
||||
ContentReport: q.ContentReport.replaceDB(db),
|
||||
Coupon: q.Coupon.replaceDB(db),
|
||||
MediaAsset: q.MediaAsset.replaceDB(db),
|
||||
Notification: q.Notification.replaceDB(db),
|
||||
@@ -201,6 +207,7 @@ type queryCtx struct {
|
||||
ContentAccess *contentAccessQueryDo
|
||||
ContentAsset *contentAssetQueryDo
|
||||
ContentPrice *contentPriceQueryDo
|
||||
ContentReport *contentReportQueryDo
|
||||
Coupon *couponQueryDo
|
||||
MediaAsset *mediaAssetQueryDo
|
||||
Notification *notificationQueryDo
|
||||
@@ -228,6 +235,7 @@ func (q *Query) WithContext(ctx context.Context) *queryCtx {
|
||||
ContentAccess: q.ContentAccess.WithContext(ctx),
|
||||
ContentAsset: q.ContentAsset.WithContext(ctx),
|
||||
ContentPrice: q.ContentPrice.WithContext(ctx),
|
||||
ContentReport: q.ContentReport.WithContext(ctx),
|
||||
Coupon: q.Coupon.WithContext(ctx),
|
||||
MediaAsset: q.MediaAsset.WithContext(ctx),
|
||||
Notification: q.Notification.WithContext(ctx),
|
||||
|
||||
Reference in New Issue
Block a user