adding separate database class

This commit is contained in:
2019-06-27 12:37:23 +02:00
parent fa8a5e55f8
commit c25844a335
3 changed files with 40 additions and 14 deletions

23
src/database.py Normal file
View File

@@ -0,0 +1,23 @@
import sqlite3
import os
class Database:
def __init__(self, args):
filename = ":memory:" if args.db is None else args.db
if not args.keep_db and os.path.exists(filename):
os.remove(filename)
self.new = not os.path.exists(filename)
self.db = sqlite3.connect(filename)
def execute(self, *args, **kwargs):
return self.db.execute(*args, **kwargs)
def init(self, *args, **kwargs):
# same as execute, only skipped if not a new database file
if self.new:
return self.execute(*args, **kwargs)
def commit(self):
self.db.commit()