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.

80 lines
2.2 KiB
Go

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

// Code generated by goctl. DO NOT EDIT!
package model
import (
"context"
"git.noahlan.cn/northlan/ntools-go/gorm-zero/gormc"
"gorm.io/plugin/optimisticlock"
"time"
"gorm.io/gorm"
)
type (
userIntegralModel interface {
Insert(ctx context.Context, data *UserIntegral) error
FindOne(ctx context.Context, integral int64) (*UserIntegral, error)
Update(ctx context.Context, data *UserIntegral) error
Delete(ctx context.Context, integral int64) error
}
defaultUserIntegralModel struct {
conn *gorm.DB
table string
}
UserIntegral struct {
UserId int64 `gorm:"column:user_id;primaryKey"` // 用户ID
Integral int64 `gorm:"column:integral"` // 用户积分1 RMB1000
Version optimisticlock.Version `gorm:"column:version"` // 乐观锁
CreateTime time.Time `gorm:"column:create_time;default:null"` // 创建时间
UpdateTime time.Time `gorm:"column:update_time;default:null"` // 更新时间
}
)
func newUserIntegralModel(conn *gorm.DB) *defaultUserIntegralModel {
return &defaultUserIntegralModel{
conn: conn,
table: "`user_integral`",
}
}
func (m *defaultUserIntegralModel) Insert(ctx context.Context, data *UserIntegral) error {
err := m.conn.WithContext(ctx).Create(&data).Error
return err
}
func (m *defaultUserIntegralModel) FindOne(ctx context.Context, integral int64) (*UserIntegral, error) {
var resp UserIntegral
err := m.conn.WithContext(ctx).Model(&UserIntegral{}).Where("`integral` = ?", integral).Take(&resp).Error
switch err {
case nil:
return &resp, nil
case gormc.ErrNotFound:
return nil, ErrNotFound
default:
return nil, err
}
}
func (m *defaultUserIntegralModel) Update(ctx context.Context, data *UserIntegral) error {
err := m.conn.WithContext(ctx).Save(data).Error
return err
}
func (m *defaultUserIntegralModel) Delete(ctx context.Context, integral int64) error {
err := m.conn.WithContext(ctx).Delete(&UserIntegral{}, integral).Error
return err
}
func (m *defaultUserIntegralModel) tableName() string {
return m.table
}
func (UserIntegral) TableName() string {
model := newUserIntegralModel(nil)
return model.tableName()
}