Tools for enabling and disabling WAL, closes #132

This commit is contained in:
Simon Willison 2020-08-10 11:59:21 -07:00
commit 2d2d724e32
5 changed files with 115 additions and 0 deletions

View file

@ -170,6 +170,18 @@ class Database:
).fetchall()
]
@property
def journal_mode(self):
return self.conn.execute("PRAGMA journal_mode;").fetchone()[0]
def enable_wal(self):
if self.journal_mode != "wal":
self.conn.execute("PRAGMA journal_mode=wal;")
def disable_wal(self):
if self.journal_mode != "delete":
self.conn.execute("PRAGMA journal_mode=delete;")
def execute_returning_dicts(self, sql, params=None):
cursor = self.conn.execute(sql, params or tuple())
keys = [d[0] for d in cursor.description]