fusenapi/model/fscanteentypemodel.go
2023-06-06 17:25:49 +08:00

53 lines
1.3 KiB
Go
Executable File

package model
import (
"context"
"fmt"
"github.com/zeromicro/go-zero/core/stores/sqlc"
"github.com/zeromicro/go-zero/core/stores/sqlx"
)
var _ FsCanteenTypeModel = (*customFsCanteenTypeModel)(nil)
type (
// FsCanteenTypeModel is an interface to be customized, add more methods here,
// and implement the added methods in customFsCanteenTypeModel.
FsCanteenTypeModel interface {
fsCanteenTypeModel
FindGetType(ctx context.Context) ([]*FsGetTypeCanteenType, error)
}
customFsCanteenTypeModel struct {
*defaultFsCanteenTypeModel
}
)
// NewFsCanteenTypeModel returns a model for the database table.
func NewFsCanteenTypeModel(conn sqlx.SqlConn) FsCanteenTypeModel {
return &customFsCanteenTypeModel{
defaultFsCanteenTypeModel: newFsCanteenTypeModel(conn),
}
}
type FsGetTypeCanteenType struct {
Id int64 `db:"id" json:"key"` // ID
Name string `db:"name" json:"name"` // 餐厅名字
}
func (m *defaultFsCanteenTypeModel) FindGetType(ctx context.Context) ([]*FsGetTypeCanteenType, error) {
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
}
}