Hi List,

I have no Google-fu. This is especially obvious when trying to search for 
something like I’m asking about.

Does anyone have any info or links to docs, blog posts, etc. that covers how to 
use connection pools with individual PostgreSQL user logins for a backend REST 
API?

The reason I ask is I’m using row level security (RLS) like in the example 
below from the PostgreSQL docs. I’ve only ever used a single 
application-specific account for accessing the database for all tenants. Now, 
however, each API key used in an API request will be tied to an account table 
and will have a PostgreSQL database user created for them so “current_user” 
works for RLS.

I’d like for requests to complete as fast as possible and I’m guessing there’s 
a better way than logging in to the database for each request.

The software involved is PostgreSQL 14, SQLAlchemy with asyncpg and FastAPI.

>From the page: https://www.postgresql.org/docs/current/ddl-rowsecurity.html 
><https://www.postgresql.org/docs/current/ddl-rowsecurity.html>

One example uses the DDL and policy:

CREATE TABLE accounts (manager text, company text, contact_email text);

ALTER TABLE accounts ENABLE ROW LEVEL SECURITY;

CREATE POLICY account_managers ON accounts TO managers
    USING (manager = current_user);

Thanks for your help.

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy/DCF5536D-71FD-46BA-B831-0755588A79DD%40gmail.com.

Reply via email to