Skip to content

Commit 4973115

Browse files
committed
fix comment_link column matching insert
1 parent 8cc2e52 commit 4973115

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

app/src/base.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,12 @@ def make_request(self, url: str) -> requests.Response:
6161
@staticmethod
6262
def insert_into(table: str, dictionary: RedditComment | RedditPost | dict):
6363
"""build query"""
64-
keys: str = ":" + ", :".join(dictionary)
65-
to_execute: str = f"INSERT INTO {table} VALUES ({keys})"
64+
keys = ", ".join(dictionary.keys())
65+
placeholders = ", ".join([f":{k}" for k in dictionary.keys()])
66+
to_execute = f"INSERT INTO {table} ({keys}) VALUES ({placeholders})"
6667

6768
db_handler = Database()
68-
db_handler.execute(to_execute, values=list(dictionary.values()))
69+
db_handler.execute(to_execute, dict(dictionary))
6970
db_handler.finish()
7071

7172
@staticmethod
@@ -241,10 +242,8 @@ def add_column_if_not_exists(self, table_name: str, column_name: str, column_typ
241242
)
242243
else:
243244
self.cursor.execute(f"ALTER TABLE {table_name} ADD COLUMN {column_name} {column_type};")
244-
else:
245-
print(f"[db] column '{column_name}' already exists in table '{table_name}', skipping.")
246245

247-
def execute(self, to_execute: str, values: list | bool = False) -> None:
246+
def execute(self, to_execute: str, values: list | dict | bool = False) -> None:
248247
"""execute on the cursor"""
249248
if values:
250249
self.cursor.execute(to_execute, values)

0 commit comments

Comments
 (0)