bouquin 0.1.5__py3-none-any.whl → 0.1.9__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of bouquin might be problematic. Click here for more details.

bouquin/db.py CHANGED
@@ -133,7 +133,7 @@ class DBManager:
133
133
  raise RuntimeError("Database is not connected")
134
134
  cur = self.conn.cursor()
135
135
  # Change the encryption key of the currently open database
136
- cur.execute(f"PRAGMA rekey = '{new_key}';")
136
+ cur.execute(f"PRAGMA rekey = '{new_key}';").fetchone()
137
137
  self.conn.commit()
138
138
 
139
139
  # Close and reopen with the new key to verify and restore PRAGMAs
@@ -409,7 +409,7 @@ class DBManager:
409
409
  f.write(separator)
410
410
 
411
411
  def export_html(
412
- self, entries: Sequence[Entry], file_path: str, title: str = "Entries export"
412
+ self, entries: Sequence[Entry], file_path: str, title: str = "Bouquin export"
413
413
  ) -> None:
414
414
  parts = [
415
415
  "<!doctype html>",
@@ -430,6 +430,25 @@ class DBManager:
430
430
  with open(file_path, "w", encoding="utf-8") as f:
431
431
  f.write("\n".join(parts))
432
432
 
433
+ def export_sql(self, file_path: str) -> None:
434
+ """
435
+ Exports the encrypted database as plaintext SQL.
436
+ """
437
+ cur = self.conn.cursor()
438
+ cur.execute(f"ATTACH DATABASE '{file_path}' AS plaintext KEY '';")
439
+ cur.execute("SELECT sqlcipher_export('plaintext')")
440
+ cur.execute("DETACH DATABASE plaintext")
441
+
442
+ def export_sqlcipher(self, file_path: str) -> None:
443
+ """
444
+ Exports the encrypted database as an encrypted database with the same key.
445
+ Intended for Bouquin-compatible backups.
446
+ """
447
+ cur = self.conn.cursor()
448
+ cur.execute(f"ATTACH DATABASE '{file_path}' AS backup KEY '{self.cfg.key}'")
449
+ cur.execute("SELECT sqlcipher_export('backup')")
450
+ cur.execute("DETACH DATABASE backup")
451
+
433
452
  def export_by_extension(self, file_path: str) -> None:
434
453
  entries = self.get_all_entries()
435
454
  ext = os.path.splitext(file_path)[1].lower()
@@ -445,6 +464,16 @@ class DBManager:
445
464
  else:
446
465
  raise ValueError(f"Unsupported extension: {ext}")
447
466
 
467
+ def compact(self) -> None:
468
+ """
469
+ Runs VACUUM on the db.
470
+ """
471
+ try:
472
+ cur = self.conn.cursor()
473
+ cur.execute("VACUUM")
474
+ except Exception as e:
475
+ print(f"Error: {e}")
476
+
448
477
  def close(self) -> None:
449
478
  if self.conn is not None:
450
479
  self.conn.close()