Core Models¶
Model
¶
Bases: BaseModel
Provide the base class for all Ferro models
Inheriting from this class registers schema metadata with the Rust core and exposes high-performance CRUD and query entrypoints.
Examples:
Attributes¶
model_config = ConfigDict(from_attributes=True, use_attribute_docstrings=True, arbitrary_types_allowed=True)
class-attribute
instance-attribute
¶
Functions¶
__init__(**data)
¶
save()
async
¶
delete()
async
¶
all()
async
classmethod
¶
get(pk)
async
classmethod
¶
Fetch one record by primary key value
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pk
|
Any
|
Primary key value to fetch a single record. |
required |
Returns:
| Type | Description |
|---|---|
Self | None
|
The matching model instance, or None when no record exists. |
Examples:
refresh()
async
¶
where(node)
classmethod
¶
Start a fluent query with an initial condition
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node
|
QueryNode
|
Query predicate node to apply first. |
required |
Returns:
| Type | Description |
|---|---|
Query[Self]
|
A query object scoped to this model class. |
Examples:
select()
classmethod
¶
Start an empty fluent query for this model class
Returns:
| Type | Description |
|---|---|
Query[Self]
|
A query object scoped to this model class. |
Examples:
create(**fields)
async
classmethod
¶
bulk_create(instances)
async
classmethod
¶
Persist multiple instances in a single bulk operation
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
instances
|
list[Self]
|
Model instances to persist. |
required |
Returns:
| Type | Description |
|---|---|
int
|
The number of records inserted. |
Examples:
get_or_create(defaults=None, **fields)
async
classmethod
¶
Fetch a record by filters or create one when missing
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
defaults
|
dict[str, Any] | None
|
Values applied only when creating a new record. |
None
|
**fields
|
Exact-match filters used for lookup. |
{}
|
Returns:
| Type | Description |
|---|---|
tuple[Self, bool]
|
A tuple of |
Examples:
update_or_create(defaults=None, **fields)
async
classmethod
¶
Update a matched record or create one when missing
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
defaults
|
dict[str, Any] | None
|
Values applied on update or create paths. |
None
|
**fields
|
Exact-match filters used for lookup. |
{}
|
Returns:
| Type | Description |
|---|---|
tuple[Self, bool]
|
A tuple of |
Examples: