I have create a fastapi end point. I pass some params and i want to get a csv file. How can i do that. The following is the code.
@app.get("/")
async def root(token: str, dbhost: str, port: int, dbname: str ,username: str, passwd: str,table: str):
con = psycopg2.connect(dbname=dbname, user=username, password=passwd, host=dbhost, port=port)
cur = con.cursor()
save = "{}.csv".format(table)
store = sql.SQL("""COPY {table} TO STDOUT WITH CSV HEADER""").format(table=sql.Identifier(table),)
### --> HOW TO write the store into the save <-------
con.commit()
cur.close()
con.close()
return csv file ### <- how to return csv file