qunicorn_core.db.models.db_model module
- class qunicorn_core.db.models.db_model.DbModel
Bases:
objectDataclass for database model to create a table name and the id column
- classmethod apply_ordering(query: Select) Select
- classmethod delete_by_id(id_: int, commit: bool = False)
Delete a single database object by its id attribute and optionally commit all pending changes.
- classmethod get_all(where: Sequence[ColumnElement[_T] | _HasClauseElement[bool] | SQLCoreOperations[_T] | ExpressionElementRole[bool] | TypedColumnsClauseRole[bool] | Callable[[], ColumnElement[_T]] | LambdaElement] | None = None, limit: int | None = None, offset: int | None = None)
Get all database objects of this class.
Objects can be filtered by providing a sequence of sql expressions as
whereclause. All expressions must evaluate to True for an item to be included (i.e., clauses are joined by an AND).Limit and offset can be used for pagination.
- classmethod get_all_authenticated(user_id: str | None, where: Sequence[ColumnElement[_T] | _HasClauseElement[bool] | SQLCoreOperations[_T] | ExpressionElementRole[bool] | TypedColumnsClauseRole[bool] | Callable[[], ColumnElement[_T]] | LambdaElement] | None = None, limit: int | None = None, offset: int | None = None)
Get all database objects of this class that the given user is allowed to access.
Uses the apply_authentication_filter method to filter out objects.
Additionally, objects can be filtered by providing a sequence of sql expressions as
whereclause. All expressions must evaluate to True for an item to be included (i.e., clauses are joined by an AND).Limit and offset can be used for pagination.
- classmethod get_by_id_authenticated(id_: int, user_id: str | None)
Get a single database object by its id attribute and return None if not found or the user has insufficient rights.
- classmethod get_by_id_authenticated_or_404(id_: int, user_id: str | None)
Get a single database object by its id attribute and raise 404 error if not found or the user has insufficient rights.
- classmethod get_by_id_or_404(id_: int)
Get a single database object by its id attribute and raise 404 error if not found.