use crate::sql::Prefix;
use crate::BooleanJoiner;
use crate::LogicPath;
#[derive(Debug, Clone)]
pub struct AssemblyContext {
prefix: Prefix,
logic_path: LogicPath,
}
impl AssemblyContext {
pub fn new_root() -> Self {
Self {
prefix: Prefix::empty(),
logic_path: LogicPath::new_root(),
}
}
pub fn prefix(&self) -> &Prefix {
&self.prefix
}
pub fn logic_path(&self) -> &LogicPath {
&self.logic_path
}
pub fn prefix_with(&self, token: &str) -> Self {
Self {
prefix: self.prefix.with(token),
logic_path: self.logic_path,
}
}
pub fn prefix_with_unique_reason(&self, reason: &str, group: Option<BooleanJoiner>) -> Self {
Self {
prefix: self.prefix.with_unique_reason(reason, group),
logic_path: self.logic_path,
}
}
pub fn in_and_block(&self) -> Self {
Self {
prefix: self.prefix.in_block(Some(BooleanJoiner::And)),
logic_path: self.logic_path.and(),
}
}
pub fn in_or_block(&self) -> Self {
Self {
prefix: self.prefix.in_block(Some(BooleanJoiner::Or)),
logic_path: self.logic_path.or(),
}
}
pub fn in_invert_block(&self) -> Self {
Self {
prefix: self.prefix.clone(),
logic_path: self.logic_path.not(),
}
}
pub fn in_subquery_block(&self) -> Self {
Self {
prefix: self.prefix.with_unique_reason("subquery_", None),
logic_path: LogicPath::new_root(),
}
}
pub fn is_branch_inverted(&self) -> bool {
self.logic_path.is_branch_inverted()
}
}