2022-07-30 15:34:12 +00:00
|
|
|
use crate::record::ColumnValue;
|
|
|
|
|
2021-09-18 15:00:35 +00:00
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct Schema {
|
2022-07-04 20:22:40 +00:00
|
|
|
pub kind: String,
|
|
|
|
pub name: String,
|
|
|
|
pub table_name: String,
|
2022-11-14 10:49:48 +00:00
|
|
|
pub root_page: u32,
|
2022-07-26 07:57:26 +00:00
|
|
|
pub sql: String,
|
2021-09-18 15:00:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Schema {
|
|
|
|
/// Parses a record into a schema
|
2022-07-30 15:34:12 +00:00
|
|
|
pub fn parse(record: Vec<ColumnValue>) -> Option<Self> {
|
2021-09-18 15:00:35 +00:00
|
|
|
let mut items = record.into_iter();
|
2022-11-14 10:37:18 +00:00
|
|
|
let kind = items.next()?.to_string();
|
|
|
|
let name = items.next()?.to_string();
|
|
|
|
let table_name = items.next()?.to_string();
|
2022-11-14 10:49:48 +00:00
|
|
|
let root_page = items.next()?.read_u32();
|
2022-11-14 10:37:18 +00:00
|
|
|
let sql = items.next()?.to_string();
|
2021-09-18 15:00:35 +00:00
|
|
|
|
|
|
|
let schema = Self {
|
2022-07-30 15:34:12 +00:00
|
|
|
kind,
|
|
|
|
name,
|
|
|
|
table_name,
|
2021-09-18 15:00:35 +00:00
|
|
|
root_page,
|
2022-07-30 15:34:12 +00:00
|
|
|
sql,
|
2021-09-18 15:00:35 +00:00
|
|
|
};
|
|
|
|
Some(schema)
|
|
|
|
}
|
|
|
|
}
|