Skip to content
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

Database(memory_name="name") constructor argument #405

Closed
simonw opened this issue Feb 9, 2022 · 2 comments
Closed

Database(memory_name="name") constructor argument #405

simonw opened this issue Feb 9, 2022 · 2 comments
Labels
enhancement New feature or request python-library

Comments

@simonw
Copy link
Owner

simonw commented Feb 9, 2022

SQLite in-memory databases can be named, in which case multiple connections can be opened to a shared in-memory database running within the same process.

Datasette supports this - SQLite could support it too.

https://docs.datasette.io/en/0.60.2/internals.html#database-ds-path-none-is-mutable-false-is-memory-false-memory-name-none

@simonw simonw added enhancement New feature or request python-library labels Feb 9, 2022
@simonw
Copy link
Owner Author

simonw commented Feb 9, 2022

Writing tests against this is always a tiny bit fiddly since the created databases persist across the lifetime of the test run. Using randomly generated names helps.

@simonw
Copy link
Owner Author

simonw commented Feb 9, 2022

Datasette's implementation: https://github.com/simonw/datasette/blob/458f03ad3a454d271f47a643f4530bd8b60ddb76/datasette/database.py#L73-L79

        if self.memory_name:
            uri = "file:{}?mode=memory&cache=shared".format(self.memory_name)
            conn = sqlite3.connect(
                uri,
                uri=True,
                check_same_thread=False,
            )

@simonw simonw closed this as completed in 4bc06a2 Feb 16, 2022
simonw added a commit that referenced this issue Feb 16, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request python-library
Projects
None yet
Development

No branches or pull requests

1 participant