Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions sqlite_utils/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -1897,6 +1897,7 @@ def index_foreign_keys(self) -> None:

def vacuum(self) -> None:
"Run a SQLite ``VACUUM`` against the database."
self.commit()
self.execute("VACUUM;")

def analyze(self, name: Optional[str] = None) -> None:
Expand Down
11 changes: 11 additions & 0 deletions tests/test_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -1170,6 +1170,17 @@ def test_vacuum(fresh_db):
fresh_db.vacuum()


def test_vacuum_commits_open_transaction(fresh_db):
fresh_db["data"].insert({"foo": "foo"})
fresh_db.begin()
fresh_db.execute("insert into data (foo) values ('bar')")

fresh_db.vacuum()

assert not fresh_db.conn.in_transaction
assert [row["foo"] for row in fresh_db["data"].rows] == ["foo", "bar"]


def test_works_with_pathlib_path(tmpdir):
path = pathlib.Path(tmpdir / "test.db")
db = Database(path)
Expand Down
Loading