// 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 }