Models¶
A file containing the implementation of the Model class for database management
- class lightdb.models.Model(**kwargs)[source]¶
Bases:
objectA base model class that provides a simple interface for interacting with data in a LightDB database
- classmethod all(use_db: LightDB | None = None) List[MODEL][source]¶
Retrieves a list of all instances of the model from the database
- Returns:
List[Model]: A list of all instances of the model
- classmethod create(**kwargs) MODEL[source]¶
Creates a new instance of the model with the provided keyword arguments and saves it to the database
- Params:
kwargs (
Dict[str, Any]): Keyword arguments representing field names and values for the model instance- Returns:
Model: The newly created instance of the model
- classmethod filter(*args, **kwargs) List[MODEL][source]¶
Retrieves a list of instances of the model that matmatch thech the provided filter criteria
- Params:
kwargs (
Dict[str, Any]): Keyword arguments representing filter criteria for the model instances- Returns:
A list of instances of the model that provided filter criteria
- classmethod get(*args, **kwargs) MODEL | None[source]¶
Retrieves a single instance of the model that matches the provided filter criteria
- Params:
kwargs (
Dict[str, Any]): Keyword arguments representing filter criteria for the model instance- Returns:
Optional[Model]: The matching instance of the model, or None if no matching instance is found