fusenapi/model/fscanteentypemodel_gen.go

113 lines
3.7 KiB
Go
Raw Normal View History

2023-06-01 08:19:24 +00:00
// Code generated by goctl. DO NOT EDIT.
package model
import (
"context"
"database/sql"
"fmt"
"strings"
"github.com/zeromicro/go-zero/core/stores/builder"
"github.com/zeromicro/go-zero/core/stores/sqlc"
"github.com/zeromicro/go-zero/core/stores/sqlx"
"github.com/zeromicro/go-zero/core/stringx"
)
var (
2023-06-02 11:24:58 +00:00
fsCanteenTypeFieldNames = builder.RawFieldNames(&FsCanteenType{})
fsCanteenTypeRows = strings.Join(fsCanteenTypeFieldNames, ",")
2023-06-01 08:19:24 +00:00
// fsCanteenTypeGetTypeRows = strings.Join(stringx.Remove(fsCanteenTypeFieldNames, "`id`", "`name`", "`sort`", "`created_at`", "`status`"), ",")
// fsCanteenTypeGetTypeRows = builder.RawFieldNames(&FsGetTypeCanteenType{})
fsCanteenTypeRowsExpectAutoSet = strings.Join(stringx.Remove(fsCanteenTypeFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",")
fsCanteenTypeRowsWithPlaceHolder = strings.Join(stringx.Remove(fsCanteenTypeFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), "=?,") + "=?"
)
type (
fsCanteenTypeModel interface {
Insert(ctx context.Context, data *FsCanteenType) (sql.Result, error)
FindOne(ctx context.Context, id int64) (*FsCanteenType, error)
Update(ctx context.Context, data *FsCanteenType) error
Delete(ctx context.Context, id int64) error
2023-06-02 11:24:58 +00:00
2023-06-01 08:19:24 +00:00
FindGetType(ctx context.Context) ([]*FsGetTypeCanteenType, error)
}
defaultFsCanteenTypeModel struct {
conn sqlx.SqlConn
table string
}
FsCanteenType struct {
Id int64 `db:"id"` // ID
Name string `db:"name"` // 餐厅名字
Sort int64 `db:"sort"` // 排序
Status int64 `db:"status"` // 状态位 1启用0停用
Ctime int64 `db:"ctime"` // 添加时间
}
FsGetTypeCanteenType struct {
2023-06-02 11:24:58 +00:00
Id int64 `db:"id" json:"key"` // ID
Name string `db:"name" json:"name"` // 餐厅名字
2023-06-01 08:19:24 +00:00
}
)
func newFsCanteenTypeModel(conn sqlx.SqlConn) *defaultFsCanteenTypeModel {
return &defaultFsCanteenTypeModel{
conn: conn,
table: "`fs_canteen_type`",
}
}
func (m *defaultFsCanteenTypeModel) Delete(ctx context.Context, id int64) error {
query := fmt.Sprintf("delete from %s where `id` = ?", m.table)
_, err := m.conn.ExecCtx(ctx, query, id)
return err
}
func (m *defaultFsCanteenTypeModel) FindOne(ctx context.Context, id int64) (*FsCanteenType, error) {
query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", fsCanteenTypeRows, m.table)
var resp FsCanteenType
err := m.conn.QueryRowCtx(ctx, &resp, query, id)
switch err {
case nil:
return &resp, nil
case sqlc.ErrNotFound:
return nil, ErrNotFound
default:
return nil, err
}
}
func (m *defaultFsCanteenTypeModel) FindGetType(ctx context.Context) ([]*FsGetTypeCanteenType, error) {
2023-06-02 11:24:58 +00:00
2023-06-01 08:19:24 +00:00
query := fmt.Sprintf("select X.id,X.name from (select %s from %s where status = 1 order by sort desc) X", fsCanteenTypeRows, m.table)
var resp []*FsGetTypeCanteenType
err := m.conn.QueryRows(&resp, query)
switch err {
case nil:
return resp, nil
case sqlc.ErrNotFound:
return nil, ErrNotFound
default:
return nil, err
}
}
func (m *defaultFsCanteenTypeModel) Insert(ctx context.Context, data *FsCanteenType) (sql.Result, error) {
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?)", m.table, fsCanteenTypeRowsExpectAutoSet)
ret, err := m.conn.ExecCtx(ctx, query, data.Name, data.Sort, data.Status, data.Ctime)
return ret, err
}
func (m *defaultFsCanteenTypeModel) Update(ctx context.Context, data *FsCanteenType) error {
query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, fsCanteenTypeRowsWithPlaceHolder)
_, err := m.conn.ExecCtx(ctx, query, data.Name, data.Sort, data.Status, data.Ctime, data.Id)
return err
}
func (m *defaultFsCanteenTypeModel) tableName() string {
return m.table
}