tribally report
This commit is contained in:
105
internal/model/nh_global_data_model_gen.go
Executable file
105
internal/model/nh_global_data_model_gen.go
Executable file
@@ -0,0 +1,105 @@
|
||||
// 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 (
|
||||
nhGlobalDataFieldNames = builder.RawFieldNames(&NhGlobalData{})
|
||||
nhGlobalDataRows = strings.Join(nhGlobalDataFieldNames, ",")
|
||||
nhGlobalDataRowsExpectAutoSet = strings.Join(stringx.Remove(nhGlobalDataFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",")
|
||||
nhGlobalDataRowsWithPlaceHolder = strings.Join(stringx.Remove(nhGlobalDataFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), "=?,") + "=?"
|
||||
)
|
||||
|
||||
type (
|
||||
nhGlobalDataModel interface {
|
||||
Insert(ctx context.Context, data *NhGlobalData) (sql.Result, error)
|
||||
FindOne(ctx context.Context, id uint) (*NhGlobalData, error)
|
||||
FindOneByKey(ctx context.Context, key string) (*NhGlobalData, error)
|
||||
Update(ctx context.Context, data *NhGlobalData) error
|
||||
Delete(ctx context.Context, id uint) error
|
||||
}
|
||||
|
||||
defaultNhGlobalDataModel struct {
|
||||
conn sqlx.SqlConn
|
||||
table string
|
||||
}
|
||||
|
||||
NhGlobalData struct {
|
||||
Id uint `db:"id"`
|
||||
Key string `db:"key"` // key
|
||||
Value string `db:"value"` // value
|
||||
Remark string `db:"remark"` // 备注
|
||||
CreatedAt time.Time `db:"created_at"` // 创建时间
|
||||
UpdatedAt time.Time `db:"updated_at"` // 修改时间
|
||||
}
|
||||
)
|
||||
|
||||
func newNhGlobalDataModel(conn sqlx.SqlConn) *defaultNhGlobalDataModel {
|
||||
return &defaultNhGlobalDataModel{
|
||||
conn: conn,
|
||||
table: "`nh_global_data`",
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultNhGlobalDataModel) 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 *defaultNhGlobalDataModel) FindOne(ctx context.Context, id uint) (*NhGlobalData, error) {
|
||||
query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", nhGlobalDataRows, m.table)
|
||||
var resp NhGlobalData
|
||||
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 *defaultNhGlobalDataModel) FindOneByKey(ctx context.Context, key string) (*NhGlobalData, error) {
|
||||
var resp NhGlobalData
|
||||
query := fmt.Sprintf("select %s from %s where `key` = ? limit 1", nhGlobalDataRows, m.table)
|
||||
err := m.conn.QueryRowCtx(ctx, &resp, query, key)
|
||||
switch err {
|
||||
case nil:
|
||||
return &resp, nil
|
||||
case sqlx.ErrNotFound:
|
||||
return nil, ErrNotFound
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultNhGlobalDataModel) Insert(ctx context.Context, data *NhGlobalData) (sql.Result, error) {
|
||||
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?)", m.table, nhGlobalDataRowsExpectAutoSet)
|
||||
ret, err := m.conn.ExecCtx(ctx, query, data.Key, data.Value, data.Remark)
|
||||
return ret, err
|
||||
}
|
||||
|
||||
func (m *defaultNhGlobalDataModel) Update(ctx context.Context, newData *NhGlobalData) error {
|
||||
query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, nhGlobalDataRowsWithPlaceHolder)
|
||||
_, err := m.conn.ExecCtx(ctx, query, newData.Key, newData.Value, newData.Remark, newData.Id)
|
||||
return err
|
||||
}
|
||||
|
||||
func (m *defaultNhGlobalDataModel) tableName() string {
|
||||
return m.table
|
||||
}
|
||||
Reference in New Issue
Block a user