Skip to content

Commit

Permalink
autodb
Browse files Browse the repository at this point in the history
  • Loading branch information
mtill committed Sep 3, 2018
1 parent 54b356c commit de658c0
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 30 deletions.
31 changes: 1 addition & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,35 +13,6 @@ web based HBCI banking software
## how to poll your bank account for updates
have a look at the hbciMail/config_mail.py example and the MailWebsiteChanges tool (https://github.com/mtill/MailWebsiteChanges)

# database model
~~~~
CREATE TABLE transactions(
account TEXT NOT NULL,
timestamp INTEGER NOT NULL,
amount REAL NOT NULL,
currency TEXT NOT NULL,
name TEXT NOT NULL,
description TEXT NOT NULL,
category TEXT NULL,
note TEXT NULL,
id INTEGER PRIMARY KEY AUTOINCREMENT);
CREATE INDEX account ON transactions(account);
CREATE INDEX timestamp ON transactions(timestamp ASC);
CREATE TABLE categories(
pattern TEXT NOT NULL,
field TEXT NOT NULL,
category TEXT NOT NULL
);
CREATE INDEX category ON categories(category ASC);
~~~~

# database backup
~~~~
## how to backup the transaction database
sqlite3 my_database.sqlite ".backup backup_file.sqlite"
OR: sqlite3 my_database .dump > my_database.back
~~~~

22 changes: 22 additions & 0 deletions dbmodel.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
CREATE TABLE transactions(
account TEXT NOT NULL,
timestamp INTEGER NOT NULL,
amount REAL NOT NULL,
currency TEXT NOT NULL,
name TEXT NOT NULL,
description TEXT NOT NULL,
category TEXT NULL,
note TEXT NULL,
id INTEGER PRIMARY KEY AUTOINCREMENT);

CREATE INDEX account ON transactions(account);
CREATE INDEX timestamp ON transactions(timestamp ASC);


CREATE TABLE categories(
pattern TEXT NOT NULL,
field TEXT NOT NULL,
category TEXT NOT NULL
);

CREATE INDEX category ON categories(category ASC);
7 changes: 7 additions & 0 deletions kontomodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,17 @@

class KontoModel:
def __init__(self, sqlitefile):
isExistingDB = os.path.exists(sqlitefile)

self.conn = sqlite3.connect(sqlitefile)
self.conn.row_factory = sqlite3.Row
self.cursor = self.conn.cursor()

if not isExistingDB:
with open('dbmodel.sql', 'r') as thefile:
self.conn.executescript(thefile.read())
print("initiated new database")

def close(self):
self.conn.close()

Expand Down

0 comments on commit de658c0

Please sign in to comment.