systemprompt_database/scope/mod.rs
1//! Per-request connection scoping for pooled multi-tenancy.
2//!
3//! Extensions register a [`ConnectionScopeProvider`] that translates a
4//! [`RequestScope`](systemprompt_models::RequestScope) into transaction-local
5//! Postgres settings (custom GUCs such as `app.current_org`) applied via
6//! `set_config($1, $2, true)` on a scoped transaction — the parameterizable
7//! equivalent of `SET LOCAL`, which cannot bind parameters. Row-level-security
8//! policies then read the setting with `current_setting('app.current_org',
9//! true)`.
10//!
11//! The seam is strictly opt-in: only
12//! [`begin_scoped`](crate::services::begin_scoped) and the
13//! `with_scoped_transaction*` wrappers in
14//! [`crate::services`] consult the registry, and with no registered provider
15//! they degenerate to a plain `pool.begin()`. Existing transaction and pool
16//! APIs are untouched.
17//!
18//! Copyright (c) systemprompt.io — Business Source License 1.1.
19//! See <https://systemprompt.io> for licensing details.
20
21mod provider;
22mod registry;
23
24pub use provider::{ConnectionScopeProvider, ScopeError, ScopeSetting, SharedScopeProvider};
25pub use registry::{ScopeProviderRegistration, discover_scope_providers, scope_providers};