flask-sqlalchemy
flask-sqlalchemy copied to clipboard
Sqlite: In-Memory Databases with Shared cache not working
Hello, I'm loading a sqlite3 database, which is stored on disk to memory via:
source = sqlite3.connect(os.path.abspath('./db-auth.sqlite'))
dest = sqlite3.connect("file:{}?mode=memory&cache=shared".format(sqlite_shared_name), uri=True)
source.backup(dest)
Regarding to this SO answer ( https://stackoverflow.com/a/65429612 ) I want to "bind" this in-memory database to flask_SQLAlchemy. But I don't have a create_engine(). I have a Config class which is used via:
db = SQLAlchemy()
app.config.from_object(config_class)
db.app = app
db.init_app(app)
There he tooks the Database URI from SQLALCHEMY_DATABASE_URI, which is:
os.environ.get('DATABASE_URL') or "sqlite:///file:{}?mode=memory&cache=shared&uri=true".format(sqlite_shared_name)
But this won't work and I can't query data.
Environment:
- Python version: 3.8.10
- Flask-SQLAlchemy version: 2.5.1
- SQLAlchemy version: 1.3.12