100 lines
3.8 KiB
Go
Executable File
100 lines
3.8 KiB
Go
Executable File
// Code generated by goctl. DO NOT EDIT.
|
||
|
||
package model
|
||
|
||
import (
|
||
"context"
|
||
"database/sql"
|
||
"fmt"
|
||
"strings"
|
||
"time"
|
||
|
||
"github.com/zeromicro/go-zero/core/stores/builder"
|
||
"github.com/zeromicro/go-zero/core/stores/sqlc"
|
||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||
"github.com/zeromicro/go-zero/core/stringx"
|
||
)
|
||
|
||
var (
|
||
fsCartFieldNames = builder.RawFieldNames(&FsCart{})
|
||
fsCartRows = strings.Join(fsCartFieldNames, ",")
|
||
fsCartRowsExpectAutoSet = strings.Join(stringx.Remove(fsCartFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",")
|
||
fsCartRowsWithPlaceHolder = strings.Join(stringx.Remove(fsCartFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), "=?,") + "=?"
|
||
)
|
||
|
||
type (
|
||
fsCartModel interface {
|
||
Insert(ctx context.Context, data *FsCart) (sql.Result, error)
|
||
FindOne(ctx context.Context, id int64) (*FsCart, error)
|
||
Update(ctx context.Context, data *FsCart) error
|
||
Delete(ctx context.Context, id int64) error
|
||
}
|
||
|
||
defaultFsCartModel struct {
|
||
conn sqlx.SqlConn
|
||
table string
|
||
}
|
||
|
||
FsCart struct {
|
||
Id int64 `db:"id"` // id
|
||
UserId sql.NullInt64 `db:"user_id"` // 用户ID
|
||
ProductId int64 `db:"product_id"` // 产品ID
|
||
TemplateId int64 `db:"template_id"` // 模板ID
|
||
PriceId int64 `db:"price_id"` // 价格ID
|
||
MaterialId int64 `db:"material_id"` // 材质ID
|
||
SizeId int64 `db:"size_id"` // 尺寸ID
|
||
BuyNum int64 `db:"buy_num"` // 购买数量
|
||
Cover string `db:"cover"` // 截图
|
||
DesignId int64 `db:"design_id"` // 设计ID
|
||
Ctime sql.NullInt64 `db:"ctime"` // 添加时间
|
||
Status int64 `db:"status"` // 状态位
|
||
OptionalId int64 `db:"optional_id"` // 选项ID
|
||
IsCheck int64 `db:"is_check"` // 是否选中状态(0:未选中,1:选中)
|
||
TsTime time.Time `db:"ts_time"`
|
||
IsEmail int64 `db:"is_email"` // 是否发送邮件
|
||
}
|
||
)
|
||
|
||
func newFsCartModel(conn sqlx.SqlConn) *defaultFsCartModel {
|
||
return &defaultFsCartModel{
|
||
conn: conn,
|
||
table: "`fs_cart`",
|
||
}
|
||
}
|
||
|
||
func (m *defaultFsCartModel) Delete(ctx context.Context, id int64) error {
|
||
query := fmt.Sprintf("delete from %s where `id` = ?", m.table)
|
||
_, err := m.conn.ExecCtx(ctx, query, id)
|
||
return err
|
||
}
|
||
|
||
func (m *defaultFsCartModel) FindOne(ctx context.Context, id int64) (*FsCart, error) {
|
||
query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", fsCartRows, m.table)
|
||
var resp FsCart
|
||
err := m.conn.QueryRowCtx(ctx, &resp, query, id)
|
||
switch err {
|
||
case nil:
|
||
return &resp, nil
|
||
case sqlc.ErrNotFound:
|
||
return nil, ErrNotFound
|
||
default:
|
||
return nil, err
|
||
}
|
||
}
|
||
|
||
func (m *defaultFsCartModel) Insert(ctx context.Context, data *FsCart) (sql.Result, error) {
|
||
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", m.table, fsCartRowsExpectAutoSet)
|
||
ret, err := m.conn.ExecCtx(ctx, query, data.UserId, data.ProductId, data.TemplateId, data.PriceId, data.MaterialId, data.SizeId, data.BuyNum, data.Cover, data.DesignId, data.Ctime, data.Status, data.OptionalId, data.IsCheck, data.TsTime, data.IsEmail)
|
||
return ret, err
|
||
}
|
||
|
||
func (m *defaultFsCartModel) Update(ctx context.Context, data *FsCart) error {
|
||
query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, fsCartRowsWithPlaceHolder)
|
||
_, err := m.conn.ExecCtx(ctx, query, data.UserId, data.ProductId, data.TemplateId, data.PriceId, data.MaterialId, data.SizeId, data.BuyNum, data.Cover, data.DesignId, data.Ctime, data.Status, data.OptionalId, data.IsCheck, data.TsTime, data.IsEmail, data.Id)
|
||
return err
|
||
}
|
||
|
||
func (m *defaultFsCartModel) tableName() string {
|
||
return m.table
|
||
}
|