|
ORE Studio 0.0.4
|
Manages tenant context for multi-tenant database operations. More...
#include <tenant_context.hpp>

Static Public Member Functions | |
| static context | with_tenant (const context &ctx, const std::string &tenant) |
| Creates a new context with the specified tenant. | |
| static context | with_system_tenant (const context &ctx) |
| Creates a new context with the system tenant. | |
| static utility::uuid::tenant_id | lookup_by_code (const context &ctx, const std::string &code) |
| Looks up a tenant ID by its code. | |
| static utility::uuid::tenant_id | lookup_by_hostname (const context &ctx, const std::string &hostname) |
| Looks up a tenant ID by its hostname. | |
| static std::string | lookup_name (const context &ctx, const utility::uuid::tenant_id &tenant_id) |
| Looks up a tenant name by its ID. | |
| static bool | is_uuid (const std::string &str) |
| Checks if a string is a valid UUID format. | |
Static Public Attributes | |
| static constexpr const char * | system_tenant_id |
| The UUID of the system tenant (max UUID per RFC 9562). | |
Manages tenant context for multi-tenant database operations.
This class provides utilities for setting and managing the current tenant context on database connections. In a multi-tenant environment, all database operations must be performed within a tenant context to ensure proper row-level security enforcement.
Creates a new context with the specified tenant.
Accepts either a tenant code (e.g., "system", "acme") or a tenant UUID. If a code is provided, looks up the corresponding tenant_id from the database. The returned context will set the session variable app.current_tenant_id on connection acquisition, which is used by row-level security policies.
| ctx | The source context (provides pool and credentials). |
| tenant | Tenant code or UUID string. |
| std::runtime_error | if tenant not found. |

Creates a new context with the system tenant.
Convenience method that creates a context for the system tenant (ffffffff-ffff-ffff-ffff-ffffffffffff, the max UUID).
| ctx | The source context (provides pool and credentials). |

|
static |
Looks up a tenant ID by its code.
| ctx | The database context to query. |
| code | The tenant code (e.g., "system", "acme"). |
| std::runtime_error | if tenant not found. |
|
static |
Looks up a tenant ID by its hostname.
| ctx | The database context to query. |
| hostname | The tenant hostname (e.g., "localhost", "acme.example.com"). |
| std::runtime_error | if tenant not found. |
|
static |
Looks up a tenant name by its ID.
Returns "System" for the system tenant (max UUID), otherwise queries the database for the tenant name.
| ctx | The database context to query. |
| tenant_id | The tenant ID. |
| std::runtime_error | if tenant not found. |
|
static |
Checks if a string is a valid UUID format.
| str | The string to check. |
|
staticconstexpr |
The UUID of the system tenant (max UUID per RFC 9562).
Uses max UUID instead of nil UUID to prevent confusion with uninitialized UUIDs (boost::uuids::uuid default-constructs to nil).