pub struct SearchPath(/* private fields */);Expand description
A validated PostgreSQL search_path, applied at connection establishment.
§Why this is a type and not a SET statement
SET search_path is session-scoped, and a connection pool is N independent
sessions. Issuing the SET through a pooled query configures whichever single
connection was checked out and leaves every other connection — including ones
the pool opens later, and every replacement created after a backend
disconnects — on the server default. Schema-per-tenant isolation built that way
resolves most queries against public: silently wrong rows where public
shadows the relation, an intermittent relation ... does not exist where it does
not (#809).
Lowering the path into the startup options parameter instead makes it a
property of how connections are made, so it cannot be missed by a connection
and cannot be lost to recycling — RESET/DISCARD ALL restore the startup
value, not the server default.
§Example
use fraiseql_db::postgres::SearchPath;
let path = SearchPath::new(["tenant_acme", "public"])?;
assert_eq!(path.as_str(), "tenant_acme,public");
// Anything that is not a bare identifier is refused rather than escaped.
assert!(SearchPath::new(["public; DROP SCHEMA x"]).is_err());Implementations§
Source§impl SearchPath
impl SearchPath
Sourcepub fn new<I, S>(schemas: I) -> Result<SearchPath, FraiseQLError>
pub fn new<I, S>(schemas: I) -> Result<SearchPath, FraiseQLError>
Build a search path from schema names, in resolution order.
§Errors
Returns FraiseQLError::Validation if the list is empty or any entry is
not a bare, unquoted PostgreSQL identifier ([A-Za-z_][A-Za-z0-9_]*, at most
63 characters). Rejecting rather than quoting keeps the emitted startup
option free of characters that could terminate it.
Trait Implementations§
Source§impl Clone for SearchPath
impl Clone for SearchPath
Source§fn clone(&self) -> SearchPath
fn clone(&self) -> SearchPath
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for SearchPath
impl Debug for SearchPath
Source§impl Display for SearchPath
impl Display for SearchPath
impl Eq for SearchPath
Source§impl PartialEq for SearchPath
impl PartialEq for SearchPath
impl StructuralPartialEq for SearchPath
Auto Trait Implementations§
impl Freeze for SearchPath
impl RefUnwindSafe for SearchPath
impl Send for SearchPath
impl Sync for SearchPath
impl Unpin for SearchPath
impl UnsafeUnpin for SearchPath
impl UnwindSafe for SearchPath
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.