'SQLite3 with flask in-memory mode

I am using sqlite3 in a flask app (actually connexion). I would like to stay in-memory but keep the db between the requests to the server. So it should be destroyed after server is killed

  • When I use sqlite3.connect(':memory:') the db is destroyed after each response
  • So I followed this approach In memory SQLite3 shared database python and run sqlite3.connect('file::memory:?cache=shared&mode=memory', uri=True). But then, a file called file::memory:?cache=shared&mode=memory appears in the app root and does not disappear when I kill the server. When I start the server again, the db-init routine which creates the tables fails, because the tables are already created.

I tried this out on linux and Mac. Both have same behaviour. It seems like the db is saved to file instead of being mapped to memory. My python version is 3.9 and sqlite3.sqlite_version_info is (3, 37, 0)



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source