ORE Studio 0.0.4
Loading...
Searching...
No Matches
Public Member Functions | List of all members
tenant_aware_pool< Connection > Class Template Reference

A connection pool wrapper that sets tenant and party context on acquire. More...

#include <tenant_aware_pool.hpp>

Collaboration diagram for tenant_aware_pool< Connection >:
Collaboration graph

Public Member Functions

 tenant_aware_pool (sqlgen::ConnectionPool< Connection > pool, utility::uuid::tenant_id tenant_id, std::string actor="", std::string service_account="")
 Constructs a tenant-aware pool wrapper (tenant-only).
 
 tenant_aware_pool (sqlgen::ConnectionPool< Connection > pool, utility::uuid::tenant_id tenant_id, boost::uuids::uuid party_id, std::vector< boost::uuids::uuid > visible_party_ids, std::string actor="", std::string service_account="")
 Constructs a tenant-and-party-aware pool wrapper.
 
sqlgen::Result< sqlgen::Ref< sqlgen::Session< Connection > > > acquire () noexcept
 Acquires a session and sets the tenant (and party) context.
 
const utility::uuid::tenant_idtenant_id () const
 Gets the current tenant ID.
 
std::optional< boost::uuids::uuid > party_id () const
 Gets the current party ID, if set.
 
const std::vector< boost::uuids::uuid > & visible_party_ids () const
 Gets the visible party IDs.
 
const std::string & actor () const
 Gets the current actor (username), if set.
 
const std::string & service_account () const
 Gets the current service account, if set.
 
const sqlgen::ConnectionPool< Connection > & underlying_pool () const
 Gets the underlying connection pool.
 
size_t available () const
 Gets the number of available connections.
 
size_t size () const
 Gets the total number of connections in the pool.
 

Detailed Description

template<class Connection>
class ores::database::tenant_aware_pool< Connection >

A connection pool wrapper that sets tenant and party context on acquire.

PostgreSQL session variables are per-connection. When using a connection pool, different operations may get different connections, causing RLS policies that check the session variable to fail.

This wrapper ensures that whenever a connection is acquired from the pool, the tenant context (and optionally party context) is set via SET_CONFIG before returning the session. This allows RLS policies to work correctly with connection pooling.