use std::path::PathBuf;
use super::super::csv_import::CsvImport;
use super::super::sqlpage_expr::{RowExpr, StandaloneExpr};
use super::super::sqlpage_functions::functions::SqlPageFunctionName;
#[derive(Default)]
pub struct SqlFile {
pub(in crate::webserver::database) statements: Box<[FileStatement]>,
pub source_path: PathBuf,
}
#[derive(Debug)]
pub(in crate::webserver::database) enum FileStatement {
Query(Query),
SetVariable { target: VariableName, value: Query },
CsvImport(CsvImport),
Error(anyhow::Error),
}
#[derive(Debug, PartialEq)]
pub(in crate::webserver::database) struct Query {
pub body: QueryBody,
pub source_span: SourceSpan,
}
#[derive(Debug, PartialEq)]
pub(in crate::webserver::database) enum QueryBody {
Database(DatabaseQuery),
SingleRow(SingleRowQuery),
}
#[derive(Debug, PartialEq)]
pub(in crate::webserver::database) struct DatabaseQuery {
pub sql: String,
pub bindings: Box<[StandaloneExpr]>,
pub row_input_json: Box<[bool]>,
pub computed_columns: Box<[OutputColumn<RowExpr>]>,
pub json_columns: Box<[String]>,
}
impl DatabaseQuery {
pub fn must_buffer_rows(&self) -> bool {
self.computed_columns
.iter()
.any(|column| column.value.contains_function(SqlPageFunctionName::run_sql))
}
}
#[derive(Debug, PartialEq)]
pub(in crate::webserver::database) struct SingleRowQuery {
pub columns: Box<[OutputColumn<StandaloneExpr>]>,
}
#[derive(Debug, PartialEq, Eq)]
pub(in crate::webserver::database) struct OutputColumn<Expr> {
pub name: String,
pub value: Expr,
}
#[derive(Debug, PartialEq, Eq)]
pub(in crate::webserver::database) struct VariableName(pub String);
#[derive(Debug, PartialEq, Clone, Copy)]
pub(in crate::webserver::database) struct SourceSpan {
pub start: SourceLocation,
pub end: SourceLocation,
}
#[derive(Debug, PartialEq, Clone, Copy)]
pub(in crate::webserver::database) struct SourceLocation {
pub line: usize,
pub column: usize,
}