· 6 years ago · Mar 08, 2019, 10:42 AM
1import sqlite3
2
3
4class DbHandler:
5
6 def __init__(self, dbfile="database.db"):
7 self.dbfile = dbfile
8 self.connection = sqlite3.connect(dbfile)
9
10 def setup(self):
11 statement = "CREATE TABLE IF NOT EXISTS breach (email text UNIQUE,username text,domain text,country text)"
12 self.connection.execute(statement)
13 self.connection.commit()
14
15 def get_allrecords(self):
16 statement = "SELECT * FROM breach"
17 return [x for x in self.connection.execute(statement)]
18
19 def add_item(self, email, username, domain, country):
20 statement = "INSERT OR IGNORE INTO breach (email, username, domain, country) VALUES (?, ?, ?, ?)"
21 args = (email, username, domain, country)
22 self.connection.execute(statement, args)
23 self.connection.commit()