DB
eunomia.db.crud
create_entity(entity, db)
Create a new entity in the database.
This function creates a new entity record and its associated attributes in the database.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
entity
|
EntityCreate
|
Pydantic model containing the entity data to be created. |
required |
db
|
Session
|
SQLAlchemy database session. |
required |
Returns:
Type | Description |
---|---|
Entity
|
The created entity as a SQLAlchemy model. |
Source code in src/eunomia/db/crud.py
delete_entity(db_entity, db)
Delete an entity from the database.
This function deletes an entity record and its associated attributes from the database.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
db_entity
|
Entity
|
The entity to delete. |
required |
db
|
Session
|
SQLAlchemy database session. |
required |
Source code in src/eunomia/db/crud.py
delete_entity_attributes(db_entity, db)
Delete all attributes of an entity.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
db_entity
|
Entity
|
The entity to delete attributes from. |
required |
db
|
Session
|
SQLAlchemy database session. |
required |
Source code in src/eunomia/db/crud.py
get_attribute(uri, key, db)
Retrieve an attribute from the database by its key and entity uri.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
uri
|
str
|
The uri of the entity. |
required |
key
|
str
|
The key of the attribute. |
required |
db
|
Session
|
SQLAlchemy database session. |
required |
Returns:
Type | Description |
---|---|
Attribute | None
|
The attribute as a SQLAlchemy model or None if it does not exist. |
Source code in src/eunomia/db/crud.py
get_entity(uri, db)
Retrieve an entity from the database by its unique identifier.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
uri
|
str
|
Unique identifier of the entity. |
required |
db
|
Session
|
SQLAlchemy database session. |
required |
Returns:
Type | Description |
---|---|
Entity | None
|
The entity as a SQLAlchemy model or None if it does not exist. |
Source code in src/eunomia/db/crud.py
get_entity_attributes(uri, db)
Retrieve attributes for a resource by its unique identifier.
This function retrieves all attributes associated with a specific resource and returns it as a dictionary. If no entity with the specified uri is found, an empty dictionary is returned.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
uri
|
str
|
Unique identifier of the entity. |
required |
db
|
Session
|
SQLAlchemy database session. |
required |
Returns:
Type | Description |
---|---|
dict
|
Dictionary containing all attributes key-value pairs for the entity. |
Source code in src/eunomia/db/crud.py
update_entity_attributes(db_entity, attributes, db)
Update the attributes of an existing entity.
This function updates the attributes of an existing entity. If an attribute does not exist, it is created. If an attribute exists, it is updated.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
db_entity
|
Entity
|
The entity to update. |
required |
attributes
|
list[Attribute]
|
The attributes to update. |
required |
db
|
Session
|
SQLAlchemy database session. |
required |
Returns:
Type | Description |
---|---|
Entity
|
The updated entity as a SQLAlchemy model. |