package goods_info import ( "context" "fmt" "github.com/zeromicro/go-zero/core/stores/sqlx" ) var _ GoodsInfoModel = (*customGoodsInfoModel)(nil) type ( // GoodsInfoModel is an interface to be customized, add more methods here, // and implement the added methods in customGoodsInfoModel. GoodsInfoModel interface { goodsInfoModel withSession(session sqlx.Session) GoodsInfoModel GetGoodsIndex(ctx context.Context, value string) ([]GoodsInfo, error) } customGoodsInfoModel struct { *defaultGoodsInfoModel } ) func (m *customGoodsInfoModel) GetGoodsIndex(ctx context.Context, value string) ([]GoodsInfo, error) { var resp []GoodsInfo var err error if len(value) > 1 || value != "0" { query := fmt.Sprintf("select %s from %s where status = 1 and type = ? order by id desc", goodsInfoRows, m.table) err = m.conn.QueryRowsCtx(ctx, &resp, query, value) } else { query := fmt.Sprintf("select %s from %s where status = 1 order by id desc", goodsInfoRows, m.table) err = m.conn.QueryRowsCtx(ctx, &resp, query) } switch err { case nil: return resp, nil case sqlx.ErrNotFound: return nil, ErrNotFound default: return nil, err } } // NewGoodsInfoModel returns a model for the database table. func NewGoodsInfoModel(conn sqlx.SqlConn) GoodsInfoModel { return &customGoodsInfoModel{ defaultGoodsInfoModel: newGoodsInfoModel(conn), } } func (m *customGoodsInfoModel) withSession(session sqlx.Session) GoodsInfoModel { return NewGoodsInfoModel(sqlx.NewSqlConnFromSession(session)) }