erase data under classname #1739
Replies: 2 comments 2 replies
-
|
So, you want to remove a class, its objects, parameters and parameter values from a Spine database, am I right? In that case, the following script might be a good starting point: from spinedb_api import DatabaseMapping
class_name = "class_to_remove"
class_type = "object_class" # or "relationship_class"
url = "sqlite:///my_database.sqlite"
db_map = DatabaseMapping(url)
def class_id_for_name(name):
return db_map.query(db_map.entity_class_sq).filter(db_map.entity_class_sq.c.name == name).first().id
try:
id_to_remove = class_id_for_name(class_name)
db_map.cascade_remove_items(**{class_type: {id_to_remove}})
db_map.commit_session(f"Removed {class_name}")
finally:
db_map.connection.close()Since data is removed in a cascade, removing the class will also remove all its entities (objects/relationships), parameters and parameter values. Note, that in case you remove an object class, all relationship classes (and their associated data) that have the said object class will get removed as well. |
Beta Was this translation helpful? Give feedback.
-
|
Hello, For other cases, can I also erase some objects according to the parameter_value? For example, erase this bid is status is not "Accepted". |
Beta Was this translation helpful? Give feedback.

Uh oh!
There was an error while loading. Please reload this page.
-
Hello,
To make simulations faster, I would like to delete a classname and all the data from a python script, once that data is no longer in use.
Could you please give me a quick example of how to do that?
Thank you very much!
Beta Was this translation helpful? Give feedback.
All reactions