carv api logic
This commit is contained in:
29
internal/model/nh_game_report_model.go
Executable file
29
internal/model/nh_game_report_model.go
Executable file
@@ -0,0 +1,29 @@
|
||||
package model
|
||||
|
||||
import "github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||
|
||||
var _ NhGameReportModel = (*customNhGameReportModel)(nil)
|
||||
|
||||
type (
|
||||
// NhGameReportModel is an interface to be customized, add more methods here,
|
||||
// and implement the added methods in customNhGameReportModel.
|
||||
NhGameReportModel interface {
|
||||
nhGameReportModel
|
||||
withSession(session sqlx.Session) NhGameReportModel
|
||||
}
|
||||
|
||||
customNhGameReportModel struct {
|
||||
*defaultNhGameReportModel
|
||||
}
|
||||
)
|
||||
|
||||
// NewNhGameReportModel returns a model for the database table.
|
||||
func NewNhGameReportModel(conn sqlx.SqlConn) NhGameReportModel {
|
||||
return &customNhGameReportModel{
|
||||
defaultNhGameReportModel: newNhGameReportModel(conn),
|
||||
}
|
||||
}
|
||||
|
||||
func (m *customNhGameReportModel) withSession(session sqlx.Session) NhGameReportModel {
|
||||
return NewNhGameReportModel(sqlx.NewSqlConnFromSession(session))
|
||||
}
|
||||
107
internal/model/nh_game_report_model_gen.go
Executable file
107
internal/model/nh_game_report_model_gen.go
Executable file
@@ -0,0 +1,107 @@
|
||||
// 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
|
||||
}
|
||||
Reference in New Issue
Block a user