summaryrefslogtreecommitdiff
path: root/db/db_manager.py
diff options
context:
space:
mode:
authorMichaël Ball <michael.ball@gmail.com>2015-08-03 06:52:00 +0100
committerMichaël Ball <michael.ball@gmail.com>2015-08-03 06:52:00 +0100
commit122ec1c9b283776b8f1fea5559d4317bdba5b977 (patch)
tree874f4a1e2644f165f08295e56e150be9e3cafe97 /db/db_manager.py
parent35a21c4d12ae85aed699d4117ebbdb4c510ad40f (diff)
Initially use memory based db, then dump on exit
Diffstat (limited to 'db/db_manager.py')
-rw-r--r--db/db_manager.py19
1 files changed, 14 insertions, 5 deletions
diff --git a/db/db_manager.py b/db/db_manager.py
index eb813ec..ca47ae4 100644
--- a/db/db_manager.py
+++ b/db/db_manager.py
@@ -11,25 +11,34 @@ class DbManager:
def __init__(self):
new_db = False
+ cache_size_kb = 9766
if not os.path.isfile(self.config["DEFAULT"]["database"]):
new_db = True
- self.conn = apsw.Connection(self.config["DEFAULT"]["database"],
- apsw.SQLITE_OPEN_READWRITE |
- apsw.SQLITE_OPEN_CREATE)
-
if new_db:
+ self.conn = apsw.Connection(":memory:")
self.create_tables()
else:
+ self.conn = apsw.Connection(self.config["DEFAULT"]["database"])
library_info = os.stat(self.config["DEFAULT"]["database"])
cache_size_kb = round((library_info.st_size * 1.2) / 1024)
cursor = self.conn.cursor()
# Setting pragma with ? placeholder errors out
- cursor.execute("pragma cache_size=%s" % cache_size_kb)
+ cursor.execute("pragma cache_size=-%s" % cache_size_kb)
cursor.close()
+ def __del__(self):
+ if not os.path.isfile(self.config["DEFAULT"]["database"]):
+ tempconn = apsw.Connection(self.config["DEFAULT"]["database"],
+ apsw.SQLITE_OPEN_READWRITE |
+ apsw.SQLITE_OPEN_CREATE)
+
+ with tempconn.backup("main",
+ self.conn, "main") as backup:
+ backup.step()
+
def __str__(self):
return repr(self)