package model import ( "context" "fmt" "github.com/zeromicro/go-zero/core/stores/sqlx" ) 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 CountByStatus(ctx context.Context, status int) (total int, err error) FindAllByStatus(ctx context.Context, status int, sort int) ([]FsProductSize, error) } customFsProductSizeModel struct { *defaultFsProductSizeModel } ) // NewFsProductSizeModel returns a model for the database table. func NewFsProductSizeModel(conn sqlx.SqlConn) FsProductSizeModel { return &customFsProductSizeModel{ defaultFsProductSizeModel: newFsProductSizeModel(conn), } } 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 }