Re:PostgREST 9.0
by throwawayboise on Tuesday November 30, 2021 @10:58AM
(#29393524)
So write those functions. Would be a minimal one-time investment that you could re-use everywhere.
Re:PostgREST 9.0
by steve-chavez on Tuesday November 30, 2021 @12:51PM
(#29395102)
There are python clients available[1]. For example with postgrest-py[2] you can do:
async with PostgrestClient("http://<yourhost>.com") as client:
r = await client.from_("countries").select("*").execute()
countries = r.json()
One advantage is that you don't have to worry about handling raw postgresql connections or pooling(as PostgREST does that for you), you only do HTTP requests. And if you want more complex SQL you can create functions or views.[1]: https://postgrest.org/en/v9.0/ecosystem.html#client-side-lib...
class PG:
_pg_conn = None
@classmethod
def pg(cls):
if cls._pg_conn is None:
cls._pg_conn = psycopg2.connect(...)
return cls._pg_conn
connection = PG.pg()Another approach would be to use a lazy property:
I've seen that. I wish it were in the standard library though.
I'd like to be able to do:
or even and have the lib deal with initialising and managing any connection pools/objects.