Search code examples
multithreadingsqlitepeeweein-memory-database

Peewee Sqlite share in memory database


Reading this post I learnt that is possible to have shared in-memory database across thread:

https://stackoverflow.com/a/24708173/7754093

Using sqlite python package I could do this:

sqlite3.connect('file:foobar_database?mode=memory&cache=shared', uri=True)

How can this be done in Peewee? I can't find any documentation that describes it.


Solution

  • If your sqlite3 module can successfully connect to a shared in-memory database, then the following will work:

    from peewee import *
    sqlite_db = SqliteDatabase('file:foobar_database?mode=memory&cache=shared')