#[cfg(feature = "sql")]
use crate::db::sql::lowering::LoweredSqlCommand;
use crate::db::{
query::intent::StructuralQuery,
sql::{
lowering::SqlGlobalAggregateCommand,
parser::{SqlDescribeMode, SqlInsertStatement, SqlReturningProjection, SqlUpdateStatement},
},
};
#[derive(Clone, Debug)]
pub(in crate::db) enum CompiledSqlCommand {
Select {
query: Box<StructuralQuery>,
},
Delete {
query: Box<StructuralQuery>,
returning: Option<SqlReturningProjection>,
},
GlobalAggregate {
command: Box<SqlGlobalAggregateCommand>,
},
#[cfg(feature = "sql")]
Explain(Box<LoweredSqlCommand>),
Insert(CompiledSqlInsertCommand),
Update(SqlUpdateStatement),
DescribeEntity {
mode: SqlDescribeMode,
},
ShowConstraintsEntity,
ShowIndexesEntity,
ShowColumnsEntity {
mode: SqlDescribeMode,
},
ShowRelationsEntity,
ShowEntities {
entity: Option<String>,
verbose: bool,
},
ShowStores {
verbose: bool,
},
ShowMemory,
}
#[derive(Clone, Debug)]
pub(in crate::db) struct CompiledSqlInsertCommand {
statement: SqlInsertStatement,
source_query: Option<Box<StructuralQuery>>,
}
impl CompiledSqlInsertCommand {
#[must_use]
pub(in crate::db) fn new(
statement: SqlInsertStatement,
source_query: Option<StructuralQuery>,
) -> Self {
Self {
statement,
source_query: source_query.map(Box::new),
}
}
#[must_use]
pub(in crate::db) const fn statement(&self) -> &SqlInsertStatement {
&self.statement
}
#[must_use]
pub(in crate::db) fn source_query(&self) -> Option<&StructuralQuery> {
self.source_query.as_deref()
}
}
impl CompiledSqlCommand {
#[must_use]
pub(in crate::db) fn select(query: StructuralQuery) -> Self {
Self::Select {
query: Box::new(query),
}
}
#[must_use]
pub(in crate::db) fn global_aggregate(command: SqlGlobalAggregateCommand) -> Self {
Self::GlobalAggregate {
command: Box::new(command),
}
}
}
crate::retained::retained_fields!(CompiledSqlInsertCommand {
Self { statement, source_query } => [statement, source_query],
});
crate::retained::retained_fields!(CompiledSqlCommand {
Self::Select { query } => [query],
Self::Delete { query, returning } => [query, returning],
Self::GlobalAggregate { command } => [command],
#[cfg(feature = "sql")]
Self::Explain(command) => [command],
Self::Insert(command) => [command],
Self::Update(statement) => [statement],
Self::ShowEntities { entity, verbose: _ } => [entity],
Self::DescribeEntity { mode: _ } | Self::ShowConstraintsEntity | Self::ShowIndexesEntity
| Self::ShowColumnsEntity { mode: _ } | Self::ShowRelationsEntity | Self::ShowStores { verbose: _ }
| Self::ShowMemory => [],
});