tessl install tessl/pypi-sqlmodel@0.0.0SQLModel, SQL databases in Python, designed for simplicity, compatibility, and robustness.
Agent Success
Agent success rate when using this tile
85%
Improvement
Agent success rate improvement when using this tile compared to baseline
1x
Baseline
Agent success rate without this tile
85%
Build a product inventory query system that allows filtering, sorting, and paginating products from a database.
Create a Python module that provides functions to query product inventory data. The system should support:
Filtering products by various criteria:
Sorting:
Pagination:
Combining filters:
Define a Product database model with these fields:
id: Integer, primary key (auto-generated)name: String, requiredcategory: String, required (e.g., "Electronics", "Books", "Clothing")price: Float, required (product price in dollars)stock_quantity: Integer, required (number of items in stock)@generates
Create a module with the following query functions:
get_products_above_price(session, min_price) - Returns products priced above the thresholdget_products_in_price_range(session, min_price, max_price) - Returns products within price rangeget_low_stock_products(session, threshold) - Returns products with stock below thresholdget_products_by_categories(session, categories) - Returns products in specified categories (list)get_products_sorted_by_price(session, descending=False) - Returns products sorted by priceget_paginated_products(session, page, page_size) - Returns a specific page of productsget_filtered_products(session, min_price=None, max_price=None, categories=None, min_stock=None) - Returns products matching all provided filtersfrom typing import Optional
from sqlmodel import SQLModel, Field
class Product(SQLModel, table=True):
"""Product inventory model."""
id: Optional[int] = Field(default=None, primary_key=True)
name: str
category: str
price: float
stock_quantity: int
def get_products_above_price(session, min_price: float) -> list[Product]:
"""Return all products with price greater than min_price."""
pass
def get_products_in_price_range(session, min_price: float, max_price: float) -> list[Product]:
"""Return all products with price between min_price and max_price (inclusive)."""
pass
def get_low_stock_products(session, threshold: int) -> list[Product]:
"""Return all products with stock_quantity less than threshold."""
pass
def get_products_by_categories(session, categories: list[str]) -> list[Product]:
"""Return all products belonging to any of the specified categories."""
pass
def get_products_sorted_by_price(session, descending: bool = False) -> list[Product]:
"""Return all products sorted by price."""
pass
def get_paginated_products(session, page: int, page_size: int) -> list[Product]:
"""Return a specific page of products (page is 1-indexed)."""
pass
def get_filtered_products(
session,
min_price: Optional[float] = None,
max_price: Optional[float] = None,
categories: Optional[list[str]] = None,
min_stock: Optional[int] = None
) -> list[Product]:
"""Return all products matching all provided filter criteria."""
passProvides database ORM and query building capabilities.