Working with multiple databases
Pony can work with several databases simultaneously. In the example below we use PostgreSQL for storing user information and MySQL for storing information about addresses:
db1 = Database()
class User(db1.Entity):
...
db1.bind('postgres', ...)
db2 = Database()
class Address(db2.Entity):
...
db2.bind('mysql', ...)
@db_session
def do_something(user_id, address_id):
u = User[user_id]
a = Address[address_id]
...
On exiting from the do_something()
function Pony will perform commit()
or rollback()
to both databases. If you need to commit to one database before exiting from the function you can use db1.commit()
or db2.commit()
methods.