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.

88 lines
2.6 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"
"database/sql"
"fmt"
"strings"
"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 (
giftFieldNames = builder.RawFieldNames(&Gift{})
giftRows = strings.Join(giftFieldNames, ",")
giftRowsExpectAutoSet = strings.Join(stringx.Remove(giftFieldNames, "`create_time`", "`update_time`"), ",")
giftRowsWithPlaceHolder = strings.Join(stringx.Remove(giftFieldNames, "`id`", "`create_time`", "`update_time`"), "=?,") + "=?"
)
type (
giftModel interface {
Insert(ctx context.Context, data *Gift) (sql.Result, 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 sqlx.SqlConn
table string
}
Gift struct {
Id int64 `db:"id"` // 主键
GiftId string `db:"gift_id"` // 礼物ID不同平台可能类型都不同用varchar
GiftName string `db:"gift_name"` // 礼物名
Platform string `db:"platform"` // 平台
PPrice int64 `db:"p_price"` // 平台价值货币总数B站: 瓜子虎牙: xxx
}
)
func newGiftModel(conn sqlx.SqlConn) *defaultGiftModel {
return &defaultGiftModel{
conn: conn,
table: "`gift`",
}
}
func (m *defaultGiftModel) Insert(ctx context.Context, data *Gift) (sql.Result, error) {
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?)", m.table, giftRowsExpectAutoSet)
ret, err := m.conn.ExecCtx(ctx, query, data.Id, data.GiftId, data.GiftName, data.Platform, data.PPrice)
return ret, err
}
func (m *defaultGiftModel) FindOne(ctx context.Context, id int64) (*Gift, error) {
query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", giftRows, m.table)
var resp Gift
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 *defaultGiftModel) Update(ctx context.Context, data *Gift) error {
query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, giftRowsWithPlaceHolder)
_, err := m.conn.ExecCtx(ctx, query, data.GiftId, data.GiftName, data.Platform, data.PPrice, data.Id)
return err
}
func (m *defaultGiftModel) 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 *defaultGiftModel) tableName() string {
return m.table
}