106 lines
3.4 KiB
Go
Executable File
106 lines
3.4 KiB
Go
Executable File
// Code generated by goctl. DO NOT EDIT.
|
|
// versions:
|
|
// goctl version: 1.7.6
|
|
|
|
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 (
|
|
nhTriballyUserFieldNames = builder.RawFieldNames(&NhTriballyUser{})
|
|
nhTriballyUserRows = strings.Join(nhTriballyUserFieldNames, ",")
|
|
nhTriballyUserRowsExpectAutoSet = strings.Join(stringx.Remove(nhTriballyUserFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",")
|
|
nhTriballyUserRowsWithPlaceHolder = strings.Join(stringx.Remove(nhTriballyUserFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), "=?,") + "=?"
|
|
)
|
|
|
|
type (
|
|
nhTriballyUserModel interface {
|
|
Insert(ctx context.Context, data *NhTriballyUser) (sql.Result, error)
|
|
FindOne(ctx context.Context, id uint) (*NhTriballyUser, error)
|
|
FindOneByUid(ctx context.Context, uid uint) (*NhTriballyUser, error)
|
|
Update(ctx context.Context, data *NhTriballyUser) error
|
|
Delete(ctx context.Context, id uint) error
|
|
}
|
|
|
|
defaultNhTriballyUserModel struct {
|
|
conn sqlx.SqlConn
|
|
table string
|
|
}
|
|
|
|
NhTriballyUser struct {
|
|
Id uint `db:"id"`
|
|
Uid uint `db:"uid"` // 用户id
|
|
Email string `db:"email"` // 邮箱
|
|
Chapter int `db:"chapter"` // 章节
|
|
CreatedAt time.Time `db:"created_at"` // 创建时间
|
|
UpdatedAt time.Time `db:"updated_at"` // 修改时间
|
|
}
|
|
)
|
|
|
|
func newNhTriballyUserModel(conn sqlx.SqlConn) *defaultNhTriballyUserModel {
|
|
return &defaultNhTriballyUserModel{
|
|
conn: conn,
|
|
table: "`nh_tribally_user`",
|
|
}
|
|
}
|
|
|
|
func (m *defaultNhTriballyUserModel) 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 *defaultNhTriballyUserModel) FindOne(ctx context.Context, id uint) (*NhTriballyUser, error) {
|
|
query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", nhTriballyUserRows, m.table)
|
|
var resp NhTriballyUser
|
|
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 *defaultNhTriballyUserModel) FindOneByUid(ctx context.Context, uid uint) (*NhTriballyUser, error) {
|
|
var resp NhTriballyUser
|
|
query := fmt.Sprintf("select %s from %s where `uid` = ? limit 1", nhTriballyUserRows, 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 *defaultNhTriballyUserModel) Insert(ctx context.Context, data *NhTriballyUser) (sql.Result, error) {
|
|
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?)", m.table, nhTriballyUserRowsExpectAutoSet)
|
|
ret, err := m.conn.ExecCtx(ctx, query, data.Uid, data.Email, data.Chapter)
|
|
return ret, err
|
|
}
|
|
|
|
func (m *defaultNhTriballyUserModel) Update(ctx context.Context, newData *NhTriballyUser) error {
|
|
query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, nhTriballyUserRowsWithPlaceHolder)
|
|
_, err := m.conn.ExecCtx(ctx, query, newData.Uid, newData.Email, newData.Chapter, newData.Id)
|
|
return err
|
|
}
|
|
|
|
func (m *defaultNhTriballyUserModel) tableName() string {
|
|
return m.table
|
|
}
|