72 lines
3.4 KiB
Go
72 lines
3.4 KiB
Go
// Code generated by go.ipao.vip/gen. DO NOT EDIT.
|
|
// Code generated by go.ipao.vip/gen. DO NOT EDIT.
|
|
// Code generated by go.ipao.vip/gen. DO NOT EDIT.
|
|
|
|
package models
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"quyun/v2/pkg/consts"
|
|
|
|
"go.ipao.vip/gen"
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
const TableNameContent = "contents"
|
|
|
|
// Content mapped from table <contents>
|
|
type Content struct {
|
|
ID int64 `gorm:"column:id;type:bigint;primaryKey;autoIncrement:true" json:"id"`
|
|
TenantID int64 `gorm:"column:tenant_id;type:bigint;not null" json:"tenant_id"`
|
|
UserID int64 `gorm:"column:user_id;type:bigint;not null" json:"user_id"`
|
|
Title string `gorm:"column:title;type:character varying(255);not null" json:"title"`
|
|
Description string `gorm:"column:description;type:text;not null" json:"description"`
|
|
Status consts.ContentStatus `gorm:"column:status;type:character varying(32);not null;default:draft" json:"status"`
|
|
Visibility consts.ContentVisibility `gorm:"column:visibility;type:character varying(32);not null;default:tenant_only" json:"visibility"`
|
|
PreviewSeconds int32 `gorm:"column:preview_seconds;type:integer;not null;default:60" json:"preview_seconds"`
|
|
PreviewDownloadable bool `gorm:"column:preview_downloadable;type:boolean;not null" json:"preview_downloadable"`
|
|
PublishedAt time.Time `gorm:"column:published_at;type:timestamp with time zone" json:"published_at"`
|
|
DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;type:timestamp with time zone" json:"deleted_at"`
|
|
CreatedAt time.Time `gorm:"column:created_at;type:timestamp with time zone;not null;default:now()" json:"created_at"`
|
|
UpdatedAt time.Time `gorm:"column:updated_at;type:timestamp with time zone;not null;default:now()" json:"updated_at"`
|
|
}
|
|
|
|
// Quick operations without importing query package
|
|
// Update applies changed fields to the database using the default DB.
|
|
func (m *Content) Update(ctx context.Context) (gen.ResultInfo, error) {
|
|
return Q.Content.WithContext(ctx).Updates(m)
|
|
}
|
|
|
|
// Save upserts the model using the default DB.
|
|
func (m *Content) Save(ctx context.Context) error { return Q.Content.WithContext(ctx).Save(m) }
|
|
|
|
// Create inserts the model using the default DB.
|
|
func (m *Content) Create(ctx context.Context) error { return Q.Content.WithContext(ctx).Create(m) }
|
|
|
|
// Delete removes the row represented by the model using the default DB.
|
|
func (m *Content) Delete(ctx context.Context) (gen.ResultInfo, error) {
|
|
return Q.Content.WithContext(ctx).Delete(m)
|
|
}
|
|
|
|
// ForceDelete permanently deletes the row (ignores soft delete) using the default DB.
|
|
func (m *Content) ForceDelete(ctx context.Context) (gen.ResultInfo, error) {
|
|
return Q.Content.WithContext(ctx).Unscoped().Delete(m)
|
|
}
|
|
|
|
// Restore sets deleted_at to NULL for this model's primary key using the default DB.
|
|
func (m *Content) Restore(ctx context.Context) (gen.ResultInfo, error) {
|
|
return Q.Content.WithContext(ctx).RestoreByID(m.ID)
|
|
}
|
|
|
|
// Reload reloads the model from database by its primary key and overwrites current fields.
|
|
func (m *Content) Reload(ctx context.Context) error {
|
|
fresh, err := Q.Content.WithContext(ctx).GetByID(m.ID)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
*m = *fresh
|
|
return nil
|
|
}
|