* Async chalice.core.tenants:tenants_exists, and propagate * rework after review * typofix * fix(chalice): small fixes * fix(api): use a global variable to store singletong... ... that will not work if several POSIX threads are serving from the same POSIX processus. * fix(api): pass database argument as dictionary. ref: https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNSTRING * chore(api): ease debugging with simple return statement. * NOTES++ --------- Co-authored-by: Taha Yassine Kraiem <tahayk2@gmail.com>
25 lines
824 B
Markdown
25 lines
824 B
Markdown
#### psycopg3 API
|
|
|
|
I mis-remember the psycopg v2 vs. v3 API.
|
|
|
|
For the record, the expected psycopg3's async api looks like the
|
|
following pseudo code:
|
|
|
|
```python
|
|
async with orpy.get().database.connection() as cnx:
|
|
async with cnx.transaction():
|
|
row = await cnx.execute("SELECT EXISTS(SELECT 1 FROM public.tenants)")
|
|
row = await row.fetchone()
|
|
return row["exists"]
|
|
```
|
|
|
|
Minding the following:
|
|
|
|
- Where `orpy.get().database` is the postgresql connection pooler.
|
|
- Wrap explicit transaction with `async with cnx.transaction():
|
|
foobar()`
|
|
- Most of the time the transaction object is not used;
|
|
- Do execute await operation against `cnx`;
|
|
- `await cnx.execute` returns a cursor object;
|
|
- Do the `await cursor.fetchqux...` calls against the object return by
|
|
a call to execute.
|