From feb929c6f82e984ee6afe576d40030a005b5a6ea Mon Sep 17 00:00:00 2001 From: oliverhnat Date: Mon, 6 Jan 2025 20:32:56 +0100 Subject: [PATCH] feat(db): add db layer --- db.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 db.py diff --git a/db.py b/db.py new file mode 100644 index 0000000..6448216 --- /dev/null +++ b/db.py @@ -0,0 +1,24 @@ +import sqlite3 + + +class DB: + def __init__(self, db_path, schema_path="schema.sql", seed_path="seed.sql"): + self.con = sqlite3.connect(db_path) + self.cur = self.con.cursor() + with open(schema_path) as f: + self.cur.executescript(f.read()) + + with open(seed_path) as f: + self.cur.executescript(f.read()) + + def __del__(self): + self.con.close() + + def query(self, query, params=[]): + self.cur.execute(query, params) + return self.cur.fetchall() + + def insertDisclosures(self, disclosures): + sql = "INSERT INTO disclosures (member_id, filing_year, filing, link) VALUES (?, ?, ?, ?)" + self.cur.executemany(sql, disclosures) + self.con.commit()