74 lines
3.2 KiB
Go
74 lines
3.2 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 TableNameMediaAsset = "media_assets"
|
|
|
|
// MediaAsset mapped from table <media_assets>
|
|
type MediaAsset 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"`
|
|
Type consts.MediaAssetType `gorm:"column:type;type:character varying(32);not null;default:video" json:"type"`
|
|
Status consts.MediaAssetStatus `gorm:"column:status;type:character varying(32);not null;default:uploaded" json:"status"`
|
|
Provider string `gorm:"column:provider;type:character varying(64);not null" json:"provider"`
|
|
Bucket string `gorm:"column:bucket;type:character varying(128);not null" json:"bucket"`
|
|
ObjectKey string `gorm:"column:object_key;type:character varying(512);not null" json:"object_key"`
|
|
Meta types.JSON `gorm:"column:meta;type:jsonb;not null;default:{}" json:"meta"`
|
|
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 *MediaAsset) Update(ctx context.Context) (gen.ResultInfo, error) {
|
|
return Q.MediaAsset.WithContext(ctx).Updates(m)
|
|
}
|
|
|
|
// Save upserts the model using the default DB.
|
|
func (m *MediaAsset) Save(ctx context.Context) error { return Q.MediaAsset.WithContext(ctx).Save(m) }
|
|
|
|
// Create inserts the model using the default DB.
|
|
func (m *MediaAsset) Create(ctx context.Context) error {
|
|
return Q.MediaAsset.WithContext(ctx).Create(m)
|
|
}
|
|
|
|
// Delete removes the row represented by the model using the default DB.
|
|
func (m *MediaAsset) Delete(ctx context.Context) (gen.ResultInfo, error) {
|
|
return Q.MediaAsset.WithContext(ctx).Delete(m)
|
|
}
|
|
|
|
// ForceDelete permanently deletes the row (ignores soft delete) using the default DB.
|
|
func (m *MediaAsset) ForceDelete(ctx context.Context) (gen.ResultInfo, error) {
|
|
return Q.MediaAsset.WithContext(ctx).Unscoped().Delete(m)
|
|
}
|
|
|
|
// Restore sets deleted_at to NULL for this model's primary key using the default DB.
|
|
func (m *MediaAsset) Restore(ctx context.Context) (gen.ResultInfo, error) {
|
|
return Q.MediaAsset.WithContext(ctx).RestoreByID(m.ID)
|
|
}
|
|
|
|
// Reload reloads the model from database by its primary key and overwrites current fields.
|
|
func (m *MediaAsset) Reload(ctx context.Context) error {
|
|
fresh, err := Q.MediaAsset.WithContext(ctx).GetByID(m.ID)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
*m = *fresh
|
|
return nil
|
|
}
|