Insert, Update, Query, etc. with Plugin Model

How does one “interact” with the model in Indico?

For example, I have an Invoices table, and I want to query all Invoices, add an Invoice, delete an Invoice, etc., but can’t find any reference on how to use the model :frowning:


You might want to have a look at existing code and if necessary the sqlalchemy docs (I think the flask-sqlalchemy docs also contain a simple example showing how the basics work). :wink:

Only relevant difference in Indico’s code is that the RH base class automatically commits at the end, so you do not need to do that manually.

Will do, but which object/class do I use to perform the add/update/delete operations on? SQLAlchemy usually uses a session object.

While searching the code for session will yield too many false positives, searching for db.session (which I think is what the flask-sqlalchemy examples use as well) will give you exactly what you need! The import you are looking for is from indico.core.db import db.

FYI: For updates you do not need to use the SA session yourself! Just query the object (e.g. Invoice.get(ID) or Invoice.query.fiter(...).first()) and update attributes on it.

I am having some issues generating the migration :frowning: I’ll post my plight in a separate discussion.