use crate::db::{
commit::CommitSchemaFingerprint,
executor::EntityAuthority,
query::intent::StructuralQuery,
schema::AcceptedSchemaSnapshot,
sql::{
lowering::{LoweredSqlCommand, StructuralSqlGlobalAggregateCommand},
parser::{SqlInsertStatement, SqlReturningProjection, SqlUpdateStatement},
},
};
use std::sync::Arc;
#[derive(Clone, Debug)]
pub(in crate::db) enum CompiledSqlCommand {
Select {
query: Arc<StructuralQuery>,
},
Delete {
query: Arc<StructuralQuery>,
returning: Option<SqlReturningProjection>,
},
GlobalAggregate {
command: Box<StructuralSqlGlobalAggregateCommand>,
},
Explain(Box<LoweredSqlCommand>),
Insert(SqlInsertStatement),
Update(SqlUpdateStatement),
DescribeEntity,
ShowIndexesEntity,
ShowColumnsEntity,
ShowEntities {
verbose: bool,
},
ShowStores {
verbose: bool,
},
ShowMemory,
}
#[derive(Clone, Debug)]
pub(in crate::db) struct SqlCompiledCommandExecutionContext {
command: CompiledSqlCommand,
accepted_schema: AcceptedSchemaSnapshot,
schema_fingerprint: CommitSchemaFingerprint,
accepted_authority: Option<EntityAuthority>,
}
impl SqlCompiledCommandExecutionContext {
#[must_use]
pub(in crate::db) const fn new(
command: CompiledSqlCommand,
accepted_schema: AcceptedSchemaSnapshot,
schema_fingerprint: CommitSchemaFingerprint,
accepted_authority: Option<EntityAuthority>,
) -> Self {
Self {
command,
accepted_schema,
schema_fingerprint,
accepted_authority,
}
}
#[must_use]
pub(in crate::db) const fn command(&self) -> &CompiledSqlCommand {
&self.command
}
#[must_use]
pub(in crate::db) fn into_command(self) -> CompiledSqlCommand {
self.command
}
#[must_use]
pub(in crate::db) const fn accepted_schema(&self) -> &AcceptedSchemaSnapshot {
&self.accepted_schema
}
#[must_use]
pub(in crate::db) const fn schema_fingerprint(&self) -> CommitSchemaFingerprint {
self.schema_fingerprint
}
#[must_use]
pub(in crate::db) const fn accepted_authority(&self) -> Option<&EntityAuthority> {
self.accepted_authority.as_ref()
}
}
#[derive(Clone, Debug)]
pub(in crate::db) struct SqlProjectionContract {
columns: Vec<String>,
fixed_scales: Vec<Option<u32>>,
}
impl SqlProjectionContract {
#[must_use]
pub(in crate::db) const fn new(columns: Vec<String>, fixed_scales: Vec<Option<u32>>) -> Self {
Self {
columns,
fixed_scales,
}
}
#[must_use]
pub(in crate::db) fn into_components(self) -> (Vec<String>, Vec<Option<u32>>) {
(self.columns, self.fixed_scales)
}
}