core: add helper for opening read-only database
This commit is contained in:
parent
0bcc5952c7
commit
4fc33a9ed2
2 changed files with 12 additions and 3 deletions
9
my/core/dataset.py
Normal file
9
my/core/dataset.py
Normal file
|
@ -0,0 +1,9 @@
|
|||
from pathlib import Path
|
||||
|
||||
# TODO wonder if also need to open without WAL.. test this on read-only directory/db file
|
||||
def connect_readonly(db: Path):
|
||||
import dataset # type: ignore
|
||||
# see https://github.com/pudo/dataset/issues/136#issuecomment-128693122
|
||||
import sqlite3
|
||||
creator = lambda: sqlite3.connect(f'file:{db}?mode=ro', uri=True)
|
||||
return dataset.connect('sqlite:///', engine_kwargs={'creator': creator})
|
Loading…
Add table
Add a link
Reference in a new issue