aboutsummaryrefslogtreecommitdiff
path: root/gn3/db
diff options
context:
space:
mode:
authorBonfaceKilz2021-06-07 19:43:17 +0300
committerzsloan2021-06-18 22:08:04 +0000
commite67316601be4b43da6f60322fef1f4ce15ed5905 (patch)
tree5c1b6ce53fec27db39fb3d939fb67905d7719e10 /gn3/db
parent712a4f7235cc1167fe1c4e591737a045b9a60ac3 (diff)
downloadgenenetwork3-e67316601be4b43da6f60322fef1f4ce15ed5905.tar.gz
gn3: db: Fix how columns from tables is resolved
Diffstat (limited to 'gn3/db')
-rw-r--r--gn3/db/__init__.py10
1 files changed, 5 insertions, 5 deletions
diff --git a/gn3/db/__init__.py b/gn3/db/__init__.py
index 25ecfd6..34a0236 100644
--- a/gn3/db/__init__.py
+++ b/gn3/db/__init__.py
@@ -65,12 +65,12 @@ def fetchone(conn: Any,
"""Run a SELECT on a table. Returns only one result!"""
if not any(astuple(where)):
return None
- where_ = {k: v for k, v in asdict(where).items()
+ where_ = {TABLEMAP[table].get(k): v for k, v in asdict(where).items()
if v is not None and k in TABLEMAP[table]}
sql = f"SELECT * FROM {table} "
if where:
sql += "WHERE "
- sql += " AND ".join(f"{TABLEMAP[table].get(k)} = "
+ sql += " AND ".join(f"{k} = "
"%s" for k in where_.keys())
with conn.cursor() as cursor:
cursor.execute(sql, tuple(where_.values()))
@@ -83,12 +83,12 @@ def fetchall(conn: Any,
"""Run a SELECT on a table. Returns all the results as a tuple!"""
if not any(astuple(where)):
return None
- where_ = {k: v for k, v in asdict(where).items()
+ where_ = {TABLEMAP[table].get(k): v for k, v in asdict(where).items()
if v is not None and k in TABLEMAP[table]}
sql = f"SELECT * FROM {table} "
if where:
sql += "WHERE "
- sql += " AND ".join(f"{TABLEMAP[table].get(k)} = "
+ sql += " AND ".join(f"{k} = "
"%s" for k in where_.keys())
with conn.cursor() as cursor:
cursor.execute(sql, tuple(where_.values()))
@@ -99,7 +99,7 @@ def insert(conn: Any,
table: str,
data: Dataclass) -> Optional[int]:
"""Run an INSERT into a table"""
- dict_ = {k: v for k, v in asdict(data).items()
+ dict_ = {TABLEMAP[table].get(k): v for k, v in asdict(data).items()
if v is not None and k in TABLEMAP[table]}
sql = f"INSERT INTO {table} ("
sql += ", ".join(f"{k}" for k in dict_.keys())