I use python. I create a cloud function to return results from the search query connected with PostgreSQL. I swear the sql is connect. When it comes to retuning fetch result from the sql, it says the row object is not serialisable JSON . How should I convert this row results into json ?
Here is my code
def freebie(request):
engine = create_engine('postgresql://ABC' , echo=True)
conn = engine.connect()
x_sql = sa.text('''
SELECT user_label from "database"."user"
WHERE "_id" = :userId
''')
record = conn.execute(x_sql, userId = '82f3f82f-5bae-45d3-971f-b4af3a06182f',
current_time = datetime.now(), ).fetchall()
user_labbel = record[0][0]
campaign_sql = sa.text('''
SELECT * from "database"."user_fav_books"
WHERE "user_label" = :campaign_id
''')
result = conn.execute(campaign_sql, campaign_id = user_labbel,
current_time = datetime.now(), ).fetchall()
if len(result) == 0 :
return "No result"
else:
return json.dump(result, indent=4 , check_circular=True)