feat: add audit logs and system configs
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
-- +goose Up
|
||||
-- +goose StatementBegin
|
||||
CREATE TABLE IF NOT EXISTS audit_logs (
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
tenant_id BIGINT NOT NULL DEFAULT 0,
|
||||
operator_id BIGINT NOT NULL,
|
||||
action VARCHAR(64) NOT NULL,
|
||||
target_id VARCHAR(64) NOT NULL DEFAULT '',
|
||||
detail TEXT NOT NULL DEFAULT '',
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
|
||||
);
|
||||
|
||||
COMMENT ON TABLE audit_logs IS '审计日志:记录超管关键操作,用于追溯与合规审查。';
|
||||
COMMENT ON COLUMN audit_logs.id IS '主键ID。';
|
||||
COMMENT ON COLUMN audit_logs.tenant_id IS '租户ID;用途:关联租户审计(0表示平台级)。';
|
||||
COMMENT ON COLUMN audit_logs.operator_id IS '操作者用户ID;用途:审计追溯;约束:必须存在。';
|
||||
COMMENT ON COLUMN audit_logs.action IS '动作标识;用途:检索分类;约束:例如 review_content/freeze_coupon。';
|
||||
COMMENT ON COLUMN audit_logs.target_id IS '目标ID;用途:定位被操作对象;可为空字符串。';
|
||||
COMMENT ON COLUMN audit_logs.detail IS '动作详情;用途:记录操作原因与补充说明。';
|
||||
COMMENT ON COLUMN audit_logs.created_at IS '创建时间;用途:时间序列查询与审计留存。';
|
||||
|
||||
CREATE INDEX IF NOT EXISTS audit_logs_tenant_id_idx ON audit_logs(tenant_id);
|
||||
CREATE INDEX IF NOT EXISTS audit_logs_operator_id_idx ON audit_logs(operator_id);
|
||||
CREATE INDEX IF NOT EXISTS audit_logs_action_idx ON audit_logs(action);
|
||||
CREATE INDEX IF NOT EXISTS audit_logs_created_at_idx ON audit_logs(created_at);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS system_configs (
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
config_key VARCHAR(64) NOT NULL,
|
||||
value JSONB NOT NULL DEFAULT '{}'::jsonb,
|
||||
description VARCHAR(255) NOT NULL DEFAULT '',
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
||||
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
|
||||
);
|
||||
|
||||
COMMENT ON TABLE system_configs IS '系统配置:平台级可配置项(JSON);用于功能开关与运营参数。';
|
||||
COMMENT ON COLUMN system_configs.id IS '主键ID。';
|
||||
COMMENT ON COLUMN system_configs.config_key IS '配置项Key;用途:按Key读取/更新;约束:唯一。';
|
||||
COMMENT ON COLUMN system_configs.value IS '配置值(JSON);用途:存储任意结构化配置;默认 {}。';
|
||||
COMMENT ON COLUMN system_configs.description IS '配置说明;用途:给运营/技术理解用途。';
|
||||
COMMENT ON COLUMN system_configs.created_at IS '创建时间;用途:审计与追溯。';
|
||||
COMMENT ON COLUMN system_configs.updated_at IS '更新时间;用途:变更记录。';
|
||||
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS system_configs_config_key_uindex ON system_configs(config_key);
|
||||
CREATE INDEX IF NOT EXISTS system_configs_updated_at_idx ON system_configs(updated_at);
|
||||
-- +goose StatementEnd
|
||||
|
||||
-- +goose Down
|
||||
-- +goose StatementBegin
|
||||
DROP TABLE IF EXISTS system_configs;
|
||||
DROP TABLE IF EXISTS audit_logs;
|
||||
-- +goose StatementEnd
|
||||
57
backend/database/models/audit_logs.gen.go
Normal file
57
backend/database/models/audit_logs.gen.go
Normal file
@@ -0,0 +1,57 @@
|
||||
// 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 TableNameAuditLog = "audit_logs"
|
||||
|
||||
// AuditLog mapped from table <audit_logs>
|
||||
type AuditLog 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;用途:关联租户审计(0表示平台级)。" json:"tenant_id"` // 租户ID;用途:关联租户审计(0表示平台级)。
|
||||
OperatorID int64 `gorm:"column:operator_id;type:bigint;not null;comment:操作者用户ID;用途:审计追溯;约束:必须存在。" json:"operator_id"` // 操作者用户ID;用途:审计追溯;约束:必须存在。
|
||||
Action string `gorm:"column:action;type:character varying(64);not null;comment:动作标识;用途:检索分类;约束:例如 review_content/freeze_coupon。" json:"action"` // 动作标识;用途:检索分类;约束:例如 review_content/freeze_coupon。
|
||||
TargetID string `gorm:"column:target_id;type:character varying(64);not null;comment:目标ID;用途:定位被操作对象;可为空字符串。" json:"target_id"` // 目标ID;用途:定位被操作对象;可为空字符串。
|
||||
Detail string `gorm:"column:detail;type:text;not null;comment:动作详情;用途:记录操作原因与补充说明。" json:"detail"` // 动作详情;用途:记录操作原因与补充说明。
|
||||
CreatedAt time.Time `gorm:"column:created_at;type:timestamp with time zone;not null;default:now();comment:创建时间;用途:时间序列查询与审计留存。" json:"created_at"` // 创建时间;用途:时间序列查询与审计留存。
|
||||
}
|
||||
|
||||
// Quick operations without importing query package
|
||||
// Update applies changed fields to the database using the default DB.
|
||||
func (m *AuditLog) Update(ctx context.Context) (gen.ResultInfo, error) {
|
||||
return Q.AuditLog.WithContext(ctx).Updates(m)
|
||||
}
|
||||
|
||||
// Save upserts the model using the default DB.
|
||||
func (m *AuditLog) Save(ctx context.Context) error { return Q.AuditLog.WithContext(ctx).Save(m) }
|
||||
|
||||
// Create inserts the model using the default DB.
|
||||
func (m *AuditLog) Create(ctx context.Context) error { return Q.AuditLog.WithContext(ctx).Create(m) }
|
||||
|
||||
// Delete removes the row represented by the model using the default DB.
|
||||
func (m *AuditLog) Delete(ctx context.Context) (gen.ResultInfo, error) {
|
||||
return Q.AuditLog.WithContext(ctx).Delete(m)
|
||||
}
|
||||
|
||||
// ForceDelete permanently deletes the row (ignores soft delete) using the default DB.
|
||||
func (m *AuditLog) ForceDelete(ctx context.Context) (gen.ResultInfo, error) {
|
||||
return Q.AuditLog.WithContext(ctx).Unscoped().Delete(m)
|
||||
}
|
||||
|
||||
// Reload reloads the model from database by its primary key and overwrites current fields.
|
||||
func (m *AuditLog) Reload(ctx context.Context) error {
|
||||
fresh, err := Q.AuditLog.WithContext(ctx).GetByID(m.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
*m = *fresh
|
||||
return nil
|
||||
}
|
||||
485
backend/database/models/audit_logs.query.gen.go
Normal file
485
backend/database/models/audit_logs.query.gen.go
Normal file
@@ -0,0 +1,485 @@
|
||||
// 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 newAuditLog(db *gorm.DB, opts ...gen.DOOption) auditLogQuery {
|
||||
_auditLogQuery := auditLogQuery{}
|
||||
|
||||
_auditLogQuery.auditLogQueryDo.UseDB(db, opts...)
|
||||
_auditLogQuery.auditLogQueryDo.UseModel(&AuditLog{})
|
||||
|
||||
tableName := _auditLogQuery.auditLogQueryDo.TableName()
|
||||
_auditLogQuery.ALL = field.NewAsterisk(tableName)
|
||||
_auditLogQuery.ID = field.NewInt64(tableName, "id")
|
||||
_auditLogQuery.TenantID = field.NewInt64(tableName, "tenant_id")
|
||||
_auditLogQuery.OperatorID = field.NewInt64(tableName, "operator_id")
|
||||
_auditLogQuery.Action = field.NewString(tableName, "action")
|
||||
_auditLogQuery.TargetID = field.NewString(tableName, "target_id")
|
||||
_auditLogQuery.Detail = field.NewString(tableName, "detail")
|
||||
_auditLogQuery.CreatedAt = field.NewTime(tableName, "created_at")
|
||||
|
||||
_auditLogQuery.fillFieldMap()
|
||||
|
||||
return _auditLogQuery
|
||||
}
|
||||
|
||||
type auditLogQuery struct {
|
||||
auditLogQueryDo auditLogQueryDo
|
||||
|
||||
ALL field.Asterisk
|
||||
ID field.Int64 // 主键ID。
|
||||
TenantID field.Int64 // 租户ID;用途:关联租户审计(0表示平台级)。
|
||||
OperatorID field.Int64 // 操作者用户ID;用途:审计追溯;约束:必须存在。
|
||||
Action field.String // 动作标识;用途:检索分类;约束:例如 review_content/freeze_coupon。
|
||||
TargetID field.String // 目标ID;用途:定位被操作对象;可为空字符串。
|
||||
Detail field.String // 动作详情;用途:记录操作原因与补充说明。
|
||||
CreatedAt field.Time // 创建时间;用途:时间序列查询与审计留存。
|
||||
|
||||
fieldMap map[string]field.Expr
|
||||
}
|
||||
|
||||
func (a auditLogQuery) Table(newTableName string) *auditLogQuery {
|
||||
a.auditLogQueryDo.UseTable(newTableName)
|
||||
return a.updateTableName(newTableName)
|
||||
}
|
||||
|
||||
func (a auditLogQuery) As(alias string) *auditLogQuery {
|
||||
a.auditLogQueryDo.DO = *(a.auditLogQueryDo.As(alias).(*gen.DO))
|
||||
return a.updateTableName(alias)
|
||||
}
|
||||
|
||||
func (a *auditLogQuery) updateTableName(table string) *auditLogQuery {
|
||||
a.ALL = field.NewAsterisk(table)
|
||||
a.ID = field.NewInt64(table, "id")
|
||||
a.TenantID = field.NewInt64(table, "tenant_id")
|
||||
a.OperatorID = field.NewInt64(table, "operator_id")
|
||||
a.Action = field.NewString(table, "action")
|
||||
a.TargetID = field.NewString(table, "target_id")
|
||||
a.Detail = field.NewString(table, "detail")
|
||||
a.CreatedAt = field.NewTime(table, "created_at")
|
||||
|
||||
a.fillFieldMap()
|
||||
|
||||
return a
|
||||
}
|
||||
|
||||
func (a *auditLogQuery) QueryContext(ctx context.Context) (*auditLogQuery, *auditLogQueryDo) {
|
||||
return a, a.auditLogQueryDo.WithContext(ctx)
|
||||
}
|
||||
|
||||
func (a *auditLogQuery) WithContext(ctx context.Context) *auditLogQueryDo {
|
||||
return a.auditLogQueryDo.WithContext(ctx)
|
||||
}
|
||||
|
||||
func (a auditLogQuery) TableName() string { return a.auditLogQueryDo.TableName() }
|
||||
|
||||
func (a auditLogQuery) Alias() string { return a.auditLogQueryDo.Alias() }
|
||||
|
||||
func (a auditLogQuery) Columns(cols ...field.Expr) gen.Columns {
|
||||
return a.auditLogQueryDo.Columns(cols...)
|
||||
}
|
||||
|
||||
func (a *auditLogQuery) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
|
||||
_f, ok := a.fieldMap[fieldName]
|
||||
if !ok || _f == nil {
|
||||
return nil, false
|
||||
}
|
||||
_oe, ok := _f.(field.OrderExpr)
|
||||
return _oe, ok
|
||||
}
|
||||
|
||||
func (a *auditLogQuery) fillFieldMap() {
|
||||
a.fieldMap = make(map[string]field.Expr, 7)
|
||||
a.fieldMap["id"] = a.ID
|
||||
a.fieldMap["tenant_id"] = a.TenantID
|
||||
a.fieldMap["operator_id"] = a.OperatorID
|
||||
a.fieldMap["action"] = a.Action
|
||||
a.fieldMap["target_id"] = a.TargetID
|
||||
a.fieldMap["detail"] = a.Detail
|
||||
a.fieldMap["created_at"] = a.CreatedAt
|
||||
}
|
||||
|
||||
func (a auditLogQuery) clone(db *gorm.DB) auditLogQuery {
|
||||
a.auditLogQueryDo.ReplaceConnPool(db.Statement.ConnPool)
|
||||
return a
|
||||
}
|
||||
|
||||
func (a auditLogQuery) replaceDB(db *gorm.DB) auditLogQuery {
|
||||
a.auditLogQueryDo.ReplaceDB(db)
|
||||
return a
|
||||
}
|
||||
|
||||
type auditLogQueryDo struct{ gen.DO }
|
||||
|
||||
func (a auditLogQueryDo) Debug() *auditLogQueryDo {
|
||||
return a.withDO(a.DO.Debug())
|
||||
}
|
||||
|
||||
func (a auditLogQueryDo) WithContext(ctx context.Context) *auditLogQueryDo {
|
||||
return a.withDO(a.DO.WithContext(ctx))
|
||||
}
|
||||
|
||||
func (a auditLogQueryDo) ReadDB() *auditLogQueryDo {
|
||||
return a.Clauses(dbresolver.Read)
|
||||
}
|
||||
|
||||
func (a auditLogQueryDo) WriteDB() *auditLogQueryDo {
|
||||
return a.Clauses(dbresolver.Write)
|
||||
}
|
||||
|
||||
func (a auditLogQueryDo) Session(config *gorm.Session) *auditLogQueryDo {
|
||||
return a.withDO(a.DO.Session(config))
|
||||
}
|
||||
|
||||
func (a auditLogQueryDo) Clauses(conds ...clause.Expression) *auditLogQueryDo {
|
||||
return a.withDO(a.DO.Clauses(conds...))
|
||||
}
|
||||
|
||||
func (a auditLogQueryDo) Returning(value interface{}, columns ...string) *auditLogQueryDo {
|
||||
return a.withDO(a.DO.Returning(value, columns...))
|
||||
}
|
||||
|
||||
func (a auditLogQueryDo) Not(conds ...gen.Condition) *auditLogQueryDo {
|
||||
return a.withDO(a.DO.Not(conds...))
|
||||
}
|
||||
|
||||
func (a auditLogQueryDo) Or(conds ...gen.Condition) *auditLogQueryDo {
|
||||
return a.withDO(a.DO.Or(conds...))
|
||||
}
|
||||
|
||||
func (a auditLogQueryDo) Select(conds ...field.Expr) *auditLogQueryDo {
|
||||
return a.withDO(a.DO.Select(conds...))
|
||||
}
|
||||
|
||||
func (a auditLogQueryDo) Where(conds ...gen.Condition) *auditLogQueryDo {
|
||||
return a.withDO(a.DO.Where(conds...))
|
||||
}
|
||||
|
||||
func (a auditLogQueryDo) Order(conds ...field.Expr) *auditLogQueryDo {
|
||||
return a.withDO(a.DO.Order(conds...))
|
||||
}
|
||||
|
||||
func (a auditLogQueryDo) Distinct(cols ...field.Expr) *auditLogQueryDo {
|
||||
return a.withDO(a.DO.Distinct(cols...))
|
||||
}
|
||||
|
||||
func (a auditLogQueryDo) Omit(cols ...field.Expr) *auditLogQueryDo {
|
||||
return a.withDO(a.DO.Omit(cols...))
|
||||
}
|
||||
|
||||
func (a auditLogQueryDo) Join(table schema.Tabler, on ...field.Expr) *auditLogQueryDo {
|
||||
return a.withDO(a.DO.Join(table, on...))
|
||||
}
|
||||
|
||||
func (a auditLogQueryDo) LeftJoin(table schema.Tabler, on ...field.Expr) *auditLogQueryDo {
|
||||
return a.withDO(a.DO.LeftJoin(table, on...))
|
||||
}
|
||||
|
||||
func (a auditLogQueryDo) RightJoin(table schema.Tabler, on ...field.Expr) *auditLogQueryDo {
|
||||
return a.withDO(a.DO.RightJoin(table, on...))
|
||||
}
|
||||
|
||||
func (a auditLogQueryDo) Group(cols ...field.Expr) *auditLogQueryDo {
|
||||
return a.withDO(a.DO.Group(cols...))
|
||||
}
|
||||
|
||||
func (a auditLogQueryDo) Having(conds ...gen.Condition) *auditLogQueryDo {
|
||||
return a.withDO(a.DO.Having(conds...))
|
||||
}
|
||||
|
||||
func (a auditLogQueryDo) Limit(limit int) *auditLogQueryDo {
|
||||
return a.withDO(a.DO.Limit(limit))
|
||||
}
|
||||
|
||||
func (a auditLogQueryDo) Offset(offset int) *auditLogQueryDo {
|
||||
return a.withDO(a.DO.Offset(offset))
|
||||
}
|
||||
|
||||
func (a auditLogQueryDo) Scopes(funcs ...func(gen.Dao) gen.Dao) *auditLogQueryDo {
|
||||
return a.withDO(a.DO.Scopes(funcs...))
|
||||
}
|
||||
|
||||
func (a auditLogQueryDo) Unscoped() *auditLogQueryDo {
|
||||
return a.withDO(a.DO.Unscoped())
|
||||
}
|
||||
|
||||
func (a auditLogQueryDo) Create(values ...*AuditLog) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return a.DO.Create(values)
|
||||
}
|
||||
|
||||
func (a auditLogQueryDo) CreateInBatches(values []*AuditLog, batchSize int) error {
|
||||
return a.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 (a auditLogQueryDo) Save(values ...*AuditLog) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return a.DO.Save(values)
|
||||
}
|
||||
|
||||
func (a auditLogQueryDo) First() (*AuditLog, error) {
|
||||
if result, err := a.DO.First(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*AuditLog), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (a auditLogQueryDo) Take() (*AuditLog, error) {
|
||||
if result, err := a.DO.Take(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*AuditLog), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (a auditLogQueryDo) Last() (*AuditLog, error) {
|
||||
if result, err := a.DO.Last(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*AuditLog), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (a auditLogQueryDo) Find() ([]*AuditLog, error) {
|
||||
result, err := a.DO.Find()
|
||||
return result.([]*AuditLog), err
|
||||
}
|
||||
|
||||
func (a auditLogQueryDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*AuditLog, err error) {
|
||||
buf := make([]*AuditLog, 0, batchSize)
|
||||
err = a.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 (a auditLogQueryDo) FindInBatches(result *[]*AuditLog, batchSize int, fc func(tx gen.Dao, batch int) error) error {
|
||||
return a.DO.FindInBatches(result, batchSize, fc)
|
||||
}
|
||||
|
||||
func (a auditLogQueryDo) Attrs(attrs ...field.AssignExpr) *auditLogQueryDo {
|
||||
return a.withDO(a.DO.Attrs(attrs...))
|
||||
}
|
||||
|
||||
func (a auditLogQueryDo) Assign(attrs ...field.AssignExpr) *auditLogQueryDo {
|
||||
return a.withDO(a.DO.Assign(attrs...))
|
||||
}
|
||||
|
||||
func (a auditLogQueryDo) Joins(fields ...field.RelationField) *auditLogQueryDo {
|
||||
for _, _f := range fields {
|
||||
a = *a.withDO(a.DO.Joins(_f))
|
||||
}
|
||||
return &a
|
||||
}
|
||||
|
||||
func (a auditLogQueryDo) Preload(fields ...field.RelationField) *auditLogQueryDo {
|
||||
for _, _f := range fields {
|
||||
a = *a.withDO(a.DO.Preload(_f))
|
||||
}
|
||||
return &a
|
||||
}
|
||||
|
||||
func (a auditLogQueryDo) FirstOrInit() (*AuditLog, error) {
|
||||
if result, err := a.DO.FirstOrInit(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*AuditLog), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (a auditLogQueryDo) FirstOrCreate() (*AuditLog, error) {
|
||||
if result, err := a.DO.FirstOrCreate(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*AuditLog), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (a auditLogQueryDo) FindByPage(offset int, limit int) (result []*AuditLog, count int64, err error) {
|
||||
result, err = a.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 = a.Offset(-1).Limit(-1).Count()
|
||||
return
|
||||
}
|
||||
|
||||
func (a auditLogQueryDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) {
|
||||
count, err = a.Count()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = a.Offset(offset).Limit(limit).Scan(result)
|
||||
return
|
||||
}
|
||||
|
||||
func (a auditLogQueryDo) Scan(result interface{}) (err error) {
|
||||
return a.DO.Scan(result)
|
||||
}
|
||||
|
||||
func (a auditLogQueryDo) Delete(models ...*AuditLog) (result gen.ResultInfo, err error) {
|
||||
return a.DO.Delete(models)
|
||||
}
|
||||
|
||||
// ForceDelete performs a permanent delete (ignores soft-delete) for current scope.
|
||||
func (a auditLogQueryDo) ForceDelete() (gen.ResultInfo, error) {
|
||||
return a.Unscoped().Delete()
|
||||
}
|
||||
|
||||
// Inc increases the given column by step for current scope.
|
||||
func (a auditLogQueryDo) Inc(column field.Expr, step int64) (gen.ResultInfo, error) {
|
||||
// column = column + step
|
||||
e := field.NewUnsafeFieldRaw("?+?", column.RawExpr(), step)
|
||||
return a.DO.UpdateColumn(column, e)
|
||||
}
|
||||
|
||||
// Dec decreases the given column by step for current scope.
|
||||
func (a auditLogQueryDo) Dec(column field.Expr, step int64) (gen.ResultInfo, error) {
|
||||
// column = column - step
|
||||
e := field.NewUnsafeFieldRaw("?-?", column.RawExpr(), step)
|
||||
return a.DO.UpdateColumn(column, e)
|
||||
}
|
||||
|
||||
// Sum returns SUM(column) for current scope.
|
||||
func (a auditLogQueryDo) Sum(column field.Expr) (float64, error) {
|
||||
var _v float64
|
||||
agg := field.NewUnsafeFieldRaw("SUM(?)", column.RawExpr())
|
||||
if err := a.Select(agg).Scan(&_v); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return _v, nil
|
||||
}
|
||||
|
||||
// Avg returns AVG(column) for current scope.
|
||||
func (a auditLogQueryDo) Avg(column field.Expr) (float64, error) {
|
||||
var _v float64
|
||||
agg := field.NewUnsafeFieldRaw("AVG(?)", column.RawExpr())
|
||||
if err := a.Select(agg).Scan(&_v); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return _v, nil
|
||||
}
|
||||
|
||||
// Min returns MIN(column) for current scope.
|
||||
func (a auditLogQueryDo) Min(column field.Expr) (float64, error) {
|
||||
var _v float64
|
||||
agg := field.NewUnsafeFieldRaw("MIN(?)", column.RawExpr())
|
||||
if err := a.Select(agg).Scan(&_v); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return _v, nil
|
||||
}
|
||||
|
||||
// Max returns MAX(column) for current scope.
|
||||
func (a auditLogQueryDo) Max(column field.Expr) (float64, error) {
|
||||
var _v float64
|
||||
agg := field.NewUnsafeFieldRaw("MAX(?)", column.RawExpr())
|
||||
if err := a.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 (a auditLogQueryDo) PluckMap(key, val field.Expr) (map[interface{}]interface{}, error) {
|
||||
do := a.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 (a auditLogQueryDo) Exists(conds ...gen.Condition) (bool, error) {
|
||||
cnt, err := a.Where(conds...).Count()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
return cnt > 0, nil
|
||||
}
|
||||
|
||||
// PluckIDs returns all primary key values under current scope.
|
||||
func (a auditLogQueryDo) PluckIDs() ([]int64, error) {
|
||||
ids := make([]int64, 0, 16)
|
||||
pk := field.NewInt64(a.TableName(), "id")
|
||||
if err := a.DO.Pluck(pk, &ids); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return ids, nil
|
||||
}
|
||||
|
||||
// GetByID finds a single record by primary key.
|
||||
func (a auditLogQueryDo) GetByID(id int64) (*AuditLog, error) {
|
||||
pk := field.NewInt64(a.TableName(), "id")
|
||||
return a.Where(pk.Eq(id)).First()
|
||||
}
|
||||
|
||||
// GetByIDs finds records by primary key list.
|
||||
func (a auditLogQueryDo) GetByIDs(ids ...int64) ([]*AuditLog, error) {
|
||||
if len(ids) == 0 {
|
||||
return []*AuditLog{}, nil
|
||||
}
|
||||
pk := field.NewInt64(a.TableName(), "id")
|
||||
return a.Where(pk.In(ids...)).Find()
|
||||
}
|
||||
|
||||
// DeleteByID deletes records by primary key.
|
||||
func (a auditLogQueryDo) DeleteByID(id int64) (gen.ResultInfo, error) {
|
||||
pk := field.NewInt64(a.TableName(), "id")
|
||||
return a.Where(pk.Eq(id)).Delete()
|
||||
}
|
||||
|
||||
// DeleteByIDs deletes records by a list of primary keys.
|
||||
func (a auditLogQueryDo) DeleteByIDs(ids ...int64) (gen.ResultInfo, error) {
|
||||
if len(ids) == 0 {
|
||||
return gen.ResultInfo{RowsAffected: 0, Error: nil}, nil
|
||||
}
|
||||
pk := field.NewInt64(a.TableName(), "id")
|
||||
return a.Where(pk.In(ids...)).Delete()
|
||||
}
|
||||
|
||||
func (a *auditLogQueryDo) withDO(do gen.Dao) *auditLogQueryDo {
|
||||
a.DO = *do.(*gen.DO)
|
||||
return a
|
||||
}
|
||||
@@ -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,12 +46,6 @@ 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{}),
|
||||
|
||||
@@ -64,6 +58,12 @@ 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
|
||||
Author contentQueryBelongsToAuthor
|
||||
|
||||
ContentAssets contentQueryHasManyContentAssets
|
||||
ContentAssets contentQueryHasManyContentAssets
|
||||
|
||||
Comments contentQueryHasManyComments
|
||||
|
||||
Author contentQueryBelongsToAuthor
|
||||
|
||||
fieldMap map[string]field.Expr
|
||||
}
|
||||
|
||||
@@ -195,104 +195,23 @@ 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
|
||||
|
||||
@@ -455,6 +374,87 @@ 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 {
|
||||
|
||||
@@ -17,6 +17,7 @@ import (
|
||||
|
||||
var (
|
||||
Q = new(Query)
|
||||
AuditLogQuery *auditLogQuery
|
||||
CommentQuery *commentQuery
|
||||
ContentQuery *contentQuery
|
||||
ContentAccessQuery *contentAccessQuery
|
||||
@@ -29,6 +30,7 @@ var (
|
||||
OrderQuery *orderQuery
|
||||
OrderItemQuery *orderItemQuery
|
||||
PayoutAccountQuery *payoutAccountQuery
|
||||
SystemConfigQuery *systemConfigQuery
|
||||
TenantQuery *tenantQuery
|
||||
TenantInviteQuery *tenantInviteQuery
|
||||
TenantJoinRequestQuery *tenantJoinRequestQuery
|
||||
@@ -42,6 +44,7 @@ var (
|
||||
|
||||
func SetDefault(db *gorm.DB, opts ...gen.DOOption) {
|
||||
*Q = *Use(db, opts...)
|
||||
AuditLogQuery = &Q.AuditLog
|
||||
CommentQuery = &Q.Comment
|
||||
ContentQuery = &Q.Content
|
||||
ContentAccessQuery = &Q.ContentAccess
|
||||
@@ -54,6 +57,7 @@ func SetDefault(db *gorm.DB, opts ...gen.DOOption) {
|
||||
OrderQuery = &Q.Order
|
||||
OrderItemQuery = &Q.OrderItem
|
||||
PayoutAccountQuery = &Q.PayoutAccount
|
||||
SystemConfigQuery = &Q.SystemConfig
|
||||
TenantQuery = &Q.Tenant
|
||||
TenantInviteQuery = &Q.TenantInvite
|
||||
TenantJoinRequestQuery = &Q.TenantJoinRequest
|
||||
@@ -68,6 +72,7 @@ func SetDefault(db *gorm.DB, opts ...gen.DOOption) {
|
||||
func Use(db *gorm.DB, opts ...gen.DOOption) *Query {
|
||||
return &Query{
|
||||
db: db,
|
||||
AuditLog: newAuditLog(db, opts...),
|
||||
Comment: newComment(db, opts...),
|
||||
Content: newContent(db, opts...),
|
||||
ContentAccess: newContentAccess(db, opts...),
|
||||
@@ -80,6 +85,7 @@ func Use(db *gorm.DB, opts ...gen.DOOption) *Query {
|
||||
Order: newOrder(db, opts...),
|
||||
OrderItem: newOrderItem(db, opts...),
|
||||
PayoutAccount: newPayoutAccount(db, opts...),
|
||||
SystemConfig: newSystemConfig(db, opts...),
|
||||
Tenant: newTenant(db, opts...),
|
||||
TenantInvite: newTenantInvite(db, opts...),
|
||||
TenantJoinRequest: newTenantJoinRequest(db, opts...),
|
||||
@@ -95,6 +101,7 @@ func Use(db *gorm.DB, opts ...gen.DOOption) *Query {
|
||||
type Query struct {
|
||||
db *gorm.DB
|
||||
|
||||
AuditLog auditLogQuery
|
||||
Comment commentQuery
|
||||
Content contentQuery
|
||||
ContentAccess contentAccessQuery
|
||||
@@ -107,6 +114,7 @@ type Query struct {
|
||||
Order orderQuery
|
||||
OrderItem orderItemQuery
|
||||
PayoutAccount payoutAccountQuery
|
||||
SystemConfig systemConfigQuery
|
||||
Tenant tenantQuery
|
||||
TenantInvite tenantInviteQuery
|
||||
TenantJoinRequest tenantJoinRequestQuery
|
||||
@@ -123,6 +131,7 @@ func (q *Query) Available() bool { return q.db != nil }
|
||||
func (q *Query) clone(db *gorm.DB) *Query {
|
||||
return &Query{
|
||||
db: db,
|
||||
AuditLog: q.AuditLog.clone(db),
|
||||
Comment: q.Comment.clone(db),
|
||||
Content: q.Content.clone(db),
|
||||
ContentAccess: q.ContentAccess.clone(db),
|
||||
@@ -135,6 +144,7 @@ func (q *Query) clone(db *gorm.DB) *Query {
|
||||
Order: q.Order.clone(db),
|
||||
OrderItem: q.OrderItem.clone(db),
|
||||
PayoutAccount: q.PayoutAccount.clone(db),
|
||||
SystemConfig: q.SystemConfig.clone(db),
|
||||
Tenant: q.Tenant.clone(db),
|
||||
TenantInvite: q.TenantInvite.clone(db),
|
||||
TenantJoinRequest: q.TenantJoinRequest.clone(db),
|
||||
@@ -158,6 +168,7 @@ func (q *Query) WriteDB() *Query {
|
||||
func (q *Query) ReplaceDB(db *gorm.DB) *Query {
|
||||
return &Query{
|
||||
db: db,
|
||||
AuditLog: q.AuditLog.replaceDB(db),
|
||||
Comment: q.Comment.replaceDB(db),
|
||||
Content: q.Content.replaceDB(db),
|
||||
ContentAccess: q.ContentAccess.replaceDB(db),
|
||||
@@ -170,6 +181,7 @@ func (q *Query) ReplaceDB(db *gorm.DB) *Query {
|
||||
Order: q.Order.replaceDB(db),
|
||||
OrderItem: q.OrderItem.replaceDB(db),
|
||||
PayoutAccount: q.PayoutAccount.replaceDB(db),
|
||||
SystemConfig: q.SystemConfig.replaceDB(db),
|
||||
Tenant: q.Tenant.replaceDB(db),
|
||||
TenantInvite: q.TenantInvite.replaceDB(db),
|
||||
TenantJoinRequest: q.TenantJoinRequest.replaceDB(db),
|
||||
@@ -183,6 +195,7 @@ func (q *Query) ReplaceDB(db *gorm.DB) *Query {
|
||||
}
|
||||
|
||||
type queryCtx struct {
|
||||
AuditLog *auditLogQueryDo
|
||||
Comment *commentQueryDo
|
||||
Content *contentQueryDo
|
||||
ContentAccess *contentAccessQueryDo
|
||||
@@ -195,6 +208,7 @@ type queryCtx struct {
|
||||
Order *orderQueryDo
|
||||
OrderItem *orderItemQueryDo
|
||||
PayoutAccount *payoutAccountQueryDo
|
||||
SystemConfig *systemConfigQueryDo
|
||||
Tenant *tenantQueryDo
|
||||
TenantInvite *tenantInviteQueryDo
|
||||
TenantJoinRequest *tenantJoinRequestQueryDo
|
||||
@@ -208,6 +222,7 @@ type queryCtx struct {
|
||||
|
||||
func (q *Query) WithContext(ctx context.Context) *queryCtx {
|
||||
return &queryCtx{
|
||||
AuditLog: q.AuditLog.WithContext(ctx),
|
||||
Comment: q.Comment.WithContext(ctx),
|
||||
Content: q.Content.WithContext(ctx),
|
||||
ContentAccess: q.ContentAccess.WithContext(ctx),
|
||||
@@ -220,6 +235,7 @@ func (q *Query) WithContext(ctx context.Context) *queryCtx {
|
||||
Order: q.Order.WithContext(ctx),
|
||||
OrderItem: q.OrderItem.WithContext(ctx),
|
||||
PayoutAccount: q.PayoutAccount.WithContext(ctx),
|
||||
SystemConfig: q.SystemConfig.WithContext(ctx),
|
||||
Tenant: q.Tenant.WithContext(ctx),
|
||||
TenantInvite: q.TenantInvite.WithContext(ctx),
|
||||
TenantJoinRequest: q.TenantJoinRequest.WithContext(ctx),
|
||||
|
||||
61
backend/database/models/system_configs.gen.go
Normal file
61
backend/database/models/system_configs.gen.go
Normal file
@@ -0,0 +1,61 @@
|
||||
// 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"
|
||||
"go.ipao.vip/gen/types"
|
||||
)
|
||||
|
||||
const TableNameSystemConfig = "system_configs"
|
||||
|
||||
// SystemConfig mapped from table <system_configs>
|
||||
type SystemConfig struct {
|
||||
ID int64 `gorm:"column:id;type:bigint;primaryKey;autoIncrement:true;comment:主键ID。" json:"id"` // 主键ID。
|
||||
ConfigKey string `gorm:"column:config_key;type:character varying(64);not null;comment:配置项Key;用途:按Key读取/更新;约束:唯一。" json:"config_key"` // 配置项Key;用途:按Key读取/更新;约束:唯一。
|
||||
Value types.JSON `gorm:"column:value;type:jsonb;not null;default:{};comment:配置值(JSON);用途:存储任意结构化配置;默认 {}。" json:"value"` // 配置值(JSON);用途:存储任意结构化配置;默认 {}。
|
||||
Description string `gorm:"column:description;type:character varying(255);not null;comment:配置说明;用途:给运营/技术理解用途。" json:"description"` // 配置说明;用途:给运营/技术理解用途。
|
||||
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 *SystemConfig) Update(ctx context.Context) (gen.ResultInfo, error) {
|
||||
return Q.SystemConfig.WithContext(ctx).Updates(m)
|
||||
}
|
||||
|
||||
// Save upserts the model using the default DB.
|
||||
func (m *SystemConfig) Save(ctx context.Context) error {
|
||||
return Q.SystemConfig.WithContext(ctx).Save(m)
|
||||
}
|
||||
|
||||
// Create inserts the model using the default DB.
|
||||
func (m *SystemConfig) Create(ctx context.Context) error {
|
||||
return Q.SystemConfig.WithContext(ctx).Create(m)
|
||||
}
|
||||
|
||||
// Delete removes the row represented by the model using the default DB.
|
||||
func (m *SystemConfig) Delete(ctx context.Context) (gen.ResultInfo, error) {
|
||||
return Q.SystemConfig.WithContext(ctx).Delete(m)
|
||||
}
|
||||
|
||||
// ForceDelete permanently deletes the row (ignores soft delete) using the default DB.
|
||||
func (m *SystemConfig) ForceDelete(ctx context.Context) (gen.ResultInfo, error) {
|
||||
return Q.SystemConfig.WithContext(ctx).Unscoped().Delete(m)
|
||||
}
|
||||
|
||||
// Reload reloads the model from database by its primary key and overwrites current fields.
|
||||
func (m *SystemConfig) Reload(ctx context.Context) error {
|
||||
fresh, err := Q.SystemConfig.WithContext(ctx).GetByID(m.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
*m = *fresh
|
||||
return nil
|
||||
}
|
||||
481
backend/database/models/system_configs.query.gen.go
Normal file
481
backend/database/models/system_configs.query.gen.go
Normal file
@@ -0,0 +1,481 @@
|
||||
// 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 newSystemConfig(db *gorm.DB, opts ...gen.DOOption) systemConfigQuery {
|
||||
_systemConfigQuery := systemConfigQuery{}
|
||||
|
||||
_systemConfigQuery.systemConfigQueryDo.UseDB(db, opts...)
|
||||
_systemConfigQuery.systemConfigQueryDo.UseModel(&SystemConfig{})
|
||||
|
||||
tableName := _systemConfigQuery.systemConfigQueryDo.TableName()
|
||||
_systemConfigQuery.ALL = field.NewAsterisk(tableName)
|
||||
_systemConfigQuery.ID = field.NewInt64(tableName, "id")
|
||||
_systemConfigQuery.ConfigKey = field.NewString(tableName, "config_key")
|
||||
_systemConfigQuery.Value = field.NewJSONB(tableName, "value")
|
||||
_systemConfigQuery.Description = field.NewString(tableName, "description")
|
||||
_systemConfigQuery.CreatedAt = field.NewTime(tableName, "created_at")
|
||||
_systemConfigQuery.UpdatedAt = field.NewTime(tableName, "updated_at")
|
||||
|
||||
_systemConfigQuery.fillFieldMap()
|
||||
|
||||
return _systemConfigQuery
|
||||
}
|
||||
|
||||
type systemConfigQuery struct {
|
||||
systemConfigQueryDo systemConfigQueryDo
|
||||
|
||||
ALL field.Asterisk
|
||||
ID field.Int64 // 主键ID。
|
||||
ConfigKey field.String // 配置项Key;用途:按Key读取/更新;约束:唯一。
|
||||
Value field.JSONB // 配置值(JSON);用途:存储任意结构化配置;默认 {}。
|
||||
Description field.String // 配置说明;用途:给运营/技术理解用途。
|
||||
CreatedAt field.Time // 创建时间;用途:审计与追溯。
|
||||
UpdatedAt field.Time // 更新时间;用途:变更记录。
|
||||
|
||||
fieldMap map[string]field.Expr
|
||||
}
|
||||
|
||||
func (s systemConfigQuery) Table(newTableName string) *systemConfigQuery {
|
||||
s.systemConfigQueryDo.UseTable(newTableName)
|
||||
return s.updateTableName(newTableName)
|
||||
}
|
||||
|
||||
func (s systemConfigQuery) As(alias string) *systemConfigQuery {
|
||||
s.systemConfigQueryDo.DO = *(s.systemConfigQueryDo.As(alias).(*gen.DO))
|
||||
return s.updateTableName(alias)
|
||||
}
|
||||
|
||||
func (s *systemConfigQuery) updateTableName(table string) *systemConfigQuery {
|
||||
s.ALL = field.NewAsterisk(table)
|
||||
s.ID = field.NewInt64(table, "id")
|
||||
s.ConfigKey = field.NewString(table, "config_key")
|
||||
s.Value = field.NewJSONB(table, "value")
|
||||
s.Description = field.NewString(table, "description")
|
||||
s.CreatedAt = field.NewTime(table, "created_at")
|
||||
s.UpdatedAt = field.NewTime(table, "updated_at")
|
||||
|
||||
s.fillFieldMap()
|
||||
|
||||
return s
|
||||
}
|
||||
|
||||
func (s *systemConfigQuery) QueryContext(ctx context.Context) (*systemConfigQuery, *systemConfigQueryDo) {
|
||||
return s, s.systemConfigQueryDo.WithContext(ctx)
|
||||
}
|
||||
|
||||
func (s *systemConfigQuery) WithContext(ctx context.Context) *systemConfigQueryDo {
|
||||
return s.systemConfigQueryDo.WithContext(ctx)
|
||||
}
|
||||
|
||||
func (s systemConfigQuery) TableName() string { return s.systemConfigQueryDo.TableName() }
|
||||
|
||||
func (s systemConfigQuery) Alias() string { return s.systemConfigQueryDo.Alias() }
|
||||
|
||||
func (s systemConfigQuery) Columns(cols ...field.Expr) gen.Columns {
|
||||
return s.systemConfigQueryDo.Columns(cols...)
|
||||
}
|
||||
|
||||
func (s *systemConfigQuery) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
|
||||
_f, ok := s.fieldMap[fieldName]
|
||||
if !ok || _f == nil {
|
||||
return nil, false
|
||||
}
|
||||
_oe, ok := _f.(field.OrderExpr)
|
||||
return _oe, ok
|
||||
}
|
||||
|
||||
func (s *systemConfigQuery) fillFieldMap() {
|
||||
s.fieldMap = make(map[string]field.Expr, 6)
|
||||
s.fieldMap["id"] = s.ID
|
||||
s.fieldMap["config_key"] = s.ConfigKey
|
||||
s.fieldMap["value"] = s.Value
|
||||
s.fieldMap["description"] = s.Description
|
||||
s.fieldMap["created_at"] = s.CreatedAt
|
||||
s.fieldMap["updated_at"] = s.UpdatedAt
|
||||
}
|
||||
|
||||
func (s systemConfigQuery) clone(db *gorm.DB) systemConfigQuery {
|
||||
s.systemConfigQueryDo.ReplaceConnPool(db.Statement.ConnPool)
|
||||
return s
|
||||
}
|
||||
|
||||
func (s systemConfigQuery) replaceDB(db *gorm.DB) systemConfigQuery {
|
||||
s.systemConfigQueryDo.ReplaceDB(db)
|
||||
return s
|
||||
}
|
||||
|
||||
type systemConfigQueryDo struct{ gen.DO }
|
||||
|
||||
func (s systemConfigQueryDo) Debug() *systemConfigQueryDo {
|
||||
return s.withDO(s.DO.Debug())
|
||||
}
|
||||
|
||||
func (s systemConfigQueryDo) WithContext(ctx context.Context) *systemConfigQueryDo {
|
||||
return s.withDO(s.DO.WithContext(ctx))
|
||||
}
|
||||
|
||||
func (s systemConfigQueryDo) ReadDB() *systemConfigQueryDo {
|
||||
return s.Clauses(dbresolver.Read)
|
||||
}
|
||||
|
||||
func (s systemConfigQueryDo) WriteDB() *systemConfigQueryDo {
|
||||
return s.Clauses(dbresolver.Write)
|
||||
}
|
||||
|
||||
func (s systemConfigQueryDo) Session(config *gorm.Session) *systemConfigQueryDo {
|
||||
return s.withDO(s.DO.Session(config))
|
||||
}
|
||||
|
||||
func (s systemConfigQueryDo) Clauses(conds ...clause.Expression) *systemConfigQueryDo {
|
||||
return s.withDO(s.DO.Clauses(conds...))
|
||||
}
|
||||
|
||||
func (s systemConfigQueryDo) Returning(value interface{}, columns ...string) *systemConfigQueryDo {
|
||||
return s.withDO(s.DO.Returning(value, columns...))
|
||||
}
|
||||
|
||||
func (s systemConfigQueryDo) Not(conds ...gen.Condition) *systemConfigQueryDo {
|
||||
return s.withDO(s.DO.Not(conds...))
|
||||
}
|
||||
|
||||
func (s systemConfigQueryDo) Or(conds ...gen.Condition) *systemConfigQueryDo {
|
||||
return s.withDO(s.DO.Or(conds...))
|
||||
}
|
||||
|
||||
func (s systemConfigQueryDo) Select(conds ...field.Expr) *systemConfigQueryDo {
|
||||
return s.withDO(s.DO.Select(conds...))
|
||||
}
|
||||
|
||||
func (s systemConfigQueryDo) Where(conds ...gen.Condition) *systemConfigQueryDo {
|
||||
return s.withDO(s.DO.Where(conds...))
|
||||
}
|
||||
|
||||
func (s systemConfigQueryDo) Order(conds ...field.Expr) *systemConfigQueryDo {
|
||||
return s.withDO(s.DO.Order(conds...))
|
||||
}
|
||||
|
||||
func (s systemConfigQueryDo) Distinct(cols ...field.Expr) *systemConfigQueryDo {
|
||||
return s.withDO(s.DO.Distinct(cols...))
|
||||
}
|
||||
|
||||
func (s systemConfigQueryDo) Omit(cols ...field.Expr) *systemConfigQueryDo {
|
||||
return s.withDO(s.DO.Omit(cols...))
|
||||
}
|
||||
|
||||
func (s systemConfigQueryDo) Join(table schema.Tabler, on ...field.Expr) *systemConfigQueryDo {
|
||||
return s.withDO(s.DO.Join(table, on...))
|
||||
}
|
||||
|
||||
func (s systemConfigQueryDo) LeftJoin(table schema.Tabler, on ...field.Expr) *systemConfigQueryDo {
|
||||
return s.withDO(s.DO.LeftJoin(table, on...))
|
||||
}
|
||||
|
||||
func (s systemConfigQueryDo) RightJoin(table schema.Tabler, on ...field.Expr) *systemConfigQueryDo {
|
||||
return s.withDO(s.DO.RightJoin(table, on...))
|
||||
}
|
||||
|
||||
func (s systemConfigQueryDo) Group(cols ...field.Expr) *systemConfigQueryDo {
|
||||
return s.withDO(s.DO.Group(cols...))
|
||||
}
|
||||
|
||||
func (s systemConfigQueryDo) Having(conds ...gen.Condition) *systemConfigQueryDo {
|
||||
return s.withDO(s.DO.Having(conds...))
|
||||
}
|
||||
|
||||
func (s systemConfigQueryDo) Limit(limit int) *systemConfigQueryDo {
|
||||
return s.withDO(s.DO.Limit(limit))
|
||||
}
|
||||
|
||||
func (s systemConfigQueryDo) Offset(offset int) *systemConfigQueryDo {
|
||||
return s.withDO(s.DO.Offset(offset))
|
||||
}
|
||||
|
||||
func (s systemConfigQueryDo) Scopes(funcs ...func(gen.Dao) gen.Dao) *systemConfigQueryDo {
|
||||
return s.withDO(s.DO.Scopes(funcs...))
|
||||
}
|
||||
|
||||
func (s systemConfigQueryDo) Unscoped() *systemConfigQueryDo {
|
||||
return s.withDO(s.DO.Unscoped())
|
||||
}
|
||||
|
||||
func (s systemConfigQueryDo) Create(values ...*SystemConfig) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return s.DO.Create(values)
|
||||
}
|
||||
|
||||
func (s systemConfigQueryDo) CreateInBatches(values []*SystemConfig, batchSize int) error {
|
||||
return s.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 (s systemConfigQueryDo) Save(values ...*SystemConfig) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return s.DO.Save(values)
|
||||
}
|
||||
|
||||
func (s systemConfigQueryDo) First() (*SystemConfig, error) {
|
||||
if result, err := s.DO.First(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*SystemConfig), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (s systemConfigQueryDo) Take() (*SystemConfig, error) {
|
||||
if result, err := s.DO.Take(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*SystemConfig), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (s systemConfigQueryDo) Last() (*SystemConfig, error) {
|
||||
if result, err := s.DO.Last(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*SystemConfig), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (s systemConfigQueryDo) Find() ([]*SystemConfig, error) {
|
||||
result, err := s.DO.Find()
|
||||
return result.([]*SystemConfig), err
|
||||
}
|
||||
|
||||
func (s systemConfigQueryDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*SystemConfig, err error) {
|
||||
buf := make([]*SystemConfig, 0, batchSize)
|
||||
err = s.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 (s systemConfigQueryDo) FindInBatches(result *[]*SystemConfig, batchSize int, fc func(tx gen.Dao, batch int) error) error {
|
||||
return s.DO.FindInBatches(result, batchSize, fc)
|
||||
}
|
||||
|
||||
func (s systemConfigQueryDo) Attrs(attrs ...field.AssignExpr) *systemConfigQueryDo {
|
||||
return s.withDO(s.DO.Attrs(attrs...))
|
||||
}
|
||||
|
||||
func (s systemConfigQueryDo) Assign(attrs ...field.AssignExpr) *systemConfigQueryDo {
|
||||
return s.withDO(s.DO.Assign(attrs...))
|
||||
}
|
||||
|
||||
func (s systemConfigQueryDo) Joins(fields ...field.RelationField) *systemConfigQueryDo {
|
||||
for _, _f := range fields {
|
||||
s = *s.withDO(s.DO.Joins(_f))
|
||||
}
|
||||
return &s
|
||||
}
|
||||
|
||||
func (s systemConfigQueryDo) Preload(fields ...field.RelationField) *systemConfigQueryDo {
|
||||
for _, _f := range fields {
|
||||
s = *s.withDO(s.DO.Preload(_f))
|
||||
}
|
||||
return &s
|
||||
}
|
||||
|
||||
func (s systemConfigQueryDo) FirstOrInit() (*SystemConfig, error) {
|
||||
if result, err := s.DO.FirstOrInit(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*SystemConfig), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (s systemConfigQueryDo) FirstOrCreate() (*SystemConfig, error) {
|
||||
if result, err := s.DO.FirstOrCreate(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*SystemConfig), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (s systemConfigQueryDo) FindByPage(offset int, limit int) (result []*SystemConfig, count int64, err error) {
|
||||
result, err = s.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 = s.Offset(-1).Limit(-1).Count()
|
||||
return
|
||||
}
|
||||
|
||||
func (s systemConfigQueryDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) {
|
||||
count, err = s.Count()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = s.Offset(offset).Limit(limit).Scan(result)
|
||||
return
|
||||
}
|
||||
|
||||
func (s systemConfigQueryDo) Scan(result interface{}) (err error) {
|
||||
return s.DO.Scan(result)
|
||||
}
|
||||
|
||||
func (s systemConfigQueryDo) Delete(models ...*SystemConfig) (result gen.ResultInfo, err error) {
|
||||
return s.DO.Delete(models)
|
||||
}
|
||||
|
||||
// ForceDelete performs a permanent delete (ignores soft-delete) for current scope.
|
||||
func (s systemConfigQueryDo) ForceDelete() (gen.ResultInfo, error) {
|
||||
return s.Unscoped().Delete()
|
||||
}
|
||||
|
||||
// Inc increases the given column by step for current scope.
|
||||
func (s systemConfigQueryDo) Inc(column field.Expr, step int64) (gen.ResultInfo, error) {
|
||||
// column = column + step
|
||||
e := field.NewUnsafeFieldRaw("?+?", column.RawExpr(), step)
|
||||
return s.DO.UpdateColumn(column, e)
|
||||
}
|
||||
|
||||
// Dec decreases the given column by step for current scope.
|
||||
func (s systemConfigQueryDo) Dec(column field.Expr, step int64) (gen.ResultInfo, error) {
|
||||
// column = column - step
|
||||
e := field.NewUnsafeFieldRaw("?-?", column.RawExpr(), step)
|
||||
return s.DO.UpdateColumn(column, e)
|
||||
}
|
||||
|
||||
// Sum returns SUM(column) for current scope.
|
||||
func (s systemConfigQueryDo) Sum(column field.Expr) (float64, error) {
|
||||
var _v float64
|
||||
agg := field.NewUnsafeFieldRaw("SUM(?)", column.RawExpr())
|
||||
if err := s.Select(agg).Scan(&_v); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return _v, nil
|
||||
}
|
||||
|
||||
// Avg returns AVG(column) for current scope.
|
||||
func (s systemConfigQueryDo) Avg(column field.Expr) (float64, error) {
|
||||
var _v float64
|
||||
agg := field.NewUnsafeFieldRaw("AVG(?)", column.RawExpr())
|
||||
if err := s.Select(agg).Scan(&_v); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return _v, nil
|
||||
}
|
||||
|
||||
// Min returns MIN(column) for current scope.
|
||||
func (s systemConfigQueryDo) Min(column field.Expr) (float64, error) {
|
||||
var _v float64
|
||||
agg := field.NewUnsafeFieldRaw("MIN(?)", column.RawExpr())
|
||||
if err := s.Select(agg).Scan(&_v); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return _v, nil
|
||||
}
|
||||
|
||||
// Max returns MAX(column) for current scope.
|
||||
func (s systemConfigQueryDo) Max(column field.Expr) (float64, error) {
|
||||
var _v float64
|
||||
agg := field.NewUnsafeFieldRaw("MAX(?)", column.RawExpr())
|
||||
if err := s.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 (s systemConfigQueryDo) PluckMap(key, val field.Expr) (map[interface{}]interface{}, error) {
|
||||
do := s.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 (s systemConfigQueryDo) Exists(conds ...gen.Condition) (bool, error) {
|
||||
cnt, err := s.Where(conds...).Count()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
return cnt > 0, nil
|
||||
}
|
||||
|
||||
// PluckIDs returns all primary key values under current scope.
|
||||
func (s systemConfigQueryDo) PluckIDs() ([]int64, error) {
|
||||
ids := make([]int64, 0, 16)
|
||||
pk := field.NewInt64(s.TableName(), "id")
|
||||
if err := s.DO.Pluck(pk, &ids); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return ids, nil
|
||||
}
|
||||
|
||||
// GetByID finds a single record by primary key.
|
||||
func (s systemConfigQueryDo) GetByID(id int64) (*SystemConfig, error) {
|
||||
pk := field.NewInt64(s.TableName(), "id")
|
||||
return s.Where(pk.Eq(id)).First()
|
||||
}
|
||||
|
||||
// GetByIDs finds records by primary key list.
|
||||
func (s systemConfigQueryDo) GetByIDs(ids ...int64) ([]*SystemConfig, error) {
|
||||
if len(ids) == 0 {
|
||||
return []*SystemConfig{}, nil
|
||||
}
|
||||
pk := field.NewInt64(s.TableName(), "id")
|
||||
return s.Where(pk.In(ids...)).Find()
|
||||
}
|
||||
|
||||
// DeleteByID deletes records by primary key.
|
||||
func (s systemConfigQueryDo) DeleteByID(id int64) (gen.ResultInfo, error) {
|
||||
pk := field.NewInt64(s.TableName(), "id")
|
||||
return s.Where(pk.Eq(id)).Delete()
|
||||
}
|
||||
|
||||
// DeleteByIDs deletes records by a list of primary keys.
|
||||
func (s systemConfigQueryDo) DeleteByIDs(ids ...int64) (gen.ResultInfo, error) {
|
||||
if len(ids) == 0 {
|
||||
return gen.ResultInfo{RowsAffected: 0, Error: nil}, nil
|
||||
}
|
||||
pk := field.NewInt64(s.TableName(), "id")
|
||||
return s.Where(pk.In(ids...)).Delete()
|
||||
}
|
||||
|
||||
func (s *systemConfigQueryDo) withDO(do gen.Dao) *systemConfigQueryDo {
|
||||
s.DO = *do.(*gen.DO)
|
||||
return s
|
||||
}
|
||||
Reference in New Issue
Block a user