You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

82 lines
2.2 KiB
Go

// Code generated by goctl. DO NOT EDIT!
package model
import (
"context"
"git.noahlan.cn/northlan/ntools-go/gorm-zero/gormc"
"time"
"gorm.io/gorm"
)
type (
giftModel interface {
Insert(ctx context.Context, data *Gift) error
FindOne(ctx context.Context, id int64) (*Gift, error)
Update(ctx context.Context, data *Gift) error
Delete(ctx context.Context, id int64) error
}
defaultGiftModel struct {
conn *gorm.DB
table string
}
Gift struct {
Id int64 `gorm:"column:id;primaryKey"` // 主键
GiftId string `gorm:"column:gift_id"` // 礼物ID不同平台可能类型都不同用varchar
GiftName string `gorm:"column:gift_name"` // 礼物名
Platform string `gorm:"column:platform"` // 平台
PPriceFree int64 `gorm:"column:p_price_free"` // 平台免费价值单价B站: 银瓜子虎牙: 银豆
Price float64 `gorm:"column:price"` // 转换后的礼物价值1RMB:1000(p)
CreateTime time.Time `gorm:"column:create_time;default:null"` // 创建时间
PPricePaid int64 `gorm:"column:p_price_paid"` // 平台收费价值单价B站: 金瓜子虎牙: 金豆
}
)
func newGiftModel(conn *gorm.DB) *defaultGiftModel {
return &defaultGiftModel{
conn: conn,
table: "`gift`",
}
}
func (m *defaultGiftModel) Insert(ctx context.Context, data *Gift) error {
err := m.conn.WithContext(ctx).Create(&data).Error
return err
}
func (m *defaultGiftModel) FindOne(ctx context.Context, id int64) (*Gift, error) {
var resp Gift
err := m.conn.WithContext(ctx).Model(&Gift{}).Where("`id` = ?", id).Take(&resp).Error
switch err {
case nil:
return &resp, nil
case gormc.ErrNotFound:
return nil, ErrNotFound
default:
return nil, err
}
}
func (m *defaultGiftModel) Update(ctx context.Context, data *Gift) error {
err := m.conn.WithContext(ctx).Save(data).Error
return err
}
func (m *defaultGiftModel) Delete(ctx context.Context, id int64) error {
err := m.conn.WithContext(ctx).Delete(&Gift{}, id).Error
return err
}
func (m *defaultGiftModel) tableName() string {
return m.table
}
func (Gift) TableName() string {
model := newGiftModel(nil)
return model.tableName()
}