I have two apps, one of which shares a table from the other. This works fine in the anvil.works editor, but I’m trying to figure out if it’s possible to replicate the same setup locally on the open source runtime.
I am running a single postgres instance which is shared between the apps, but each app has its own database per the docs, so I can’t see how they will be able to share tables…
What I’ve tried and what’s not working:
Adding the table (via “add existing table”) in the web editor works fine, but when I clone the app locally and run it this just creates a new table, rather than a link to the other app.
In any case I can’t see anything in anvil.yaml that would even tell the app that it’s a shared table, as opposed to a local one, so perhaps this feature just isn’t available for self-hosted apps?
I also tried pointing both apps to the same postgres database, but of course they have conflicting schemas so this isn’t workable - doing this just ends up with each app’s initial migration step deleting the tables it doesn’t expect to see.
I’m afraid that each App Server instance supports a single Anvil app, so sharing tables is not currently supported. I’d suggest one of two ways forward:
Combine your code into a single app (perhaps via dependencies), so that they can be hosted together with the App Server
If you’re keeping them separate, to access data from other App Server’s database, I would suggest connecting via psycopg2 and using SQL access.
Thanks for the speedy reply @meredydd! I had suspected that might be the case.
The second app (from which the table is shared) actually contains (almost) no code, because my idea was to use this as a central datastore for some shared information which will need to be visible to a couple of different apps in the near future. So for now it’s really simple to combine them.
Looking ahead I might look into using psycopg2, although I’m not too excited about messing with SQL directly! I might consider publishing the shared info via an API instead. In any case, it’s good to know what the options are, thanks.
If you are just looking for a place to store data that can be shared across apps, there are other, more simple solutions than direct SQL access, may are even installable with pip or anaconda.
You might be more interested in noSQL style data stores, or something like Redis or MongoDB.
The simplest explanation I can come up with for what a noSQL database is, is it’s like a giant list of key/value pairs (like a dictionary) that is optimized for search.