fusenapi/model/fsproductsizemodel.go

53 lines
1.6 KiB
Go
Raw Normal View History

2023-06-05 09:13:05 +00:00
package model
2023-06-06 09:36:11 +00:00
import (
"context"
"fmt"
"github.com/zeromicro/go-zero/core/stores/sqlx"
)
2023-06-05 09:13:05 +00:00
var _ FsProductSizeModel = (*customFsProductSizeModel)(nil)
type (
// FsProductSizeModel is an interface to be customized, add more methods here,
// and implement the added methods in customFsProductSizeModel.
FsProductSizeModel interface {
fsProductSizeModel
2023-06-06 09:36:11 +00:00
CountByStatus(ctx context.Context, status int) (total int, err error)
FindAllByStatus(ctx context.Context, status int, sort int) ([]FsProductSize, error)
2023-06-05 09:13:05 +00:00
}
customFsProductSizeModel struct {
*defaultFsProductSizeModel
}
)
// NewFsProductSizeModel returns a model for the database table.
func NewFsProductSizeModel(conn sqlx.SqlConn) FsProductSizeModel {
return &customFsProductSizeModel{
defaultFsProductSizeModel: newFsProductSizeModel(conn),
}
}
2023-06-06 09:36:11 +00:00
func (m *defaultFsProductSizeModel) CountByStatus(ctx context.Context, status int) (total int, err error) {
query := fmt.Sprintf("select %s from %s where `status` = ? limit 1", "count(*) as num", m.table)
err = m.conn.QueryRowCtx(ctx, &total, query, status)
if err != nil {
return 0, err
}
return
}
func (m *defaultFsProductSizeModel) FindAllByStatus(ctx context.Context, status int, sort int) (resp []FsProductSize, err error) {
query := fmt.Sprintf("select %s from %s where `status` = ? ", fsProductSizeRows, m.table)
switch sort {
case 1:
query = fmt.Sprintf("%s order by `sort` ASC", query)
case 2:
query = fmt.Sprintf("%s order by `sort` DESC", query)
}
err = m.conn.QueryRowsCtx(ctx, &resp, query, status)
if err != nil {
return nil, err
}
return
}