Replies: 2 comments 3 replies
-
|
@pavdwest I don't know if there is a better way to do it, but you can use a transaction. Something like this works in my case from piccolo.engine.sqlite import SQLiteEngine
from piccolo.table import Table
from piccolo.columns import Varchar, Integer
DB1 = SQLiteEngine(path="db/db1.sqlite")
DB2 = SQLiteEngine(path="db/db2.sqlite")
class Band(Table):
name = Varchar()
popularity = Integer()
async def main():
async with DB1.transaction():
# set first engine
Band._meta.db = DB1
await Band.create_table(if_not_exists=True).run()
# insert data to first databse
pythonistas = Band(name="Pythonistas", popularity=100)
await pythonistas.save().run()
# Read the data from the first database
pythonistas = await Band.select().run()
print(pythonistas)
async with DB2.transaction():
# set second engine
Band._meta.db = DB2
# insert data to second databse
await Band.create_table(if_not_exists=True).run()
rustaceans = Band(name="Rustaceans", popularity=90)
await rustaceans.save().run()
# Read the data from the second database
rustaceans = await Band.select().run()
print(rustaceans)
if __name__ == "__main__":
import asyncio
asyncio.run(main()) |
Beta Was this translation helpful? Give feedback.
1 reply
-
|
If it was Postgres, you can use the https://piccolo-orm.readthedocs.io/en/latest/piccolo/engines/postgres_engine.html#source But for SQLite, we don't really have anything like that. You could create your tables on demand with the relevant DB using Here are a couple of other discussions which might be helpful: |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
Reading through the docs and using the playground I really like Piccolo's design, however for most of my use cases I need a database per tenant. I'm sure I'm just missing something obvious but I can't figure out how to get started, e.g.
Some guidance would be greatly appreciated.
Beta Was this translation helpful? Give feedback.
All reactions