Add filtering option

This commit is contained in:
Andrew 2023-03-12 01:34:54 +07:00
parent c37c93d0d4
commit e25a5aae20

View file

@ -101,7 +101,6 @@ class DBConnector:
).format(Literal(table_name))
with self.connection() as conn:
result = conn.execute(stmt).fetchone()
print(result)
return False if result is None else result["exists"]
def createTable(
@ -149,6 +148,17 @@ class DBConnector:
with self.connection() as conn:
return conn.execute(stmt).fetchall()
def filterFromTable(
self, table_name: str, columns: list[str], where: list[ColumnCondition]
) -> list[dict[str, Any]]:
stmt = SQL("SELECT {} FROM {} WHERE {}").format(
SQL(", ").join(map(lambda c: Identifier(c), columns)),
Identifier(table_name),
SQL(", ").join(map(lambda cp: cp.sql(), where)),
)
with self.connection() as conn:
return conn.execute(stmt).fetchall()
def updateDataInTable(
self, table_name: str, columns: list[ColumnUpdate], where: list[ColumnCondition]
):