#[derive(Debug, Clone, PartialEq)]
pub enum GenerateLiteral {
Text(String),
Var(String),
Concat(Vec<GenerateLiteral>),
}
#[derive(Debug, Clone, PartialEq)]
pub struct TemplateClause {
pub prefix: Option<String>,
pub expr: GenerateLiteral,
pub suffix: Option<String>,
}
impl TemplateClause {
pub fn expr_only(expr: GenerateLiteral) -> Self {
Self {
prefix: None,
expr,
suffix: None,
}
}
pub fn with_prefix(prefix: impl Into<String>, var: impl Into<String>) -> Self {
Self {
prefix: Some(prefix.into()),
expr: GenerateLiteral::Var(var.into()),
suffix: None,
}
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct GenerateQuery {
pub prefix_decls: Vec<(String, String)>,
pub template: Vec<TemplateClause>,
pub where_body: String,
pub iterator: Option<String>,
}
impl GenerateQuery {
pub fn new(template: Vec<TemplateClause>, where_body: impl Into<String>) -> Self {
Self {
prefix_decls: Vec::new(),
template,
where_body: where_body.into(),
iterator: None,
}
}
pub fn clause_count(&self) -> usize {
self.template.len()
}
pub fn is_empty(&self) -> bool {
self.template.is_empty()
}
}