Units
albert.collections.units.UnitCollection
Bases: BaseCollection
UnitCollection is a collection class for managing Unit entities in the Albert platform.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
session
|
AlbertSession
|
The Albert session instance. |
required |
Methods:
Name | Description |
---|---|
create |
Creates a new unit entity. |
get_or_create |
Retrieves a Unit or creates it if it does not exist. |
get_by_id |
Retrieves a unit by its ID. |
get_by_ids |
Retrieves a set of units by their IDs |
update |
Updates a unit entity by its ID. |
delete |
Deletes a unit by its ID. |
get_all |
Get all unit entities with optional filters. |
get_by_name |
Retrieves a unit by its name. |
exists |
Checks if a unit exists by its name. |
Attributes:
Name | Type | Description |
---|---|---|
base_path |
|
Source code in src/albert/collections/units.py
create
Creates a new unit entity.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
unit
|
Unit
|
The unit object to create. |
required |
Returns:
Type | Description |
---|---|
Unit
|
The created Unit object. |
Source code in src/albert/collections/units.py
get_or_create
Retrieves a Unit or creates it if it does not exist.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
unit
|
Unit
|
The unit object to find or create. |
required |
Returns:
Type | Description |
---|---|
Unit
|
The existing or newly created Unit object. |
Source code in src/albert/collections/units.py
get_by_id
Retrieves a unit by its ID.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
id
|
str
|
The ID of the unit to retrieve. |
required |
Returns:
Type | Description |
---|---|
Unit
|
The Unit object if found. |
Source code in src/albert/collections/units.py
get_by_ids
Retrieves a set of units by their IDs
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ids
|
list[str]
|
The IDs of the units to retrieve. |
required |
Returns:
Type | Description |
---|---|
list[Unit]
|
The Unit entities |
Source code in src/albert/collections/units.py
update
Updates a unit entity by its ID.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
unit
|
Unit
|
The updated Unit object. |
required |
Returns:
Type | Description |
---|---|
Unit
|
The updated Unit |
Source code in src/albert/collections/units.py
delete
delete(*, id: UnitId) -> None
Deletes a unit by its ID.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
id
|
str
|
The ID of the unit to delete. |
required |
Returns:
Type | Description |
---|---|
None
|
|
Source code in src/albert/collections/units.py
get_all
get_all(
*,
name: str | list[str] | None = None,
category: UnitCategory | None = None,
order_by: OrderBy = DESCENDING,
exact_match: bool = False,
verified: bool | None = None,
start_key: str | None = None,
max_items: int | None = None,
) -> Iterator[Unit]
Get all unit entities with optional filters.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str | list[str] | None
|
The name(s) of the unit(s) to filter by. |
None
|
category
|
UnitCategory | None
|
The category of the unit to filter by. |
None
|
order_by
|
OrderBy
|
The order by which to sort the results, by default OrderBy.DESCENDING. |
DESCENDING
|
exact_match
|
bool
|
Whether to match the name exactly, by default False. |
False
|
verified
|
bool | None
|
Whether the unit is verified, by default None. |
None
|
start_key
|
str | None
|
The primary key of the first item to evaluate for pagination. |
None
|
max_items
|
int
|
Maximum number of items to return in total. If None, fetches all available items. |
None
|
Returns:
Type | Description |
---|---|
Iterator[Unit]
|
An iterator of Unit entities. |
Source code in src/albert/collections/units.py
get_by_name
Retrieves a unit by its name.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
The name of the unit to retrieve. |
required |
exact_match
|
bool
|
Whether to match the name exactly, by default False. |
False
|
Returns:
Type | Description |
---|---|
Optional[Unit]
|
The Unit object if found, None otherwise. |
Source code in src/albert/collections/units.py
exists
Checks if a unit exists by its name.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
The name of the unit to check. |
required |
exact_match
|
bool
|
Whether to match the name exactly, by default True. |
True
|
Returns:
Type | Description |
---|---|
bool
|
True if the unit exists, False otherwise. |