Files
quyun-v2/backend/database/models/contents.gen.go

83 lines
4.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"
"go.ipao.vip/gen/types"
"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);default:draft" json:"status"`
Visibility consts.ContentVisibility `gorm:"column:visibility;type:character varying(32);default:tenant_only" json:"visibility"`
PreviewSeconds int32 `gorm:"column:preview_seconds;type:integer;default:60" json:"preview_seconds"`
PreviewDownloadable bool `gorm:"column:preview_downloadable;type:boolean" json:"preview_downloadable"`
PublishedAt time.Time `gorm:"column:published_at;type:timestamp with time zone" json:"published_at"`
Summary string `gorm:"column:summary;type:character varying(256)" json:"summary"`
Tags types.JSONSlice[string] `gorm:"column:tags;type:jsonb;default:[]" json:"tags"`
Body string `gorm:"column:body;type:text" json:"body"`
Genre string `gorm:"column:genre;type:character varying(64)" json:"genre"`
Views int32 `gorm:"column:views;type:integer" json:"views"`
Likes int32 `gorm:"column:likes;type:integer" json:"likes"`
CreatedAt time.Time `gorm:"column:created_at;type:timestamp with time zone;default:now()" json:"created_at"`
UpdatedAt time.Time `gorm:"column:updated_at;type:timestamp with time zone;default:now()" json:"updated_at"`
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
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"`
}
// 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
}