diff --git a/Cargo.lock b/Cargo.lock index 428e5cb..0c0ebfe 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -29,9 +29,9 @@ version = "0.1.74" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a66537f1bb974b254c98ed142ff995236e81b9d0fe4db0575f46612cb15eb0f9" dependencies = [ - "proc-macro2 1.0.70", - "quote 1.0.33", - "syn 2.0.41", + "proc-macro2 1.0.78", + "quote 1.0.35", + "syn 2.0.48", ] [[package]] @@ -60,6 +60,9 @@ name = "bimap" version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "230c5f1ca6a325a32553f8640d31ac9b49f2411e901e427570154868b46da4f7" +dependencies = [ + "serde", +] [[package]] name = "bincode" @@ -163,6 +166,7 @@ name = "minisql" version = "0.1.0" dependencies = [ "bimap", + "serde", ] [[package]] @@ -287,9 +291,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.70" +version = "1.0.78" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39278fbbf5fb4f646ce651690877f89d1c5811a3d4acb27700c1cb3cdb78fd3b" +checksum = "e2422ad645d89c99f8f3e6b88a9fdeca7fabeac836b1002371c4367c8f984aae" dependencies = [ "unicode-ident", ] @@ -315,11 +319,11 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.33" +version = "1.0.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" +checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" dependencies = [ - "proc-macro2 1.0.70", + "proc-macro2 1.0.78", ] [[package]] @@ -345,22 +349,22 @@ checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" [[package]] name = "serde" -version = "1.0.193" +version = "1.0.196" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25dd9975e68d0cb5aa1120c288333fc98731bd1dd12f561e468ea4728c042b89" +checksum = "870026e60fa08c69f064aa766c10f10b1d62db9ccd4d0abb206472bee0ce3b32" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.193" +version = "1.0.196" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43576ca501357b9b071ac53cdc7da8ef0cbd9493d8df094cd821777ea6e894d3" +checksum = "33c85360c95e7d137454dc81d9a4ed2b8efd8fbe19cee57357b32b9771fccb67" dependencies = [ - "proc-macro2 1.0.70", - "quote 1.0.33", - "syn 2.0.41", + "proc-macro2 1.0.78", + "quote 1.0.35", + "syn 2.0.48", ] [[package]] @@ -412,12 +416,12 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.41" +version = "2.0.48" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44c8b28c477cc3bf0e7966561e3460130e1255f7a1cf71931075f1c5e7a7e269" +checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" dependencies = [ - "proc-macro2 1.0.70", - "quote 1.0.33", + "proc-macro2 1.0.78", + "quote 1.0.35", "unicode-ident", ] @@ -436,9 +440,9 @@ version = "1.0.50" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "266b2e40bc00e5a6c09c3584011e08b06f123c00362c92b975ba9843aaaa14b8" dependencies = [ - "proc-macro2 1.0.70", - "quote 1.0.33", - "syn 2.0.41", + "proc-macro2 1.0.78", + "quote 1.0.35", + "syn 2.0.48", ] [[package]] @@ -466,9 +470,9 @@ version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" dependencies = [ - "proc-macro2 1.0.70", - "quote 1.0.33", - "syn 2.0.41", + "proc-macro2 1.0.78", + "quote 1.0.35", + "syn 2.0.48", ] [[package]] diff --git a/minisql/Cargo.toml b/minisql/Cargo.toml index 1a108f1..8cbfc5b 100644 --- a/minisql/Cargo.toml +++ b/minisql/Cargo.toml @@ -6,4 +6,5 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -bimap = "0.6.3" +bimap = { version = "0.6.3", features = ["serde"] } +serde = { version = "1.0.196", features = ["derive"] } \ No newline at end of file diff --git a/minisql/src/internals/column_index.rs b/minisql/src/internals/column_index.rs index cdd331d..c5a5ebb 100644 --- a/minisql/src/internals/column_index.rs +++ b/minisql/src/internals/column_index.rs @@ -1,7 +1,8 @@ use crate::type_system::{IndexableValue, Uuid}; use std::collections::{BTreeMap, HashSet}; +use serde::{Deserialize, Serialize}; -#[derive(Debug)] +#[derive(Debug, Serialize, Deserialize)] pub struct ColumnIndex { index: BTreeMap>, } diff --git a/minisql/src/internals/row.rs b/minisql/src/internals/row.rs index ad8dc1e..3e635b8 100644 --- a/minisql/src/internals/row.rs +++ b/minisql/src/internals/row.rs @@ -1,10 +1,11 @@ use crate::type_system::Value; use std::ops::{Index, IndexMut}; use std::slice::SliceIndex; +use serde::{Deserialize, Serialize}; pub type ColumnPosition = usize; -#[derive(Debug, Clone)] +#[derive(Debug, Clone, Serialize, Deserialize)] pub struct Row(Vec); impl Index for Row diff --git a/minisql/src/internals/table.rs b/minisql/src/internals/table.rs index 2b5a5bc..fbe2368 100644 --- a/minisql/src/internals/table.rs +++ b/minisql/src/internals/table.rs @@ -1,4 +1,5 @@ use std::collections::{BTreeMap, HashMap, HashSet}; +use serde::{Deserialize, Serialize}; use crate::error::Error; use crate::internals::column_index::ColumnIndex; @@ -7,7 +8,7 @@ use crate::schema::{ColumnName, TableSchema, TableName}; use crate::result::DbResult; use crate::type_system::{IndexableValue, Uuid, Value}; -#[derive(Debug)] +#[derive(Debug, Serialize, Deserialize)] pub struct Table { schema: TableSchema, rows: Rows, // TODO: Consider wrapping this in a lock. Also consider if we need to have the diff --git a/minisql/src/interpreter.rs b/minisql/src/interpreter.rs index e85d085..357141a 100644 --- a/minisql/src/interpreter.rs +++ b/minisql/src/interpreter.rs @@ -6,13 +6,14 @@ use crate::operation::{ColumnSelection, Condition, Operation}; use crate::result::DbResult; use crate::type_system::{DbType, IndexableValue, Value}; use bimap::BiMap; +use serde::{Deserialize, Serialize}; // Use `TablePosition` as index pub type Tables = Vec; pub type TablePosition = usize; // ==============Interpreter================ -#[derive(Debug)] +#[derive(Debug, Serialize, Deserialize)] pub struct State { table_name_position_mapping: BiMap, tables: Tables, diff --git a/minisql/src/schema.rs b/minisql/src/schema.rs index e029606..65caa55 100644 --- a/minisql/src/schema.rs +++ b/minisql/src/schema.rs @@ -5,10 +5,11 @@ use crate::result::DbResult; use crate::type_system::{DbType, IndexableValue, Uuid, Value}; use bimap::BiMap; use std::collections::HashMap; +use serde::{Deserialize, Serialize}; // Note that it is nice to split metadata from the data because // then you can give the metadata to the parser without giving it the data. -#[derive(Debug)] +#[derive(Debug, Serialize, Deserialize)] pub struct TableSchema { table_name: TableName, // used for descriptive errors primary_key: ColumnPosition, diff --git a/minisql/src/type_system.rs b/minisql/src/type_system.rs index 7bf5f60..2e17393 100644 --- a/minisql/src/type_system.rs +++ b/minisql/src/type_system.rs @@ -1,5 +1,7 @@ +use serde::{Deserialize, Serialize}; + // ==============Types================ -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)] pub enum DbType { String, Int, @@ -13,14 +15,14 @@ pub type Uuid = u64; // TODO: What about nulls? I would rather not have that in SQL, it sucks. // I would rather have non-nullable values by default, // and something like an explicit Option type for nulls. -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub enum Value { Number(f64), // TODO: Can't put floats as keys in maps, since they don't implement Eq. What to // do? Indexable(IndexableValue), } -#[derive(Debug, Ord, Eq, Clone, PartialOrd, PartialEq)] +#[derive(Debug, Ord, Eq, Clone, PartialOrd, PartialEq, Serialize, Deserialize)] pub enum IndexableValue { String(String), Int(u64),