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

Commit

Permalink
fix: Add support to updat arrays, trap no results being returned
Browse files Browse the repository at this point in the history
  • Loading branch information
rsavoye committed Mar 4, 2024
1 parent 47440ad commit 0f5ab52
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions tm_admin/pgsupport.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,10 @@ async def insertRecords(self,
# print(sql)
result = await self.execute(sql)

return result[0]['id']
if len(result) > 0:
return result[0]['id']
else:
return list()

async def updateColumns(self,
columns: dict,
Expand Down Expand Up @@ -222,19 +225,19 @@ async def updateColumns(self,
if val[:7] == "public.":
# It's an enum
tmtype = val[7:].capitalize()
if tmtype[-2:] == "[]":
# it's an array
obj = eval("tm_admin.types_tm.%s(%s)" % (tmtype[:-2], value))
# data[key] = "{%s}" % obj.name
else:
obj = eval(f"tm_admin.types_tm.{tmtype}({value})")
sql += f" {key} = '{obj.name}', "
obj = eval(f"tm_admin.types_tm.{tmtype}({value})")
sql += f" {key} = '{obj.name}', "
elif val[-2:] == "[]" or val == "jsonb":
sql += f" {key} = {key}||{value}, "
else:
sql += f" {key} = {value}, "
# print(sql)
result = await self.execute(sql[:-2] + f" {check[:-3]} RETURNING id")

return result[0]['id']
query = sql[:-2] + f" {check[:-3]} RETURNING id"
# print(query)
result = await self.execute(query)
if len(result) > 0:
return result[0]['id']
else:
return 0

async def resetSequence(self):
"""
Expand Down

0 comments on commit 0f5ab52

Please sign in to comment.