Skip to content

How to use ormar using sqlite with mmap? #237

Answered by collerek
jinserk asked this question in Q&A
Discussion options

You must be logged in to vote

This one gonna be more tricky.
Ormar already modifies sqlite settings but only to enforce foreign key usage.

To not to it manually (call PRAGMA mmap_size=268435456; before each query) you need to modify the factory for encode/databases connection pool.

This is (out of context) more or less what ormar does for you

class Connection(sqlite3.Connection):
    def __init__(self, *args: Any, **kwargs: Any) -> None:  # pragma: no cover
        super().__init__(*args, **kwargs)
        self.execute("PRAGMA foreign_keys=1;")

database = databases.Database(DATABASE_URL)
backend = database._backend
backend._options["factory"] = Connection
old_pool = backend._pool
backend._pool = old_pool.__class__(ba…

Replies: 1 comment 6 replies

Comment options

You must be logged in to vote
6 replies
@jinserk
Comment options

@collerek
Comment options

@jinserk
Comment options

@collerek
Comment options

@jinserk
Comment options

Answer selected by collerek
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants