hematite/query/
runtime.rs1use crate::catalog::{CatalogEngine, Schema, StoredRow, Value};
4use crate::error::Result;
5
6#[derive(Debug, Clone)]
7pub struct QueryResult {
8 pub affected_rows: usize,
9 pub columns: Vec<String>,
10 pub rows: Vec<Vec<Value>>,
11}
12
13#[derive(Debug)]
14pub struct ExecutionContext<'a> {
15 pub catalog: Schema,
16 pub engine: &'a mut CatalogEngine,
17 pub mutation_events: Vec<MutationEvent>,
18}
19
20#[derive(Debug, Clone)]
21pub enum MutationEvent {
22 Insert {
23 table_name: String,
24 new_row: StoredRow,
25 },
26 Update {
27 table_name: String,
28 old_row: StoredRow,
29 new_row: StoredRow,
30 },
31 Delete {
32 table_name: String,
33 old_row: StoredRow,
34 },
35}
36
37impl<'a> ExecutionContext<'a> {
38 pub fn for_read(catalog: &Schema, engine: &'a mut CatalogEngine) -> Self {
39 Self {
40 catalog: catalog.clone(),
41 engine,
42 mutation_events: Vec::new(),
43 }
44 }
45
46 pub fn for_mutation(catalog: &Schema, engine: &'a mut CatalogEngine) -> Self {
47 Self {
48 catalog: catalog.clone(),
49 engine,
50 mutation_events: Vec::new(),
51 }
52 }
53}
54
55pub trait QueryExecutor {
56 fn execute(&mut self, ctx: &mut ExecutionContext<'_>) -> Result<QueryResult>;
57}