use parking_lot::RwLockReadGuard;
use std::ops::Deref;
use crate::SessionStateSnapshot;
pub(crate) fn default_search_path() -> Vec<String> {
vec!["$user".into(), "public".into()]
}
pub(crate) fn effective_search_path(state: &SessionStateSnapshot) -> Vec<String> {
state
.search_path
.iter()
.map(|schema| {
if schema == "$user" {
state.authorization.current().name.clone()
} else {
schema.clone()
}
})
.collect()
}
pub(crate) struct LockedSearchPath<'a> {
_state: RwLockReadGuard<'a, SessionStateSnapshot>,
path: Vec<String>,
}
impl<'a> LockedSearchPath<'a> {
pub(crate) fn new(state: RwLockReadGuard<'a, SessionStateSnapshot>) -> Self {
let path = effective_search_path(&state);
Self {
_state: state,
path,
}
}
}
impl Deref for LockedSearchPath<'_> {
type Target = Vec<String>;
fn deref(&self) -> &Self::Target {
&self.path
}
}