Use custom serialization compaction for DEFINE and REMOVE statements

This commit is contained in:
Tobie Morgan Hitchcock 2023-04-01 18:49:10 +01:00
parent be42b3e7c9
commit 2895026593
5 changed files with 34 additions and 3 deletions

4
Cargo.lock generated
View file

@ -3882,9 +3882,9 @@ dependencies = [
[[package]] [[package]]
name = "surrealdb-derive" name = "surrealdb-derive"
version = "0.6.0" version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dfb39273220b1d4cd0936abb8d1e9ec0eb673e17044169cb4604345576b1e0ef" checksum = "0e0f2a75e22417f587cf23a5efa9f680f4002b8655b8481a01ee5e787f15d82b"
dependencies = [ dependencies = [
"quote", "quote",
"syn 1.0.109", "syn 1.0.109",

View file

@ -59,7 +59,7 @@ bigdecimal = { version = "0.3.0", features = ["serde", "string-only"] }
bung = "0.1.0" bung = "0.1.0"
channel = { version = "1.8.0", package = "async-channel" } channel = { version = "1.8.0", package = "async-channel" }
chrono = { version = "0.4.24", features = ["serde"] } chrono = { version = "0.4.24", features = ["serde"] }
derive = { version = "0.6.0", package = "surrealdb-derive" } derive = { version = "0.7.0", package = "surrealdb-derive" }
dmp = "0.1.3" dmp = "0.1.3"
echodb = { version = "0.4.0", optional = true } echodb = { version = "0.4.0", optional = true }
executor = { version = "1.5.0", package = "async-executor" } executor = { version = "1.5.0", package = "async-executor" }

View file

@ -41,6 +41,7 @@ use serde::{Deserialize, Serialize};
use std::fmt::{self, Display, Write}; use std::fmt::{self, Display, Write};
#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize, Store, Hash)] #[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize, Store, Hash)]
#[format(Named)]
pub enum DefineStatement { pub enum DefineStatement {
Namespace(DefineNamespaceStatement), Namespace(DefineNamespaceStatement),
Database(DefineDatabaseStatement), Database(DefineDatabaseStatement),
@ -1253,3 +1254,17 @@ fn index(i: &str) -> IResult<&str, DefineIndexStatement> {
}, },
)) ))
} }
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn check_define_serialize() {
let stm = DefineStatement::Namespace(DefineNamespaceStatement {
name: Ident::from("test"),
});
assert_eq!(22, stm.to_vec().len());
}
}

View file

@ -22,6 +22,7 @@ use serde::{Deserialize, Serialize};
use std::fmt::{self, Display, Formatter}; use std::fmt::{self, Display, Formatter};
#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize, Store, Hash)] #[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize, Store, Hash)]
#[format(Named)]
pub enum RemoveStatement { pub enum RemoveStatement {
Namespace(RemoveNamespaceStatement), Namespace(RemoveNamespaceStatement),
Database(RemoveDatabaseStatement), Database(RemoveDatabaseStatement),
@ -798,3 +799,17 @@ fn index(i: &str) -> IResult<&str, RemoveIndexStatement> {
}, },
)) ))
} }
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn check_remove_serialize() {
let stm = RemoveStatement::Namespace(RemoveNamespaceStatement {
name: Ident::from("test"),
});
assert_eq!(22, stm.to_vec().len());
}
}

View file

@ -99,6 +99,7 @@ pub fn whats(i: &str) -> IResult<&str, Values> {
} }
#[derive(Clone, Debug, Default, PartialEq, PartialOrd, Deserialize, Store, Hash)] #[derive(Clone, Debug, Default, PartialEq, PartialOrd, Deserialize, Store, Hash)]
#[format(Compact)]
pub enum Value { pub enum Value {
#[default] #[default]
None, None,