| 163 | |
| 164 | |
| 165 | def connect_db(db_file: str, set_journal_mode: bool) -> sqlite3.Connection: |
| 166 | import sqlite3.dbapi2 |
| 167 | |
| 168 | db = sqlite3.dbapi2.connect(db_file, check_same_thread=False) |
| 169 | # This is a bit unfortunate (as we may get corrupt cache after e.g. Ctrl + C), |
| 170 | # but without this flag, commits are *very* slow, especially when using HDDs, |
| 171 | # see https://www.sqlite.org/faq.html#q19 for details. |
| 172 | db.execute("PRAGMA synchronous=OFF") |
| 173 | if set_journal_mode: |
| 174 | db.execute("PRAGMA journal_mode=WAL") |
| 175 | db.executescript(SCHEMA) |
| 176 | return db |
| 177 | |
| 178 | |
| 179 | class SqliteMetadataStore(MetadataStore): |