Files
quyun-v2/backend/database/models/comments.gen.go
2025-12-29 09:30:49 +08:00

67 lines
2.6 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"
"go.ipao.vip/gen"
"gorm.io/gorm"
)
const TableNameComment = "comments"
// Comment mapped from table <comments>
type Comment struct {
ID int64 `gorm:"column:id;type:bigint;primaryKey;autoIncrement:true" json:"id"`
TenantID int64 `gorm:"column:tenant_id;type:bigint;not null" json:"tenant_id"`
UserID int64 `gorm:"column:user_id;type:bigint;not null" json:"user_id"`
ContentID int64 `gorm:"column:content_id;type:bigint;not null" json:"content_id"`
ReplyTo int64 `gorm:"column:reply_to;type:bigint" json:"reply_to"`
Content string `gorm:"column:content;type:text;not null" json:"content"`
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"`
}
// Quick operations without importing query package
// Update applies changed fields to the database using the default DB.
func (m *Comment) Update(ctx context.Context) (gen.ResultInfo, error) {
return Q.Comment.WithContext(ctx).Updates(m)
}
// Save upserts the model using the default DB.
func (m *Comment) Save(ctx context.Context) error { return Q.Comment.WithContext(ctx).Save(m) }
// Create inserts the model using the default DB.
func (m *Comment) Create(ctx context.Context) error { return Q.Comment.WithContext(ctx).Create(m) }
// Delete removes the row represented by the model using the default DB.
func (m *Comment) Delete(ctx context.Context) (gen.ResultInfo, error) {
return Q.Comment.WithContext(ctx).Delete(m)
}
// ForceDelete permanently deletes the row (ignores soft delete) using the default DB.
func (m *Comment) ForceDelete(ctx context.Context) (gen.ResultInfo, error) {
return Q.Comment.WithContext(ctx).Unscoped().Delete(m)
}
// Restore sets deleted_at to NULL for this model's primary key using the default DB.
func (m *Comment) Restore(ctx context.Context) (gen.ResultInfo, error) {
return Q.Comment.WithContext(ctx).RestoreByID(m.ID)
}
// Reload reloads the model from database by its primary key and overwrites current fields.
func (m *Comment) Reload(ctx context.Context) error {
fresh, err := Q.Comment.WithContext(ctx).GetByID(m.ID)
if err != nil {
return err
}
*m = *fresh
return nil
}