Skip to content

crud

Core CRUD operations for database controllers.

Classes:

  • CrudController

    Handles basic Create, Read, Update, Delete operations.

Classes

CrudController

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

Handles basic Create, Read, Update, Delete operations.

Initialize the CRUD controller.

Parameters:

  • model (type[ModelT]) –

    The SQLModel to perform CRUD operations on.

  • db (DatabaseService) –

    The database service instance.

Methods:

Functions

create async
Python
create(**kwargs: Any) -> ModelT

Create a new record.

Returns:

  • ModelT

    The newly created record.

get_by_id async
Python
get_by_id(record_id: Any) -> ModelT | None

Get a record by ID.

Returns:

  • ModelT | None

    The record if found, None otherwise.

update_by_id async
Python
update_by_id(record_id: Any, **values: Any) -> ModelT | None

Update a record by ID.

Returns:

  • ModelT | None

    The updated record, or None if not found.

delete_by_id async
Python
delete_by_id(record_id: Any) -> bool

Delete a record by ID.

Returns:

  • bool

    True if deleted successfully, False otherwise.

exists async
Python
exists(filters: Any) -> bool

Check if a record exists.

Returns:

  • bool

    True if record exists, False otherwise.

Functions