Models

A file containing the implementation of the Model class for database management

class lightdb.models.Model(**kwargs)[source]

Bases: object

A 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

delete() None[source]

Deletes the current instance of the model from the database

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

save() None[source]

Saves the current state of the model instance to the database

class lightdb.models.ModelMeta(name: str, bases: Tuple[type, ...], attrs: Dict[str, Any], **kwargs)[source]

Bases: type

A metaclass for the Model class that ensures that required class-level attributes are present and have valid types