Files
Lector/database.py
2017-11-06 07:41:07 +05:30

28 lines
878 B
Python

#!/usr/bin/env python3
import sqlite3
import os
class DatabaseFunctions:
def __init__(self, location_prefix):
os.makedirs(location_prefix, exist_ok=True)
self.database_path = os.path.join(
location_prefix, 'Lector.db')
self.database = sqlite3.connect(self.database_path)
if not os.path.exists(self.database_path):
self.create_database()
def create_database(self):
self.database.execute(
"CREATE TABLE books \
(id INTEGER PRIMARY KEY, Name TEXT, Path TEXT, ISBN TEXT, CoverImage BLOB)")
self.database.execute(
"CREATE TABLE cache \
(id INTEGER PRIMARY KEY, Name TEXT, Path TEXT, CachedDict BLOB)")
# It's assumed that any cached books will be pickled and put into the
# database at time of closing
self.database.commit()