mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-07-23 09:24:31 +02:00
Tools for enabling and disabling WAL, closes #132
This commit is contained in:
parent
957f8c9b4c
commit
2d2d724e32
5 changed files with 115 additions and 0 deletions
|
|
@ -377,6 +377,32 @@ def disable_fts(path, table):
|
|||
db[table].disable_fts()
|
||||
|
||||
|
||||
@cli.command(name="enable-wal")
|
||||
@click.argument(
|
||||
"path",
|
||||
nargs=-1,
|
||||
type=click.Path(exists=True, file_okay=True, dir_okay=False, allow_dash=False),
|
||||
required=True,
|
||||
)
|
||||
def enable_wal(path):
|
||||
"Enable WAL for database files"
|
||||
for path_ in path:
|
||||
sqlite_utils.Database(path_).enable_wal()
|
||||
|
||||
|
||||
@cli.command(name="disable-wal")
|
||||
@click.argument(
|
||||
"path",
|
||||
nargs=-1,
|
||||
type=click.Path(exists=True, file_okay=True, dir_okay=False, allow_dash=False),
|
||||
required=True,
|
||||
)
|
||||
def disable_wal(path):
|
||||
"Disable WAL for database files"
|
||||
for path_ in path:
|
||||
sqlite_utils.Database(path_).disable_wal()
|
||||
|
||||
|
||||
def insert_upsert_options(fn):
|
||||
for decorator in reversed(
|
||||
(
|
||||
|
|
|
|||
|
|
@ -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]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue