Skip to content
This repository has been archived by the owner on Aug 5, 2024. It is now read-only.

Commit

Permalink
fix: Be less verbose
Browse files Browse the repository at this point in the history
  • Loading branch information
robsavoye committed Mar 19, 2024
1 parent d810ef4 commit c2db5d5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
11 changes: 7 additions & 4 deletions tm_admin/pgsupport.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,14 +164,13 @@ async def insertRecords(self,
# It's for a jsonb column
# a dict uses single quotes, postgres wants double quotes.
# newval = str(value).replace("'", '"')
breakpoint()
for entry in value[key]:
for k, v in entry.items():
if str(type(v))[:5] == "<enum":
jcol[k] = v.name
else:
jcol[k] = v
print(jcol)
# print(jcol)
# continue
# This is a bit ugly. When passing a geometry we need to get rid of the
# double quote around this value.
Expand Down Expand Up @@ -278,7 +277,11 @@ async def updateColumns(self,
sql += "}'"
else:
sql += f"{key} = {value}, "
query = sql[:-2] + f" {check} RETURNING id"

if sql[-2:] == ", ":
query = sql[:-2] + f" {check} RETURNING id"
else:
query = sql + f" {check} RETURNING id"
# print(query)
result = await self.execute(query.replace(", WHERE", " WHERE"))
if len(result) > 0:
Expand Down Expand Up @@ -397,7 +400,7 @@ async def updateJsonb(self,
data += f'" {v}", '
#asc = str(entry).replace("'", '"').replace("\\'", "'")
sql = "UPDATE %s SET %s = '{\"%s\": [%s]}' WHERE id=%d AND project_id=%d" % (self.table, column, column, data[:-2], task_id, project_id)
print(sql)
# print(sql)
result = await self.execute(sql)

async def appendJsonb(self,
Expand Down
2 changes: 1 addition & 1 deletion tm_admin/teams/teams.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ async def mergeTeams(self,
# sql = f"UPDATE teams SET team_members.team={record['team_id']}, team_members.active={record['active']}, team_members.function='{tmfunc.name}' WHERE id={record['team_id']}"
# UPDATE teams SET team_members = '{"13": [{"user_id": 629, "function": 1, "active": true}, {"user_id": 111, "function": 2, "active": true}]}';
sql = "UPDATE teams SET team_members = '{\"members\": %s}' WHERE id=%d;" % (asc, id)
#print(sql)
print(sql)
result = await self.pg.execute(sql)

timer.stop()
Expand Down

0 comments on commit c2db5d5

Please sign in to comment.