luminadb.models package

Submodules

Module contents

Models

class luminadb.models.BaseModel[source]

Bases: object

Base class for all Models using Model API

classmethod all()[source]

Return all values from the table

classmethod atomic()[source]

Perform operations within a transaction.

belongs_to(related_model: Type[T])[source]

Retrieve the related model that this instance belongs to.

classmethod bulk_create(records: list[dict])[source]

Insert multiple records at once.

classmethod bulk_delete(keys: list[Any], key: str)[source]

Delete multiple records using a primary key.

classmethod bulk_update(records: list[dict], key: str | object = <object object>)[source]

Update multiple records using a primary key or provided key.

classmethod count(**kwargs) int[source]

Return count of matching records.

classmethod create(**kwargs)[source]

Create data based on kwargs

classmethod create_table(db: Database)[source]

Create table according to annotations and schema from __schema__

delete(_BaseModel__primary=<object object>, /)[source]

Delete current data

classmethod exists(**kwargs) bool[source]

Check if any record matches the query.

classmethod find(amount: int)[source]

Return models relative to the amount

classmethod find_or_fail(amount: int)[source]

Return models relative to the amount and when returned is equal to 0, throws an error

classmethod first(**kwargs)[source]

Return the first matching record or None if no match is found.

classmethod first_or_fail(**kwargs)[source]

Return the first matching record or raise an error if no match is found.

classmethod get_table()[source]

Return table instance

has_many(related: ~typing.Type[~luminadb.models.T], foreign_key: str | object = <object object>)[source]

Ensure related_model has a Foreign key pointing to self

has_one(related_model: Type[T])[source]

Retrieve the related model where this instance is referenced.

classmethod one(**kwargs)[source]

Return exactly one record. Raises error if multiple results exist.

classmethod query()[source]

Return Query Builder related to this model

raw(query: str, params: list[Any] | tuple[Any, ...] | dict[str, Any])[source]

Raw SQL query

to_dict()[source]

Convert model instance to dictionary.

to_safe_instance() Self[source]

Wrap instance that complies with __hidden__.

update(_BaseModel__primary: str | object = <object object>, /, **kwargs)[source]

Update current data

classmethod upsert(key: str, **kwargs)[source]

Insert or update a record based on primary key.

classmethod where(**kwargs)[source]

Basic select operation

class luminadb.models.Foreign(column: str, target: str | Type[Model])[source]

Bases: Constraint

Foreign constraint

apply(type_: BuilderColumn)[source]

Apply this constraint to an column

on_delete(constraint: ConstraintEnum)[source]

On delete constraint

on_update(constraint: ConstraintEnum)[source]

On update constraint

resolve()[source]

Resolve if current target is a Model

property target

Target foreign constraint

class luminadb.models.Primary(column: str, auto: bool = False)[source]

Bases: Constraint

Primary constraint

Accepts optional auto flag to enable auto-increment on integer primary columns when using the BuilderColumn API.

apply(type_: BuilderColumn)[source]

Apply this constraint as primary. If auto was requested, enable auto increment on the builder column as well.

property auto: bool

Auto increment

class luminadb.models.QueryBuilder(model: Type[T])[source]

Bases: Generic[T]

Query builder for Model ORM

count() int[source]

Count how much data is within this operation

delete()[source]

Delete data based on the filter

fetch() list[T][source]

Fetch data from table

fetch_one() T | None[source]

Fetch one data from table

limit(value: int)[source]

Sets limit

offset(value: int)[source]

Sets offset

order_by(column: str, descending: bool = False)[source]

Order the query by a column

patch(**kwargs: Any)[source]

Update a data based on the filter according to passed keyword args

throw()[source]

Set when fetch() returns nothing, will raise an error

update(**kwargs: Any)

Update a data based on the filter according to passed keyword args

where(**kwargs: Any)[source]

Sets conditioning

class luminadb.models.Unique(column: str)[source]

Bases: Constraint

Unique constraint

apply(type_: BuilderColumn)[source]

Apply this constraint to an column

luminadb.models.hook(fn_or_name: Callable[[Model], None]) staticmethod[[Callable[[Model], None]], None][source]
luminadb.models.hook(fn_or_name: str)

Register a hook

luminadb.models.model(db: Database, type_checking: bool = False)[source]

Initiate Model API compatible classes. Requires target to be a dataclass, the app automatically injects dataclass if this isn’t a dataclass.

Use type_checking if you want automatic runtime type checker.

luminadb.models.validate(fn_or_column: FuncT) staticmethod[[FuncT], bool][source]
luminadb.models.validate(fn_or_column: str, reason: str | None = None)

Register a validator