Skip to content

query

Query operations for database controllers.

Classes:

  • QueryController

    Handles query building, filtering, and advanced searches.

Classes

QueryController

Python
QueryController(model: type[ModelT], db: DatabaseService)

Handles query building, filtering, and advanced searches.

Initialize the query controller.

Parameters:

  • model (type[ModelT]) –

    The SQLModel to query.

  • db (DatabaseService) –

    The database service instance.

Methods:

Functions

build_filters
Python
build_filters(filters: Any) -> Any

Build filter expressions from various input types.

Returns:

  • Any

    Combined filter expression, or None if no filters.

find_one async
Python
find_one(
    filters: Any | None = None, order_by: OrderByType | None = None
) -> ModelT | None

Find one record.

Returns:

  • ModelT | None

    The found record, or None if not found.

find_all async
Python
find_all(
    filters: Any | None = None,
    order_by: OrderByType | None = None,
    limit: int | None = None,
    offset: int | None = None,
) -> list[ModelT]

Find all records with performance optimizations.

Returns:

  • list[ModelT]

    List of found records.

find_all_with_options async
Python
find_all_with_options(
    filters: Any | None = None,
    order_by: OrderByType | None = None,
    limit: int | None = None,
    offset: int | None = None,
    load_relationships: list[str] | None = None,
) -> list[ModelT]

Find all records with relationship loading options.

Returns:

  • list[ModelT]

    List of found records with loaded relationships.

count async
Python
count(filters: Any | None = None) -> int

Count records.

Returns:

  • int

    The count of matching records.

get_all async
Python
get_all(filters: Any | None = None, order_by: Any | None = None) -> list[ModelT]

Get all records (alias for find_all without pagination).

Returns:

  • list[ModelT]

    List of all matching records.

execute_query async
Python
execute_query(query: Any) -> Any

Execute a custom query.

Returns:

  • Any

    The query result.

find_with_json_query async
Python
find_with_json_query(
    json_column: str, json_path: str, value: Any, filters: Any | None = None
) -> list[ModelT]

Find records using JSON column queries.

Returns:

  • list[ModelT]

    List of records matching the JSON query.

find_with_array_contains async
Python
find_with_array_contains(
    array_column: str, value: Any, filters: Any | None = None
) -> list[ModelT]

Find records where array column contains value.

Returns:

  • list[ModelT]

    List of records with matching array values.

Python
find_with_full_text_search(
    search_columns: list[str], search_term: str, filters: Any | None = None
) -> list[ModelT]

Find records using full-text search.

Returns:

  • list[ModelT]

    List of records matching the search term.

Functions