1pub mod iter;
20#[cfg(feature = "core-loader")]
21pub mod loader;
22
23pub use assembly_fdb_core::value::{
24 mem::MemContext,
25 owned::{Field, OwnedContext},
26 Context, Value, ValueMapperMut, ValueType,
27};
28use std::collections::BTreeMap;
29
30#[derive(Debug, Default)]
32pub struct Row(Vec<Field>);
33
34impl From<Vec<Field>> for Row {
35 fn from(fields: Vec<Field>) -> Self {
36 Row(fields)
37 }
38}
39
40impl Row {
41 pub fn new() -> Row {
43 Row(Vec::new())
44 }
45
46 pub fn into_fields(self) -> Vec<Field> {
48 self.0
49 }
50
51 pub fn fields(&self) -> &Vec<Field> {
53 &self.0
54 }
55
56 pub fn fields_mut(&mut self) -> &mut Vec<Field> {
58 &mut self.0
59 }
60}
61
62#[derive(Debug, Default)]
64pub struct Bucket(pub Vec<Row>);
65
66impl Bucket {
67 pub fn new() -> Bucket {
69 Bucket(Vec::new())
70 }
71
72 pub fn rows(self) -> Vec<Row> {
74 self.0
75 }
76
77 pub fn rows_ref(&self) -> &Vec<Row> {
79 &self.0
80 }
81
82 pub fn rows_mut(&mut self) -> &mut Vec<Row> {
84 &mut self.0
85 }
86}
87
88#[derive(Debug)]
90pub struct Column {
91 pub name: String,
93 pub field_type: ValueType,
95}
96
97impl From<(&str, ValueType)> for Column {
98 fn from(data: (&str, ValueType)) -> Self {
99 Column {
100 name: String::from(data.0),
101 field_type: data.1,
102 }
103 }
104}
105
106#[derive(Debug)]
108pub struct TableDef {
109 pub columns: Vec<Column>,
111 pub name: String,
113}
114
115#[derive(Debug, Default)]
117pub struct TableData {
118 pub buckets: Vec<Bucket>,
120}
121
122impl TableData {
123 pub fn new() -> Self {
125 TableData {
126 buckets: Vec::new(),
127 }
128 }
129}
130
131#[derive(Debug)]
133pub struct Table {
134 definition: TableDef,
135 data: TableData,
136}
137
138impl Table {
139 pub fn from(definition: TableDef, data: TableData) -> Self {
141 Table { definition, data }
142 }
143
144 pub fn new(definition: TableDef) -> Self {
146 let data = TableData::new();
147 Table { definition, data }
148 }
149
150 pub fn into_buckets(self) -> Vec<Bucket> {
152 self.data.buckets
153 }
154
155 pub fn buckets(&self) -> &[Bucket] {
157 &self.data.buckets
158 }
159
160 pub fn buckets_mut(&mut self) -> &mut Vec<Bucket> {
162 &mut self.data.buckets
163 }
164
165 pub fn into_columns(self) -> Vec<Column> {
167 self.definition.columns
168 }
169
170 pub fn columns(&self) -> &[Column] {
172 &self.definition.columns
173 }
174
175 pub fn columns_mut(&mut self) -> &mut Vec<Column> {
177 &mut self.definition.columns
178 }
179
180 pub fn name(&self) -> &str {
182 self.definition.name.as_ref()
183 }
184}
185
186#[derive(Debug, Default)]
191pub struct Schema {
192 pub tables: BTreeMap<String, Table>,
194}
195
196impl Schema {
197 pub fn new() -> Schema {
199 Schema {
200 tables: BTreeMap::new(),
201 }
202 }
203
204 pub fn table(&self, name: &str) -> Option<&Table> {
206 self.tables.get(name)
207 }
208
209 pub fn table_mut(&mut self, name: &str) -> Option<&mut Table> {
211 self.tables.get_mut(name)
212 }
213
214 pub fn table_count(&self) -> usize {
216 self.tables.len()
217 }
218}
219
220impl From<Vec<Table>> for Schema {
221 fn from(tables: Vec<Table>) -> Self {
222 let mut tree = BTreeMap::new();
223 for table in tables {
224 tree.insert(table.name().to_string(), table);
225 }
226 Schema { tables: tree }
227 }
228}