sochdb_query/executor/
types.rs1use crate::soch_ql::SochValue;
6
7pub type Row = Vec<SochValue>;
9
10#[derive(Debug, Clone, PartialEq, Eq)]
12pub struct ColumnMeta {
13 pub name: String,
15 pub table: Option<String>,
17}
18
19impl ColumnMeta {
20 pub fn new(name: impl Into<String>) -> Self {
21 Self { name: name.into(), table: None }
22 }
23
24 pub fn qualified(table: impl Into<String>, name: impl Into<String>) -> Self {
25 Self { name: name.into(), table: Some(table.into()) }
26 }
27}
28
29#[derive(Debug, Clone, PartialEq, Eq)]
31pub struct Schema {
32 pub columns: Vec<ColumnMeta>,
33}
34
35impl Schema {
36 pub fn new(columns: Vec<ColumnMeta>) -> Self {
37 Self { columns }
38 }
39
40 pub fn empty() -> Self {
41 Self { columns: vec![] }
42 }
43
44 pub fn len(&self) -> usize {
46 self.columns.len()
47 }
48
49 pub fn is_empty(&self) -> bool {
50 self.columns.is_empty()
51 }
52
53 pub fn index_of(&self, name: &str) -> Option<usize> {
55 self.columns.iter().position(|c| c.name == name)
56 }
57
58 pub fn index_of_qualified(&self, table: Option<&str>, name: &str) -> Option<usize> {
60 match table {
61 Some(t) => self.columns.iter().position(|c| {
62 c.name == name && c.table.as_deref() == Some(t)
63 }),
64 None => self.index_of(name),
65 }
66 }
67
68 pub fn column_names(&self) -> Vec<String> {
70 self.columns.iter().map(|c| c.name.clone()).collect()
71 }
72
73 pub fn merge(&self, other: &Schema) -> Schema {
75 let mut cols = self.columns.clone();
76 cols.extend(other.columns.iter().cloned());
77 Schema::new(cols)
78 }
79}