1
0
Fork 0
sqlite-reader/src/schema.rs

30 lines
844 B
Rust
Raw Normal View History

#[derive(Debug)]
pub struct Schema {
2022-07-04 20:22:40 +00:00
pub kind: String,
pub name: String,
pub table_name: String,
2022-07-20 09:41:10 +00:00
pub root_page: u8,
sql: String,
}
impl Schema {
/// Parses a record into a schema
pub fn parse(record: Vec<Vec<u8>>) -> Option<Self> {
let mut items = record.into_iter();
let kind = items.next()?;
let name = items.next()?;
let table_name = items.next()?;
let root_page = *items.next()?.get(0)?;
let sql = items.next()?;
let schema = Self {
kind: String::from_utf8_lossy(&kind).to_string(),
name: String::from_utf8_lossy(&name).to_string(),
table_name: String::from_utf8_lossy(&table_name).to_string(),
root_page,
sql: String::from_utf8_lossy(&sql).to_string(),
};
Some(schema)
}
}