Files
novatask/internal/model/nh_game_report_model_gen.go
lianghuanjie 5d2a0a8b5d carv api logic
2025-01-08 17:53:43 +08:00

108 lines
3.7 KiB
Go
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// Code generated by goctl. DO NOT EDIT.
// versions:
// goctl version: 1.7.3
package model
import (
"context"
"database/sql"
"fmt"
"strings"
"time"
"github.com/zeromicro/go-zero/core/stores/builder"
"github.com/zeromicro/go-zero/core/stores/sqlx"
"github.com/zeromicro/go-zero/core/stringx"
)
var (
nhGameReportFieldNames = builder.RawFieldNames(&NhGameReport{})
nhGameReportRows = strings.Join(nhGameReportFieldNames, ",")
nhGameReportRowsExpectAutoSet = strings.Join(stringx.Remove(nhGameReportFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",")
nhGameReportRowsWithPlaceHolder = strings.Join(stringx.Remove(nhGameReportFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), "=?,") + "=?"
)
type (
nhGameReportModel interface {
Insert(ctx context.Context, data *NhGameReport) (sql.Result, error)
FindOne(ctx context.Context, id uint) (*NhGameReport, error)
FindOneByUid(ctx context.Context, uid uint) (*NhGameReport, error)
Update(ctx context.Context, data *NhGameReport) error
Delete(ctx context.Context, id uint) error
}
defaultNhGameReportModel struct {
conn sqlx.SqlConn
table string
}
NhGameReport struct {
Id uint `db:"id"`
Uid uint `db:"uid"` // 用户ID
IsHaveTwoHero int8 `db:"is_have_two_hero"` // 是否拥有两个以上的英雄1=是
IsUsedSummon int8 `db:"is_used_summon"` // 是否已使用了召唤1=是
IsHaveHero31 int `db:"is_have_hero_31"` // 是否拥有31级以上的英雄1=是
Chapter int `db:"chapter"` // 完成的章节
CreatedAt time.Time `db:"created_at"` // 创建时间
UpdatedAt time.Time `db:"updated_at"` // 修改时间
}
)
func newNhGameReportModel(conn sqlx.SqlConn) *defaultNhGameReportModel {
return &defaultNhGameReportModel{
conn: conn,
table: "`nh_game_report`",
}
}
func (m *defaultNhGameReportModel) Delete(ctx context.Context, id uint) error {
query := fmt.Sprintf("delete from %s where `id` = ?", m.table)
_, err := m.conn.ExecCtx(ctx, query, id)
return err
}
func (m *defaultNhGameReportModel) FindOne(ctx context.Context, id uint) (*NhGameReport, error) {
query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", nhGameReportRows, m.table)
var resp NhGameReport
err := m.conn.QueryRowCtx(ctx, &resp, query, id)
switch err {
case nil:
return &resp, nil
case sqlx.ErrNotFound:
return nil, ErrNotFound
default:
return nil, err
}
}
func (m *defaultNhGameReportModel) FindOneByUid(ctx context.Context, uid uint) (*NhGameReport, error) {
var resp NhGameReport
query := fmt.Sprintf("select %s from %s where `uid` = ? limit 1", nhGameReportRows, m.table)
err := m.conn.QueryRowCtx(ctx, &resp, query, uid)
switch err {
case nil:
return &resp, nil
case sqlx.ErrNotFound:
return nil, ErrNotFound
default:
return nil, err
}
}
func (m *defaultNhGameReportModel) Insert(ctx context.Context, data *NhGameReport) (sql.Result, error) {
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?)", m.table, nhGameReportRowsExpectAutoSet)
ret, err := m.conn.ExecCtx(ctx, query, data.Uid, data.IsHaveTwoHero, data.IsUsedSummon, data.IsHaveHero31, data.Chapter)
return ret, err
}
func (m *defaultNhGameReportModel) Update(ctx context.Context, newData *NhGameReport) error {
query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, nhGameReportRowsWithPlaceHolder)
_, err := m.conn.ExecCtx(ctx, query, newData.Uid, newData.IsHaveTwoHero, newData.IsUsedSummon, newData.IsHaveHero31, newData.Chapter, newData.Id)
return err
}
func (m *defaultNhGameReportModel) tableName() string {
return m.table
}