fusenapi/model/fscanteentypemodel_gen.go
laodaming 2a18f0c21a fix
2023-06-09 12:07:54 +08:00

88 lines
2.9 KiB
Go
Executable File

// 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 (
fsCanteenTypeFieldNames = builder.RawFieldNames(&FsCanteenType{})
fsCanteenTypeRows = strings.Join(fsCanteenTypeFieldNames, ",")
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
}
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"` // 添加时间
}
)
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) 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
}