Skip to content

Add database items

Use the method DatabaseManager().add_item() to add an object to the database like this:

from perseus.datamanager import DatabaseManager, Institute
db_manager = DatabaseManager()
new_institute = Institute(
name="Fachbereich Physik",
secondary_names=["Department of Physics"],
organization_id="67af0dd2616acdff502c8f88g",
)
oid = db_manager.add_item(new_institute)
if oid is not None:
...

DatabaseManager().add_item() will either return the inserted object id or None in case something went wrong.

If the object already exists in the database (meaning its object id is already used), DatabaseManager().add_item() will update the already existing database item. Have a look here: Update items