106 lines
3.3 KiB
Go
Executable File
106 lines
3.3 KiB
Go
Executable File
// Code generated by goctl. DO NOT EDIT.
|
|
// versions:
|
|
// goctl version: 1.7.3
|
|
|
|
package model
|
|
|
|
import (
|
|
"context"
|
|
"database/sql"
|
|
"fmt"
|
|
"strings"
|
|
|
|
"github.com/zeromicro/go-zero/core/stores/builder"
|
|
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
|
"github.com/zeromicro/go-zero/core/stringx"
|
|
)
|
|
|
|
var (
|
|
nhRoleFieldNames = builder.RawFieldNames(&NhRole{})
|
|
nhRoleRows = strings.Join(nhRoleFieldNames, ",")
|
|
nhRoleRowsExpectAutoSet = strings.Join(stringx.Remove(nhRoleFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",")
|
|
nhRoleRowsWithPlaceHolder = strings.Join(stringx.Remove(nhRoleFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), "=?,") + "=?"
|
|
)
|
|
|
|
type (
|
|
nhRoleModel interface {
|
|
Insert(ctx context.Context, data *NhRole) (sql.Result, error)
|
|
FindOne(ctx context.Context, id int) (*NhRole, error)
|
|
FindOneByRoleId(ctx context.Context, roleId int64) (*NhRole, error)
|
|
Update(ctx context.Context, data *NhRole) error
|
|
Delete(ctx context.Context, id int) error
|
|
}
|
|
|
|
defaultNhRoleModel struct {
|
|
conn sqlx.SqlConn
|
|
table string
|
|
}
|
|
|
|
NhRole struct {
|
|
Id int `db:"id"`
|
|
RoleId int64 `db:"role_id"` // 角色id
|
|
NickName string `db:"nick_name"` // 角色昵称
|
|
ServerId int `db:"server_id"` // 服务器id
|
|
Account string `db:"account"` // 账号
|
|
CreateTime int `db:"create_time"` // 创角时间
|
|
Uid uint `db:"uid"` // 用户ID
|
|
}
|
|
)
|
|
|
|
func newNhRoleModel(conn sqlx.SqlConn) *defaultNhRoleModel {
|
|
return &defaultNhRoleModel{
|
|
conn: conn,
|
|
table: "`nh_role`",
|
|
}
|
|
}
|
|
|
|
func (m *defaultNhRoleModel) Delete(ctx context.Context, id int) error {
|
|
query := fmt.Sprintf("delete from %s where `id` = ?", m.table)
|
|
_, err := m.conn.ExecCtx(ctx, query, id)
|
|
return err
|
|
}
|
|
|
|
func (m *defaultNhRoleModel) FindOne(ctx context.Context, id int) (*NhRole, error) {
|
|
query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", nhRoleRows, m.table)
|
|
var resp NhRole
|
|
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 *defaultNhRoleModel) FindOneByRoleId(ctx context.Context, roleId int64) (*NhRole, error) {
|
|
var resp NhRole
|
|
query := fmt.Sprintf("select %s from %s where `role_id` = ? limit 1", nhRoleRows, m.table)
|
|
err := m.conn.QueryRowCtx(ctx, &resp, query, roleId)
|
|
switch err {
|
|
case nil:
|
|
return &resp, nil
|
|
case sqlx.ErrNotFound:
|
|
return nil, ErrNotFound
|
|
default:
|
|
return nil, err
|
|
}
|
|
}
|
|
|
|
func (m *defaultNhRoleModel) Insert(ctx context.Context, data *NhRole) (sql.Result, error) {
|
|
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?)", m.table, nhRoleRowsExpectAutoSet)
|
|
ret, err := m.conn.ExecCtx(ctx, query, data.RoleId, data.NickName, data.ServerId, data.Account, data.Uid)
|
|
return ret, err
|
|
}
|
|
|
|
func (m *defaultNhRoleModel) Update(ctx context.Context, newData *NhRole) error {
|
|
query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, nhRoleRowsWithPlaceHolder)
|
|
_, err := m.conn.ExecCtx(ctx, query, newData.RoleId, newData.NickName, newData.ServerId, newData.Account, newData.Uid, newData.Id)
|
|
return err
|
|
}
|
|
|
|
func (m *defaultNhRoleModel) tableName() string {
|
|
return m.table
|
|
}
|