From cafec130690db361c7348febdde8d3892b715672 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?dni=20=E2=9A=A1?= Date: Thu, 26 Sep 2024 13:41:12 +0200 Subject: [PATCH] remove where from argument --- lnbits/db.py | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/lnbits/db.py b/lnbits/db.py index 878108106..fe20b6c8b 100644 --- a/lnbits/db.py +++ b/lnbits/db.py @@ -175,9 +175,7 @@ class Connection(Compat): return dict_to_model(row, model) return row - async def update( - self, table_name: str, model: BaseModel, where: str = "WHERE id = :id" - ): + async def update(self, table_name: str, model: BaseModel, where: str = "id = :id"): await self.conn.execute( text(update_query(table_name, model, where)), model_to_dict(model) ) @@ -343,7 +341,7 @@ class Database(Compat): await conn.insert(table_name, model) async def update( - self, table_name: str, model: BaseModel, where: str = "WHERE id = :id" + self, table_name: str, model: BaseModel, where: str = "id = :id" ) -> None: async with self.connect() as conn: await conn.update(table_name, model, where) @@ -571,21 +569,19 @@ def insert_query(table_name: str, model: BaseModel) -> str: return f"INSERT INTO {table_name} ({fields}) VALUES ({values})" -def update_query( - table_name: str, model: BaseModel, where: str = "WHERE id = :id" -) -> str: +def update_query(table_name: str, model: BaseModel, where: str = "id = :id") -> str: """ Generate an update query with placeholders for a given table and model :param table_name: Name of the table :param model: Pydantic model - :param where: Where string, default to `WHERE id = :id` + :param where: Where string, default to `id = :id` """ fields = [] for field in model.dict().keys(): placeholder = get_placeholder(model, field) fields.append(f"{field} = {placeholder}") query = ", ".join(fields) - return f"UPDATE {table_name} SET {query} {where}" + return f"UPDATE {table_name} SET {query} WHERE {where}" def model_to_dict(model: BaseModel) -> dict: