-
-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Datasette plugin that copies file into memory on startup #1
Comments
Would use this: https://www.sqlite.org/lang_vacuum.html#vacuuminto I think like this:
|
|
Clue in https://stackoverflow.com/a/67637492/6083
Not sure what "ping" means there - but it wasn't working for me when I tried with an empty database. |
This also failed because you can't from datasette import hookimpl
@hookimpl
def startup(datasette):
async def inner():
for db in datasette.databases.values():
if db.path:
memory_name = "{}_memory".format(db.name)
memory_db = datasette.add_memory_database(memory_name)
def vacuum_into(conn):
conn.execute("ATTACH DATABASE ? AS _copy_from", [db.path])
conn.execute("VACUUM _copy_from INTO main")
await memory_db.execute_write_fn(vacuum_into)
return inner |
This totally works! from datasette import hookimpl
@hookimpl
def startup(datasette):
async def inner():
for db in datasette.databases.values():
if db.path:
memory_name = "{}_memory".format(db.name)
memory_db = datasette.add_memory_database(memory_name)
# Ensure the in-memory database is initalized
await memory_db.execute("select 1 + 1")
def vacuum_into(conn):
conn.execute(
"VACUUM INTO ?",
["file:{}?mode=memory&cache=shared".format(memory_name)],
)
await db.execute_write_fn(vacuum_into)
return inner |
Related:
Idea from SQLite forum discussion: https://sqlite.org/forum/forumpost/652a9402eb5ea505
Based on the observation that SQLite is often I/O bound.
The text was updated successfully, but these errors were encountered: