Unify serialisation (#1881)
This commit is contained in:
parent
955aea9409
commit
91e949248d
120 changed files with 549 additions and 1137 deletions
4
Cargo.lock
generated
4
Cargo.lock
generated
|
@ -3846,9 +3846,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "surrealdb-derive"
|
||||
version = "0.7.0"
|
||||
version = "0.8.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0e0f2a75e22417f587cf23a5efa9f680f4002b8655b8481a01ee5e787f15d82b"
|
||||
checksum = "7f44db5c0ba9716670cb45585f475e46b2c2e64428736e03a4e4a83a628b8a21"
|
||||
dependencies = [
|
||||
"quote",
|
||||
"syn 1.0.109",
|
||||
|
|
18
flake.lock
18
flake.lock
|
@ -32,11 +32,11 @@
|
|||
"rust-analyzer-src": "rust-analyzer-src"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1682144464,
|
||||
"narHash": "sha256-HlVJU4p1OED3HJNOoXrxR6qabKWMtGq0wbYhroumuVc=",
|
||||
"lastModified": 1682749232,
|
||||
"narHash": "sha256-tZdhmgUIuSrRB8j1fTa5JVdewdNf0crNwDMnNIKfYqE=",
|
||||
"owner": "nix-community",
|
||||
"repo": "fenix",
|
||||
"rev": "6424d70f13761c203dada9de6ce417fc9f22712d",
|
||||
"rev": "30d4a659367f2399cdc9e813c516ae53d46ab266",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
@ -110,11 +110,11 @@
|
|||
},
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1682110011,
|
||||
"narHash": "sha256-J1ArhCRJov3Ycflq7QcmpOzeqqYj39AjlcH77cUx/pQ=",
|
||||
"lastModified": 1682682915,
|
||||
"narHash": "sha256-haR0u/j/nUvlMloYlaOYq1FMXTvkNHw+wGxc+0qXisM=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "624f65a2b164bc9fe47324606940ffe773196813",
|
||||
"rev": "09f1b33fcc0f59263137e23e935c1bb03ec920e4",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
@ -136,11 +136,11 @@
|
|||
"rust-analyzer-src": {
|
||||
"flake": false,
|
||||
"locked": {
|
||||
"lastModified": 1682101542,
|
||||
"narHash": "sha256-CHSbpvLZf0joKD1cU+Hg02uIYvV3xkvwcx+0oBWL0CQ=",
|
||||
"lastModified": 1682710505,
|
||||
"narHash": "sha256-03cthpkTbEdQF7wpmJjPuBvwcQ5eSV4jDfWj8Evg4Lk=",
|
||||
"owner": "rust-lang",
|
||||
"repo": "rust-analyzer",
|
||||
"rev": "af3b6a0893cc3a05b5ddc1e9d31b2c454b480426",
|
||||
"rev": "370b72c7dd3dcdb1efe92224ab1622e44639cb07",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
|
|
@ -59,7 +59,7 @@ bigdecimal = { version = "0.3.0", features = ["serde", "string-only"] }
|
|||
bung = "0.1.0"
|
||||
channel = { version = "1.8.0", package = "async-channel" }
|
||||
chrono = { version = "0.4.24", features = ["serde"] }
|
||||
derive = { version = "0.7.0", package = "surrealdb-derive" }
|
||||
derive = { version = "0.8.0", package = "surrealdb-derive" }
|
||||
dmp = "0.1.3"
|
||||
echodb = { version = "0.4.0", optional = true }
|
||||
executor = { version = "1.5.1", package = "async-executor" }
|
||||
|
|
|
@ -9,7 +9,6 @@ mod strict;
|
|||
mod tls;
|
||||
|
||||
use crate::api::err::Error;
|
||||
use crate::sql::serde::serialize_internal;
|
||||
use crate::sql::to_value;
|
||||
use crate::sql::Thing;
|
||||
use crate::sql::Value;
|
||||
|
@ -336,8 +335,7 @@ fn into_json(value: Value, simplify: bool) -> JsonValue {
|
|||
|
||||
match value {
|
||||
Value::None | Value::Null => JsonValue::Null,
|
||||
Value::False => false.into(),
|
||||
Value::True => true.into(),
|
||||
Value::Bool(boolean) => boolean.into(),
|
||||
Value::Number(Number::Int(n)) => n.into(),
|
||||
Value::Number(Number::Float(n)) => n.into(),
|
||||
Value::Number(Number::Decimal(n)) => json!(n),
|
||||
|
@ -386,7 +384,7 @@ pub(crate) fn from_value<T>(value: Value) -> Result<T, Error>
|
|||
where
|
||||
T: DeserializeOwned,
|
||||
{
|
||||
let json = serialize_internal(|| into_json(value.clone(), false));
|
||||
let json = into_json(value.clone(), false);
|
||||
serde_json::from_value(json).map_err(|error| Error::FromValue {
|
||||
value,
|
||||
error: error.to_string(),
|
||||
|
|
|
@ -46,7 +46,7 @@ impl<'a> Document<'a> {
|
|||
let key = crate::key::graph::new(opt.ns(), opt.db(), &r.tb, &r.id, i, rid);
|
||||
run.set(key, vec![]).await?;
|
||||
// Store the edges on the record
|
||||
self.current.to_mut().set(ctx, opt, txn, &*EDGE, Value::True).await?;
|
||||
self.current.to_mut().set(ctx, opt, txn, &*EDGE, Value::Bool(true)).await?;
|
||||
self.current.to_mut().set(ctx, opt, txn, &*IN, l.clone().into()).await?;
|
||||
self.current.to_mut().set(ctx, opt, txn, &*OUT, r.clone().into()).await?;
|
||||
}
|
||||
|
|
|
@ -40,7 +40,7 @@ impl<'a> Document<'a> {
|
|||
run.del(key).await?;
|
||||
// Purge the record edges
|
||||
match (self.initial.pick(&*EDGE), self.initial.pick(&*IN), self.initial.pick(&*OUT)) {
|
||||
(Value::True, Value::Thing(ref l), Value::Thing(ref r)) => {
|
||||
(Value::Bool(true), Value::Thing(ref l), Value::Thing(ref r)) => {
|
||||
// Get temporary edge references
|
||||
let (ref o, ref i) = (Dir::Out, Dir::In);
|
||||
// Purge the left pointer edge
|
||||
|
|
|
@ -23,7 +23,7 @@ impl<'a> Document<'a> {
|
|||
self.current.to_mut().def(ctx, opt, txn, rid).await?;
|
||||
// Ensure edge fields are reset
|
||||
if self.initial.pick(&*EDGE).is_true() {
|
||||
self.current.to_mut().put(&*EDGE, Value::True);
|
||||
self.current.to_mut().put(&*EDGE, Value::Bool(true));
|
||||
self.current.to_mut().put(&*IN, self.initial.pick(&*IN));
|
||||
self.current.to_mut().put(&*OUT, self.initial.pick(&*OUT));
|
||||
}
|
||||
|
|
|
@ -177,12 +177,12 @@ pub fn sort((mut array, order): (Array, Option<Value>)) -> Result<Value, Error>
|
|||
Ok(array.into())
|
||||
}
|
||||
// If true, sort ascending
|
||||
Some(Value::True) => {
|
||||
Some(Value::Bool(true)) => {
|
||||
array.sort_unstable();
|
||||
Ok(array.into())
|
||||
}
|
||||
// If false, sort descending
|
||||
Some(Value::False) => {
|
||||
Some(Value::Bool(false)) => {
|
||||
array.sort_unstable_by(|a, b| b.cmp(a));
|
||||
Ok(array.into())
|
||||
}
|
||||
|
|
|
@ -123,12 +123,12 @@ pub mod bcrypt {
|
|||
pub fn cmp((hash, pass): (String, String)) -> Result<Value, Error> {
|
||||
let parts = match HashParts::from_str(&hash) {
|
||||
Ok(parts) => parts,
|
||||
Err(_) => return Ok(Value::False),
|
||||
Err(_) => return Ok(Value::Bool(false)),
|
||||
};
|
||||
// Note: Bcrypt cost is exponential, so add the cost allowance as opposed to multiplying.
|
||||
Ok(if parts.get_cost() > bcrypt::DEFAULT_COST.saturating_add(COST_ALLOWANCE) {
|
||||
// Too expensive to compute.
|
||||
Value::False
|
||||
Value::Bool(false)
|
||||
} else {
|
||||
// FIXME: If base64 dependency is added, can avoid parsing the HashParts twice, once
|
||||
// above and once in verity, by using bcrypt::bcrypt.
|
||||
|
|
|
@ -88,103 +88,103 @@ mod tests {
|
|||
#[test]
|
||||
fn alphanum() {
|
||||
let value = super::alphanum((String::from("abc123"),)).unwrap();
|
||||
assert_eq!(value, Value::True);
|
||||
assert_eq!(value, Value::Bool(true));
|
||||
|
||||
let value = super::alphanum((String::from("y%*"),)).unwrap();
|
||||
assert_eq!(value, Value::False);
|
||||
assert_eq!(value, Value::Bool(false));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn alpha() {
|
||||
let value = super::alpha((String::from("abc"),)).unwrap();
|
||||
assert_eq!(value, Value::True);
|
||||
assert_eq!(value, Value::Bool(true));
|
||||
|
||||
let value = super::alpha((String::from("1234"),)).unwrap();
|
||||
assert_eq!(value, Value::False);
|
||||
assert_eq!(value, Value::Bool(false));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ascii() {
|
||||
let value = super::ascii((String::from("abc"),)).unwrap();
|
||||
assert_eq!(value, Value::True);
|
||||
assert_eq!(value, Value::Bool(true));
|
||||
|
||||
let value = super::ascii((String::from("中国"),)).unwrap();
|
||||
assert_eq!(value, Value::False);
|
||||
assert_eq!(value, Value::Bool(false));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn domain() {
|
||||
let value = super::domain((String::from("食狮.中国"),)).unwrap();
|
||||
assert_eq!(value, Value::True);
|
||||
assert_eq!(value, Value::Bool(true));
|
||||
|
||||
let value = super::domain((String::from("example-.com"),)).unwrap();
|
||||
assert_eq!(value, Value::False);
|
||||
assert_eq!(value, Value::Bool(false));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn email() {
|
||||
let input = (String::from("user@[fd79:cdcb:38cc:9dd:f686:e06d:32f3:c123]"),);
|
||||
let value = super::email(input).unwrap();
|
||||
assert_eq!(value, Value::True);
|
||||
assert_eq!(value, Value::Bool(true));
|
||||
|
||||
let input = (String::from("john..doe@example.com"),);
|
||||
let value = super::email(input).unwrap();
|
||||
assert_eq!(value, Value::False);
|
||||
assert_eq!(value, Value::Bool(false));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn hexadecimal() {
|
||||
let value = super::hexadecimal((String::from("00FF00"),)).unwrap();
|
||||
assert_eq!(value, Value::True);
|
||||
assert_eq!(value, Value::Bool(true));
|
||||
|
||||
let value = super::hexadecimal((String::from("SurrealDB"),)).unwrap();
|
||||
assert_eq!(value, Value::False);
|
||||
assert_eq!(value, Value::Bool(false));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn latitude() {
|
||||
let value = super::latitude((String::from("-0.118092"),)).unwrap();
|
||||
assert_eq!(value, Value::True);
|
||||
assert_eq!(value, Value::Bool(true));
|
||||
|
||||
let value = super::latitude((String::from("12345"),)).unwrap();
|
||||
assert_eq!(value, Value::False);
|
||||
assert_eq!(value, Value::Bool(false));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn longitude() {
|
||||
let value = super::longitude((String::from("51.509865"),)).unwrap();
|
||||
assert_eq!(value, Value::True);
|
||||
assert_eq!(value, Value::Bool(true));
|
||||
|
||||
let value = super::longitude((String::from("12345"),)).unwrap();
|
||||
assert_eq!(value, Value::False);
|
||||
assert_eq!(value, Value::Bool(false));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn numeric() {
|
||||
let value = super::numeric((String::from("12345"),)).unwrap();
|
||||
assert_eq!(value, Value::True);
|
||||
assert_eq!(value, Value::Bool(true));
|
||||
|
||||
let value = super::numeric((String::from("abcde"),)).unwrap();
|
||||
assert_eq!(value, Value::False);
|
||||
assert_eq!(value, Value::Bool(false));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn semver() {
|
||||
let value = super::semver((String::from("1.0.0"),)).unwrap();
|
||||
assert_eq!(value, Value::True);
|
||||
assert_eq!(value, Value::Bool(true));
|
||||
|
||||
let value = super::semver((String::from("1.0"),)).unwrap();
|
||||
assert_eq!(value, Value::False);
|
||||
assert_eq!(value, Value::Bool(false));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn uuid() {
|
||||
let input = (String::from("123e4567-e89b-12d3-a456-426614174000").into(),);
|
||||
let value = super::uuid(input).unwrap();
|
||||
assert_eq!(value, Value::True);
|
||||
assert_eq!(value, Value::Bool(true));
|
||||
|
||||
let input = (String::from("foo-bar").into(),);
|
||||
let value = super::uuid(input).unwrap();
|
||||
assert_eq!(value, Value::False);
|
||||
assert_eq!(value, Value::Bool(false));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,8 +22,7 @@ impl<'js> IntoJs<'js> for &Value {
|
|||
match self {
|
||||
Value::Null => Null.into_js(ctx),
|
||||
Value::None => Undefined.into_js(ctx),
|
||||
Value::True => Ok(js::Value::new_bool(ctx, true)),
|
||||
Value::False => Ok(js::Value::new_bool(ctx, false)),
|
||||
Value::Bool(boolean) => Ok(js::Value::new_bool(ctx, *boolean)),
|
||||
Value::Strand(v) => js::String::from_str(ctx, v)?.into_js(ctx),
|
||||
Value::Number(Number::Int(v)) => Ok(js::Value::new_int(ctx, *v as i32)),
|
||||
Value::Number(Number::Float(v)) => Ok(js::Value::new_float(ctx, *v)),
|
||||
|
|
|
@ -367,7 +367,7 @@ impl Datastore {
|
|||
/// async fn main() -> Result<(), Error> {
|
||||
/// let ds = Datastore::new("memory").await?;
|
||||
/// let ses = Session::for_kv();
|
||||
/// let val = Value::Future(Box::new(Future::from(Value::True)));
|
||||
/// let val = Value::Future(Box::new(Future::from(Value::Bool(true))));
|
||||
/// let res = ds.compute(val, &ses, None, false).await?;
|
||||
/// Ok(())
|
||||
/// }
|
||||
|
|
|
@ -1701,7 +1701,7 @@ impl Transaction {
|
|||
// Check if this is a graph edge
|
||||
match (v.pick(&*EDGE), v.pick(&*IN), v.pick(&*OUT)) {
|
||||
// This is a graph edge record
|
||||
(Value::True, Value::Thing(l), Value::Thing(r)) => {
|
||||
(Value::Bool(true), Value::Thing(l), Value::Thing(r)) => {
|
||||
let sql = format!("RELATE {l} -> {t} -> {r} CONTENT {v};",);
|
||||
chn.send(bytes!(sql)).await?;
|
||||
}
|
||||
|
|
|
@ -8,12 +8,10 @@ use crate::sql::error::IResult;
|
|||
use crate::sql::fmt::{pretty_indent, Fmt, Pretty};
|
||||
use crate::sql::number::Number;
|
||||
use crate::sql::operation::Operation;
|
||||
use crate::sql::serde::is_internal_serialization;
|
||||
use crate::sql::value::{value, Value};
|
||||
use nom::character::complete::char;
|
||||
use nom::combinator::opt;
|
||||
use nom::multi::separated_list0;
|
||||
use serde::ser::SerializeSeq;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::collections::HashSet;
|
||||
use std::fmt::{self, Display, Formatter, Write};
|
||||
|
@ -23,7 +21,8 @@ use std::ops::DerefMut;
|
|||
|
||||
pub(crate) const TOKEN: &str = "$surrealdb::private::sql::Array";
|
||||
|
||||
#[derive(Clone, Debug, Default, Eq, Ord, PartialEq, PartialOrd, Deserialize, Hash)]
|
||||
#[derive(Clone, Debug, Default, Eq, Ord, PartialEq, PartialOrd, Serialize, Deserialize, Hash)]
|
||||
#[serde(rename = "$surrealdb::private::sql::Array")]
|
||||
pub struct Array(pub Vec<Value>);
|
||||
|
||||
impl From<Value> for Array {
|
||||
|
@ -143,23 +142,6 @@ impl Display for Array {
|
|||
}
|
||||
}
|
||||
|
||||
impl Serialize for Array {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: serde::Serializer,
|
||||
{
|
||||
if is_internal_serialization() {
|
||||
serializer.serialize_newtype_struct(TOKEN, &self.0)
|
||||
} else {
|
||||
let mut arr = serializer.serialize_seq(Some(self.len()))?;
|
||||
for v in &self.0 {
|
||||
arr.serialize_element(v)?;
|
||||
}
|
||||
arr.end()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------
|
||||
|
||||
impl ops::Add<Value> for Array {
|
||||
|
|
|
@ -7,7 +7,6 @@ use crate::sql::comment::{comment, mightbespace};
|
|||
use crate::sql::common::colons;
|
||||
use crate::sql::error::IResult;
|
||||
use crate::sql::fmt::{is_pretty, pretty_indent, Fmt, Pretty};
|
||||
use crate::sql::serde::is_internal_serialization;
|
||||
use crate::sql::statements::create::{create, CreateStatement};
|
||||
use crate::sql::statements::delete::{delete, DeleteStatement};
|
||||
use crate::sql::statements::ifelse::{ifelse, IfelseStatement};
|
||||
|
@ -31,7 +30,8 @@ use std::ops::Deref;
|
|||
|
||||
pub(crate) const TOKEN: &str = "$surrealdb::private::sql::Block";
|
||||
|
||||
#[derive(Clone, Debug, Default, Eq, PartialEq, PartialOrd, Deserialize, Hash)]
|
||||
#[derive(Clone, Debug, Default, Eq, PartialEq, PartialOrd, Serialize, Deserialize, Hash)]
|
||||
#[serde(rename = "$surrealdb::private::sql::Block")]
|
||||
pub struct Block(pub Vec<Entry>);
|
||||
|
||||
impl Deref for Block {
|
||||
|
@ -157,19 +157,6 @@ impl Display for Block {
|
|||
}
|
||||
}
|
||||
|
||||
impl Serialize for Block {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: serde::Serializer,
|
||||
{
|
||||
if is_internal_serialization() {
|
||||
serializer.serialize_newtype_struct(TOKEN, &self.0)
|
||||
} else {
|
||||
serializer.serialize_none()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn block(i: &str) -> IResult<&str, Block> {
|
||||
let (i, _) = char('{')(i)?;
|
||||
let (i, _) = mightbespace(i)?;
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
use crate::sql::serde::is_internal_serialization;
|
||||
use serde::Deserialize;
|
||||
use serde::Serialize;
|
||||
|
||||
|
@ -10,10 +9,6 @@ impl Serialize for Bytes {
|
|||
where
|
||||
S: serde::Serializer,
|
||||
{
|
||||
if is_internal_serialization() {
|
||||
serializer.serialize_bytes(&self.0)
|
||||
} else {
|
||||
serializer.serialize_none()
|
||||
}
|
||||
serializer.serialize_bytes(&self.0)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,7 +3,6 @@ use crate::dbs::Options;
|
|||
use crate::dbs::Transaction;
|
||||
use crate::err::Error;
|
||||
use crate::sql::error::IResult;
|
||||
use crate::sql::serde::is_internal_serialization;
|
||||
use crate::sql::value::Value;
|
||||
use derive::Store;
|
||||
use nom::branch::alt;
|
||||
|
@ -106,51 +105,27 @@ impl Serialize for Constant {
|
|||
where
|
||||
S: serde::Serializer,
|
||||
{
|
||||
if is_internal_serialization() {
|
||||
match self {
|
||||
Self::MathE => s.serialize_unit_variant(TOKEN, 0, "MathE"),
|
||||
Self::MathFrac1Pi => s.serialize_unit_variant(TOKEN, 1, "MathFrac1Pi"),
|
||||
Self::MathFrac1Sqrt2 => s.serialize_unit_variant(TOKEN, 2, "MathFrac1Sqrt2"),
|
||||
Self::MathFrac2Pi => s.serialize_unit_variant(TOKEN, 3, "MathFrac2Pi"),
|
||||
Self::MathFrac2SqrtPi => s.serialize_unit_variant(TOKEN, 4, "MathFrac2SqrtPi"),
|
||||
Self::MathFracPi2 => s.serialize_unit_variant(TOKEN, 5, "MathFracPi2"),
|
||||
Self::MathFracPi3 => s.serialize_unit_variant(TOKEN, 6, "MathFracPi3"),
|
||||
Self::MathFracPi4 => s.serialize_unit_variant(TOKEN, 7, "MathFracPi4"),
|
||||
Self::MathFracPi6 => s.serialize_unit_variant(TOKEN, 8, "MathFracPi6"),
|
||||
Self::MathFracPi8 => s.serialize_unit_variant(TOKEN, 9, "MathFracPi8"),
|
||||
Self::MathLn10 => s.serialize_unit_variant(TOKEN, 10, "MathLn10"),
|
||||
Self::MathLn2 => s.serialize_unit_variant(TOKEN, 11, "MathLn2"),
|
||||
Self::MathLog102 => s.serialize_unit_variant(TOKEN, 12, "MathLog102"),
|
||||
Self::MathLog10E => s.serialize_unit_variant(TOKEN, 13, "MathLog10E"),
|
||||
Self::MathLog210 => s.serialize_unit_variant(TOKEN, 14, "MathLog210"),
|
||||
Self::MathLog2E => s.serialize_unit_variant(TOKEN, 15, "MathLog2E"),
|
||||
Self::MathPi => s.serialize_unit_variant(TOKEN, 16, "MathPi"),
|
||||
Self::MathSqrt2 => s.serialize_unit_variant(TOKEN, 17, "MathSqrt2"),
|
||||
Self::MathTau => s.serialize_unit_variant(TOKEN, 18, "MathTau"),
|
||||
}
|
||||
} else {
|
||||
match self {
|
||||
Self::MathE => s.serialize_f64(std::f64::consts::E),
|
||||
Self::MathFrac1Pi => s.serialize_f64(std::f64::consts::FRAC_1_PI),
|
||||
Self::MathFrac1Sqrt2 => s.serialize_f64(std::f64::consts::FRAC_1_SQRT_2),
|
||||
Self::MathFrac2Pi => s.serialize_f64(std::f64::consts::FRAC_2_PI),
|
||||
Self::MathFrac2SqrtPi => s.serialize_f64(std::f64::consts::FRAC_2_SQRT_PI),
|
||||
Self::MathFracPi2 => s.serialize_f64(std::f64::consts::FRAC_PI_2),
|
||||
Self::MathFracPi3 => s.serialize_f64(std::f64::consts::FRAC_PI_3),
|
||||
Self::MathFracPi4 => s.serialize_f64(std::f64::consts::FRAC_PI_4),
|
||||
Self::MathFracPi6 => s.serialize_f64(std::f64::consts::FRAC_PI_6),
|
||||
Self::MathFracPi8 => s.serialize_f64(std::f64::consts::FRAC_PI_8),
|
||||
Self::MathLn10 => s.serialize_f64(std::f64::consts::LN_10),
|
||||
Self::MathLn2 => s.serialize_f64(std::f64::consts::LN_2),
|
||||
Self::MathLog102 => s.serialize_f64(std::f64::consts::LOG10_2),
|
||||
Self::MathLog10E => s.serialize_f64(std::f64::consts::LOG10_E),
|
||||
Self::MathLog210 => s.serialize_f64(std::f64::consts::LOG2_10),
|
||||
Self::MathLog2E => s.serialize_f64(std::f64::consts::LOG2_E),
|
||||
Self::MathPi => s.serialize_f64(std::f64::consts::PI),
|
||||
Self::MathSqrt2 => s.serialize_f64(std::f64::consts::SQRT_2),
|
||||
Self::MathTau => s.serialize_f64(std::f64::consts::TAU),
|
||||
}
|
||||
}
|
||||
match self {
|
||||
Self::MathE => s.serialize_unit_variant(TOKEN, 0, "MathE"),
|
||||
Self::MathFrac1Pi => s.serialize_unit_variant(TOKEN, 1, "MathFrac1Pi"),
|
||||
Self::MathFrac1Sqrt2 => s.serialize_unit_variant(TOKEN, 2, "MathFrac1Sqrt2"),
|
||||
Self::MathFrac2Pi => s.serialize_unit_variant(TOKEN, 3, "MathFrac2Pi"),
|
||||
Self::MathFrac2SqrtPi => s.serialize_unit_variant(TOKEN, 4, "MathFrac2SqrtPi"),
|
||||
Self::MathFracPi2 => s.serialize_unit_variant(TOKEN, 5, "MathFracPi2"),
|
||||
Self::MathFracPi3 => s.serialize_unit_variant(TOKEN, 6, "MathFracPi3"),
|
||||
Self::MathFracPi4 => s.serialize_unit_variant(TOKEN, 7, "MathFracPi4"),
|
||||
Self::MathFracPi6 => s.serialize_unit_variant(TOKEN, 8, "MathFracPi6"),
|
||||
Self::MathFracPi8 => s.serialize_unit_variant(TOKEN, 9, "MathFracPi8"),
|
||||
Self::MathLn10 => s.serialize_unit_variant(TOKEN, 10, "MathLn10"),
|
||||
Self::MathLn2 => s.serialize_unit_variant(TOKEN, 11, "MathLn2"),
|
||||
Self::MathLog102 => s.serialize_unit_variant(TOKEN, 12, "MathLog102"),
|
||||
Self::MathLog10E => s.serialize_unit_variant(TOKEN, 13, "MathLog10E"),
|
||||
Self::MathLog210 => s.serialize_unit_variant(TOKEN, 14, "MathLog210"),
|
||||
Self::MathLog2E => s.serialize_unit_variant(TOKEN, 15, "MathLog2E"),
|
||||
Self::MathPi => s.serialize_unit_variant(TOKEN, 16, "MathPi"),
|
||||
Self::MathSqrt2 => s.serialize_unit_variant(TOKEN, 17, "MathSqrt2"),
|
||||
Self::MathTau => s.serialize_unit_variant(TOKEN, 18, "MathTau"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,6 @@ use crate::sql::common::{take_digits, take_digits_range, take_u32_len};
|
|||
use crate::sql::duration::Duration;
|
||||
use crate::sql::error::IResult;
|
||||
use crate::sql::escape::escape_str;
|
||||
use crate::sql::serde::is_internal_serialization;
|
||||
use crate::sql::strand::Strand;
|
||||
use chrono::{DateTime, FixedOffset, Offset, SecondsFormat, TimeZone, Utc};
|
||||
use chrono::{NaiveDate, NaiveDateTime, NaiveTime};
|
||||
|
@ -21,7 +20,8 @@ use std::str::FromStr;
|
|||
|
||||
pub(crate) const TOKEN: &str = "$surrealdb::private::sql::Datetime";
|
||||
|
||||
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Deserialize, Hash)]
|
||||
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Serialize, Deserialize, Hash)]
|
||||
#[serde(rename = "$surrealdb::private::sql::Datetime")]
|
||||
pub struct Datetime(pub DateTime<Utc>);
|
||||
|
||||
impl Default for Datetime {
|
||||
|
@ -93,19 +93,6 @@ impl Display for Datetime {
|
|||
}
|
||||
}
|
||||
|
||||
impl Serialize for Datetime {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: serde::Serializer,
|
||||
{
|
||||
if is_internal_serialization() {
|
||||
serializer.serialize_newtype_struct(TOKEN, &self.0)
|
||||
} else {
|
||||
serializer.serialize_some(&self.0)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ops::Sub<Self> for Datetime {
|
||||
type Output = Duration;
|
||||
fn sub(self, other: Self) -> Duration {
|
||||
|
|
|
@ -2,7 +2,6 @@ use crate::sql::common::take_u64;
|
|||
use crate::sql::datetime::Datetime;
|
||||
use crate::sql::ending::duration as ending;
|
||||
use crate::sql::error::IResult;
|
||||
use crate::sql::serde::is_internal_serialization;
|
||||
use crate::sql::strand::Strand;
|
||||
use nom::branch::alt;
|
||||
use nom::bytes::complete::tag;
|
||||
|
@ -24,7 +23,8 @@ static NANOSECONDS_PER_MILLISECOND: u32 = 1000000;
|
|||
|
||||
pub(crate) const TOKEN: &str = "$surrealdb::private::sql::Duration";
|
||||
|
||||
#[derive(Clone, Debug, Default, Eq, PartialEq, PartialOrd, Deserialize, Hash)]
|
||||
#[derive(Clone, Debug, Default, Eq, PartialEq, PartialOrd, Serialize, Deserialize, Hash)]
|
||||
#[serde(rename = "$surrealdb::private::sql::Duration")]
|
||||
pub struct Duration(pub time::Duration);
|
||||
|
||||
impl From<time::Duration> for Duration {
|
||||
|
@ -208,19 +208,6 @@ impl fmt::Display for Duration {
|
|||
}
|
||||
}
|
||||
|
||||
impl Serialize for Duration {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: serde::Serializer,
|
||||
{
|
||||
if is_internal_serialization() {
|
||||
serializer.serialize_newtype_struct(TOKEN, &self.0)
|
||||
} else {
|
||||
serializer.serialize_some(&self.to_string())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ops::Add for Duration {
|
||||
type Output = Self;
|
||||
fn add(self, other: Self) -> Self {
|
||||
|
|
|
@ -1,19 +1,18 @@
|
|||
use crate::sql::comment::mightbespace;
|
||||
use crate::sql::dir::{dir, Dir};
|
||||
use crate::sql::error::IResult;
|
||||
use crate::sql::serde::is_internal_serialization;
|
||||
use crate::sql::table::{table, tables, Tables};
|
||||
use crate::sql::thing::{thing, Thing};
|
||||
use nom::branch::alt;
|
||||
use nom::character::complete::char;
|
||||
use nom::combinator::map;
|
||||
use serde::ser::SerializeStruct;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::fmt;
|
||||
|
||||
pub(crate) const TOKEN: &str = "$surrealdb::private::sql::Edges";
|
||||
|
||||
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Deserialize, Hash)]
|
||||
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Serialize, Deserialize, Hash)]
|
||||
#[serde(rename = "$surrealdb::private::sql::Edges")]
|
||||
pub struct Edges {
|
||||
pub dir: Dir,
|
||||
pub from: Thing,
|
||||
|
@ -30,23 +29,6 @@ impl fmt::Display for Edges {
|
|||
}
|
||||
}
|
||||
|
||||
impl Serialize for Edges {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: serde::Serializer,
|
||||
{
|
||||
if is_internal_serialization() {
|
||||
let mut val = serializer.serialize_struct(TOKEN, 3)?;
|
||||
val.serialize_field("dir", &self.dir)?;
|
||||
val.serialize_field("from", &self.from)?;
|
||||
val.serialize_field("what", &self.what)?;
|
||||
val.end()
|
||||
} else {
|
||||
serializer.serialize_none()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn edges(i: &str) -> IResult<&str, Edges> {
|
||||
let (i, from) = thing(i)?;
|
||||
let (i, dir) = dir(i)?;
|
||||
|
|
|
@ -5,16 +5,15 @@ use crate::err::Error;
|
|||
use crate::fnc;
|
||||
use crate::sql::error::IResult;
|
||||
use crate::sql::operator::{operator, Operator};
|
||||
use crate::sql::serde::is_internal_serialization;
|
||||
use crate::sql::value::{single, value, Value};
|
||||
use serde::ser::SerializeStruct;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::fmt;
|
||||
use std::str;
|
||||
|
||||
pub(crate) const TOKEN: &str = "$surrealdb::private::sql::Expression";
|
||||
|
||||
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Deserialize, Hash)]
|
||||
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Serialize, Deserialize, Hash)]
|
||||
#[serde(rename = "$surrealdb::private::sql::Expression")]
|
||||
pub struct Expression {
|
||||
pub l: Value,
|
||||
pub o: Operator,
|
||||
|
@ -139,23 +138,6 @@ impl fmt::Display for Expression {
|
|||
}
|
||||
}
|
||||
|
||||
impl Serialize for Expression {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: serde::Serializer,
|
||||
{
|
||||
if is_internal_serialization() {
|
||||
let mut val = serializer.serialize_struct(TOKEN, 3)?;
|
||||
val.serialize_field("l", &self.l)?;
|
||||
val.serialize_field("o", &self.o)?;
|
||||
val.serialize_field("r", &self.r)?;
|
||||
val.end()
|
||||
} else {
|
||||
serializer.serialize_none()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn expression(i: &str) -> IResult<&str, Expression> {
|
||||
let (i, l) = single(i)?;
|
||||
let (i, o) = operator(i)?;
|
||||
|
|
|
@ -11,7 +11,6 @@ use crate::sql::fmt::Fmt;
|
|||
use crate::sql::idiom::Idiom;
|
||||
use crate::sql::kind::{kind, Kind};
|
||||
use crate::sql::script::{script as func, Script};
|
||||
use crate::sql::serde::is_internal_serialization;
|
||||
use crate::sql::value::{single, value, Value};
|
||||
use async_recursion::async_recursion;
|
||||
use futures::future::try_join_all;
|
||||
|
@ -227,38 +226,31 @@ impl Serialize for Function {
|
|||
where
|
||||
S: serde::Serializer,
|
||||
{
|
||||
if is_internal_serialization() {
|
||||
match self {
|
||||
Self::Cast(s, e) => {
|
||||
let mut serializer = serializer.serialize_tuple_variant(TOKEN, 0, "Cast", 2)?;
|
||||
serializer.serialize_field(s)?;
|
||||
serializer.serialize_field(e)?;
|
||||
serializer.end()
|
||||
}
|
||||
Self::Normal(s, e) => {
|
||||
let mut serializer =
|
||||
serializer.serialize_tuple_variant(TOKEN, 1, "Normal", 2)?;
|
||||
serializer.serialize_field(s)?;
|
||||
serializer.serialize_field(e)?;
|
||||
serializer.end()
|
||||
}
|
||||
Self::Custom(s, e) => {
|
||||
let mut serializer =
|
||||
serializer.serialize_tuple_variant(TOKEN, 2, "Custom", 2)?;
|
||||
serializer.serialize_field(s)?;
|
||||
serializer.serialize_field(e)?;
|
||||
serializer.end()
|
||||
}
|
||||
Self::Script(s, e) => {
|
||||
let mut serializer =
|
||||
serializer.serialize_tuple_variant(TOKEN, 3, "Script", 2)?;
|
||||
serializer.serialize_field(s)?;
|
||||
serializer.serialize_field(e)?;
|
||||
serializer.end()
|
||||
}
|
||||
match self {
|
||||
Self::Cast(s, e) => {
|
||||
let mut serializer = serializer.serialize_tuple_variant(TOKEN, 0, "Cast", 2)?;
|
||||
serializer.serialize_field(s)?;
|
||||
serializer.serialize_field(e)?;
|
||||
serializer.end()
|
||||
}
|
||||
Self::Normal(s, e) => {
|
||||
let mut serializer = serializer.serialize_tuple_variant(TOKEN, 1, "Normal", 2)?;
|
||||
serializer.serialize_field(s)?;
|
||||
serializer.serialize_field(e)?;
|
||||
serializer.end()
|
||||
}
|
||||
Self::Custom(s, e) => {
|
||||
let mut serializer = serializer.serialize_tuple_variant(TOKEN, 2, "Custom", 2)?;
|
||||
serializer.serialize_field(s)?;
|
||||
serializer.serialize_field(e)?;
|
||||
serializer.end()
|
||||
}
|
||||
Self::Script(s, e) => {
|
||||
let mut serializer = serializer.serialize_tuple_variant(TOKEN, 3, "Script", 2)?;
|
||||
serializer.serialize_field(s)?;
|
||||
serializer.serialize_field(e)?;
|
||||
serializer.end()
|
||||
}
|
||||
} else {
|
||||
serializer.serialize_none()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,7 +5,6 @@ use crate::err::Error;
|
|||
use crate::sql::block::{block, Block};
|
||||
use crate::sql::comment::mightbespace;
|
||||
use crate::sql::error::IResult;
|
||||
use crate::sql::serde::is_internal_serialization;
|
||||
use crate::sql::value::Value;
|
||||
use nom::bytes::complete::tag;
|
||||
use nom::character::complete::char;
|
||||
|
@ -14,7 +13,8 @@ use std::fmt;
|
|||
|
||||
pub(crate) const TOKEN: &str = "$surrealdb::private::sql::Future";
|
||||
|
||||
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Deserialize, Hash)]
|
||||
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Serialize, Deserialize, Hash)]
|
||||
#[serde(rename = "$surrealdb::private::sql::Future")]
|
||||
pub struct Future(pub Block);
|
||||
|
||||
impl From<Value> for Future {
|
||||
|
@ -47,19 +47,6 @@ impl fmt::Display for Future {
|
|||
}
|
||||
}
|
||||
|
||||
impl Serialize for Future {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: serde::Serializer,
|
||||
{
|
||||
if is_internal_serialization() {
|
||||
serializer.serialize_newtype_struct(TOKEN, &self.0)
|
||||
} else {
|
||||
serializer.serialize_none()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn future(i: &str) -> IResult<&str, Future> {
|
||||
let (i, _) = char('<')(i)?;
|
||||
let (i, _) = tag("future")(i)?;
|
||||
|
|
|
@ -4,7 +4,6 @@ use crate::sql::comment::mightbespace;
|
|||
use crate::sql::common::commas;
|
||||
use crate::sql::error::IResult;
|
||||
use crate::sql::fmt::Fmt;
|
||||
use crate::sql::serde::is_internal_serialization;
|
||||
use geo::algorithm::contains::Contains;
|
||||
use geo::algorithm::intersects::Intersects;
|
||||
use geo::{Coord, LineString, Point, Polygon};
|
||||
|
@ -18,7 +17,6 @@ use nom::multi::separated_list1;
|
|||
use nom::number::complete::double;
|
||||
use nom::sequence::delimited;
|
||||
use nom::sequence::preceded;
|
||||
use serde::ser::SerializeMap;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::cmp::Ordering;
|
||||
use std::iter::{once, FromIterator};
|
||||
|
@ -471,134 +469,14 @@ impl Serialize for Geometry {
|
|||
where
|
||||
S: serde::Serializer,
|
||||
{
|
||||
if is_internal_serialization() {
|
||||
match self {
|
||||
Self::Point(v) => s.serialize_newtype_variant(TOKEN, 0, "Point", v),
|
||||
Self::Line(v) => s.serialize_newtype_variant(TOKEN, 1, "Line", v),
|
||||
Self::Polygon(v) => s.serialize_newtype_variant(TOKEN, 2, "Polygon", v),
|
||||
Self::MultiPoint(v) => s.serialize_newtype_variant(TOKEN, 3, "MultiPoint", v),
|
||||
Self::MultiLine(v) => s.serialize_newtype_variant(TOKEN, 4, "MultiLine", v),
|
||||
Self::MultiPolygon(v) => s.serialize_newtype_variant(TOKEN, 5, "MultiPolygon", v),
|
||||
Self::Collection(v) => s.serialize_newtype_variant(TOKEN, 6, "Collection", v),
|
||||
}
|
||||
} else {
|
||||
match self {
|
||||
Self::Point(v) => {
|
||||
let mut map = s.serialize_map(Some(2))?;
|
||||
map.serialize_key("type")?;
|
||||
map.serialize_value("Point")?;
|
||||
map.serialize_key("coordinates")?;
|
||||
map.serialize_value(vec![v.x(), v.y()].as_slice())?;
|
||||
map.end()
|
||||
}
|
||||
Self::Line(v) => {
|
||||
let mut map = s.serialize_map(Some(2))?;
|
||||
map.serialize_key("type")?;
|
||||
map.serialize_value("LineString")?;
|
||||
map.serialize_key("coordinates")?;
|
||||
map.serialize_value(
|
||||
v.points()
|
||||
.map(|p| vec![p.x(), p.y()])
|
||||
.collect::<Vec<Vec<f64>>>()
|
||||
.as_slice(),
|
||||
)?;
|
||||
map.end()
|
||||
}
|
||||
Self::Polygon(v) => {
|
||||
let mut map = s.serialize_map(Some(2))?;
|
||||
map.serialize_key("type")?;
|
||||
map.serialize_value("Polygon")?;
|
||||
map.serialize_key("coordinates")?;
|
||||
map.serialize_value(
|
||||
vec![v
|
||||
.exterior()
|
||||
.points()
|
||||
.map(|p| vec![p.x(), p.y()])
|
||||
.collect::<Vec<Vec<f64>>>()]
|
||||
.into_iter()
|
||||
.chain(
|
||||
v.interiors()
|
||||
.iter()
|
||||
.map(|i| {
|
||||
i.points()
|
||||
.map(|p| vec![p.x(), p.y()])
|
||||
.collect::<Vec<Vec<f64>>>()
|
||||
})
|
||||
.collect::<Vec<Vec<Vec<f64>>>>(),
|
||||
)
|
||||
.collect::<Vec<Vec<Vec<f64>>>>()
|
||||
.as_slice(),
|
||||
)?;
|
||||
map.end()
|
||||
}
|
||||
Self::MultiPoint(v) => {
|
||||
let mut map = s.serialize_map(Some(2))?;
|
||||
map.serialize_key("type")?;
|
||||
map.serialize_value("MultiPoint")?;
|
||||
map.serialize_key("coordinates")?;
|
||||
map.serialize_value(
|
||||
v.0.iter()
|
||||
.map(|v| vec![v.x(), v.y()])
|
||||
.collect::<Vec<Vec<f64>>>()
|
||||
.as_slice(),
|
||||
)?;
|
||||
map.end()
|
||||
}
|
||||
Self::MultiLine(v) => {
|
||||
let mut map = s.serialize_map(Some(2))?;
|
||||
map.serialize_key("type")?;
|
||||
map.serialize_value("MultiLineString")?;
|
||||
map.serialize_key("coordinates")?;
|
||||
map.serialize_value(
|
||||
v.0.iter()
|
||||
.map(|v| {
|
||||
v.points().map(|v| vec![v.x(), v.y()]).collect::<Vec<Vec<f64>>>()
|
||||
})
|
||||
.collect::<Vec<Vec<Vec<f64>>>>()
|
||||
.as_slice(),
|
||||
)?;
|
||||
map.end()
|
||||
}
|
||||
Self::MultiPolygon(v) => {
|
||||
let mut map = s.serialize_map(Some(2))?;
|
||||
map.serialize_key("type")?;
|
||||
map.serialize_value("MultiPolygon")?;
|
||||
map.serialize_key("coordinates")?;
|
||||
map.serialize_value(
|
||||
v.0.iter()
|
||||
.map(|v| {
|
||||
vec![v
|
||||
.exterior()
|
||||
.points()
|
||||
.map(|p| vec![p.x(), p.y()])
|
||||
.collect::<Vec<Vec<f64>>>()]
|
||||
.into_iter()
|
||||
.chain(
|
||||
v.interiors()
|
||||
.iter()
|
||||
.map(|i| {
|
||||
i.points()
|
||||
.map(|p| vec![p.x(), p.y()])
|
||||
.collect::<Vec<Vec<f64>>>()
|
||||
})
|
||||
.collect::<Vec<Vec<Vec<f64>>>>(),
|
||||
)
|
||||
.collect::<Vec<Vec<Vec<f64>>>>()
|
||||
})
|
||||
.collect::<Vec<Vec<Vec<Vec<f64>>>>>()
|
||||
.as_slice(),
|
||||
)?;
|
||||
map.end()
|
||||
}
|
||||
Self::Collection(v) => {
|
||||
let mut map = s.serialize_map(Some(2))?;
|
||||
map.serialize_key("type")?;
|
||||
map.serialize_value("GeometryCollection")?;
|
||||
map.serialize_key("geometries")?;
|
||||
map.serialize_value(v)?;
|
||||
map.end()
|
||||
}
|
||||
}
|
||||
match self {
|
||||
Self::Point(v) => s.serialize_newtype_variant(TOKEN, 0, "Point", v),
|
||||
Self::Line(v) => s.serialize_newtype_variant(TOKEN, 1, "Line", v),
|
||||
Self::Polygon(v) => s.serialize_newtype_variant(TOKEN, 2, "Polygon", v),
|
||||
Self::MultiPoint(v) => s.serialize_newtype_variant(TOKEN, 3, "MultiPoint", v),
|
||||
Self::MultiLine(v) => s.serialize_newtype_variant(TOKEN, 4, "MultiLine", v),
|
||||
Self::MultiPolygon(v) => s.serialize_newtype_variant(TOKEN, 5, "MultiPolygon", v),
|
||||
Self::Collection(v) => s.serialize_newtype_variant(TOKEN, 6, "Collection", v),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,7 +8,6 @@ use crate::sql::fmt::{fmt_separated_by, Fmt};
|
|||
use crate::sql::part::Next;
|
||||
use crate::sql::part::{all, field, first, graph, index, last, part, value, Part};
|
||||
use crate::sql::paths::{ID, IN, META, OUT};
|
||||
use crate::sql::serde::is_internal_serialization;
|
||||
use crate::sql::value::Value;
|
||||
use md5::Digest;
|
||||
use md5::Md5;
|
||||
|
@ -43,7 +42,8 @@ pub fn locals(i: &str) -> IResult<&str, Idioms> {
|
|||
Ok((i, Idioms(v)))
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Default, Eq, PartialEq, PartialOrd, Deserialize, Hash)]
|
||||
#[derive(Clone, Debug, Default, Eq, PartialEq, PartialOrd, Serialize, Deserialize, Hash)]
|
||||
#[serde(rename = "$surrealdb::private::sql::Idiom")]
|
||||
pub struct Idiom(pub Vec<Part>);
|
||||
|
||||
impl Deref for Idiom {
|
||||
|
@ -168,19 +168,6 @@ impl Display for Idiom {
|
|||
}
|
||||
}
|
||||
|
||||
impl Serialize for Idiom {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: serde::Serializer,
|
||||
{
|
||||
if is_internal_serialization() {
|
||||
serializer.serialize_newtype_struct(TOKEN, &self.0)
|
||||
} else {
|
||||
serializer.serialize_none()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Used in DEFINE FIELD and DEFINE INDEX clauses
|
||||
pub fn local(i: &str) -> IResult<&str, Idiom> {
|
||||
let (i, p) = first(i)?;
|
||||
|
|
|
@ -64,7 +64,6 @@ pub(crate) mod view;
|
|||
#[cfg(test)]
|
||||
pub(crate) mod test;
|
||||
|
||||
pub mod serde;
|
||||
pub mod statements;
|
||||
|
||||
pub use self::parser::*;
|
||||
|
@ -132,4 +131,4 @@ pub use self::value::Values;
|
|||
pub use self::version::Version;
|
||||
pub use self::view::View;
|
||||
|
||||
pub(crate) use self::value::serde::to_value;
|
||||
pub use self::value::serde::to_value;
|
||||
|
|
|
@ -3,7 +3,6 @@ use crate::sql::error::IResult;
|
|||
use crate::sql::escape::escape_ident;
|
||||
use crate::sql::id::Id;
|
||||
use crate::sql::ident::ident_raw;
|
||||
use crate::sql::serde::is_internal_serialization;
|
||||
use crate::sql::thing::Thing;
|
||||
use nom::branch::alt;
|
||||
use nom::character::complete::char;
|
||||
|
@ -83,26 +82,20 @@ impl Serialize for Model {
|
|||
where
|
||||
S: serde::Serializer,
|
||||
{
|
||||
if is_internal_serialization() {
|
||||
match self {
|
||||
Self::Count(tb, c) => {
|
||||
let mut serializer =
|
||||
serializer.serialize_tuple_variant(TOKEN, 0, "Count", 2)?;
|
||||
serializer.serialize_field(tb)?;
|
||||
serializer.serialize_field(c)?;
|
||||
serializer.end()
|
||||
}
|
||||
Self::Range(tb, b, e) => {
|
||||
let mut serializer =
|
||||
serializer.serialize_tuple_variant(TOKEN, 1, "Range", 3)?;
|
||||
serializer.serialize_field(tb)?;
|
||||
serializer.serialize_field(b)?;
|
||||
serializer.serialize_field(e)?;
|
||||
serializer.end()
|
||||
}
|
||||
match self {
|
||||
Self::Count(tb, c) => {
|
||||
let mut serializer = serializer.serialize_tuple_variant(TOKEN, 0, "Count", 2)?;
|
||||
serializer.serialize_field(tb)?;
|
||||
serializer.serialize_field(c)?;
|
||||
serializer.end()
|
||||
}
|
||||
Self::Range(tb, b, e) => {
|
||||
let mut serializer = serializer.serialize_tuple_variant(TOKEN, 1, "Range", 3)?;
|
||||
serializer.serialize_field(tb)?;
|
||||
serializer.serialize_field(b)?;
|
||||
serializer.serialize_field(e)?;
|
||||
serializer.end()
|
||||
}
|
||||
} else {
|
||||
serializer.serialize_none()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,6 @@ use crate::err::Error;
|
|||
use crate::sql::ending::number as ending;
|
||||
use crate::sql::error::Error::Parser;
|
||||
use crate::sql::error::IResult;
|
||||
use crate::sql::serde::is_internal_serialization;
|
||||
use crate::sql::strand::Strand;
|
||||
use bigdecimal::num_traits::Pow;
|
||||
use bigdecimal::BigDecimal;
|
||||
|
@ -172,18 +171,10 @@ impl Serialize for Number {
|
|||
where
|
||||
S: serde::Serializer,
|
||||
{
|
||||
if is_internal_serialization() {
|
||||
match self {
|
||||
Number::Int(v) => s.serialize_newtype_variant(TOKEN, 0, "Int", v),
|
||||
Number::Float(v) => s.serialize_newtype_variant(TOKEN, 1, "Float", v),
|
||||
Number::Decimal(v) => s.serialize_newtype_variant(TOKEN, 2, "Decimal", v),
|
||||
}
|
||||
} else {
|
||||
match self {
|
||||
Number::Int(v) => s.serialize_i64(*v),
|
||||
Number::Float(v) => s.serialize_f64(*v),
|
||||
Number::Decimal(v) => s.serialize_some(v),
|
||||
}
|
||||
match self {
|
||||
Number::Int(v) => s.serialize_newtype_variant(TOKEN, 0, "Int", v),
|
||||
Number::Float(v) => s.serialize_newtype_variant(TOKEN, 1, "Float", v),
|
||||
Number::Decimal(v) => s.serialize_newtype_variant(TOKEN, 2, "Decimal", v),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,7 +8,6 @@ use crate::sql::error::IResult;
|
|||
use crate::sql::escape::escape_key;
|
||||
use crate::sql::fmt::{is_pretty, pretty_indent, Fmt, Pretty};
|
||||
use crate::sql::operation::{Op, Operation};
|
||||
use crate::sql::serde::is_internal_serialization;
|
||||
use crate::sql::thing::Thing;
|
||||
use crate::sql::value::{value, Value};
|
||||
use nom::branch::alt;
|
||||
|
@ -18,7 +17,6 @@ use nom::character::complete::char;
|
|||
use nom::combinator::opt;
|
||||
use nom::multi::separated_list0;
|
||||
use nom::sequence::delimited;
|
||||
use serde::ser::SerializeMap;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::collections::BTreeMap;
|
||||
use std::collections::HashMap;
|
||||
|
@ -28,7 +26,8 @@ use std::ops::DerefMut;
|
|||
|
||||
pub(crate) const TOKEN: &str = "$surrealdb::private::sql::Object";
|
||||
|
||||
#[derive(Clone, Debug, Default, Eq, Ord, PartialEq, PartialOrd, Deserialize, Hash)]
|
||||
#[derive(Clone, Debug, Default, Eq, Ord, PartialEq, PartialOrd, Serialize, Deserialize, Hash)]
|
||||
#[serde(rename = "$surrealdb::private::sql::Object")]
|
||||
pub struct Object(pub BTreeMap<String, Value>);
|
||||
|
||||
impl From<BTreeMap<String, Value>> for Object {
|
||||
|
@ -168,24 +167,6 @@ impl Display for Object {
|
|||
}
|
||||
}
|
||||
|
||||
impl Serialize for Object {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: serde::Serializer,
|
||||
{
|
||||
if is_internal_serialization() {
|
||||
serializer.serialize_newtype_struct(TOKEN, &self.0)
|
||||
} else {
|
||||
let mut map = serializer.serialize_map(Some(self.len()))?;
|
||||
for (k, v) in &self.0 {
|
||||
map.serialize_key(k)?;
|
||||
map.serialize_value(v)?;
|
||||
}
|
||||
map.end()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn object(i: &str) -> IResult<&str, Object> {
|
||||
let (i, _) = char('{')(i)?;
|
||||
let (i, _) = mightbespace(i)?;
|
||||
|
|
|
@ -4,7 +4,6 @@ use crate::dbs::Transaction;
|
|||
use crate::err::Error;
|
||||
use crate::sql::error::IResult;
|
||||
use crate::sql::ident::{ident, Ident};
|
||||
use crate::sql::serde::is_internal_serialization;
|
||||
use crate::sql::value::Value;
|
||||
use nom::character::complete::char;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
@ -14,7 +13,8 @@ use std::str;
|
|||
|
||||
pub(crate) const TOKEN: &str = "$surrealdb::private::sql::Param";
|
||||
|
||||
#[derive(Clone, Debug, Default, Eq, PartialEq, PartialOrd, Deserialize, Hash)]
|
||||
#[derive(Clone, Debug, Default, Eq, PartialEq, PartialOrd, Serialize, Deserialize, Hash)]
|
||||
#[serde(rename = "$surrealdb::private::sql::Param")]
|
||||
pub struct Param(pub Ident);
|
||||
|
||||
impl From<Ident> for Param {
|
||||
|
@ -90,19 +90,6 @@ impl fmt::Display for Param {
|
|||
}
|
||||
}
|
||||
|
||||
impl Serialize for Param {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: serde::Serializer,
|
||||
{
|
||||
if is_internal_serialization() {
|
||||
serializer.serialize_newtype_struct(TOKEN, &self.0)
|
||||
} else {
|
||||
serializer.serialize_none()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn param(i: &str) -> IResult<&str, Param> {
|
||||
let (i, _) = char('$')(i)?;
|
||||
let (i, v) = ident(i)?;
|
||||
|
|
|
@ -5,7 +5,6 @@ use crate::err::Error;
|
|||
use crate::sql::error::IResult;
|
||||
use crate::sql::id::{id, Id};
|
||||
use crate::sql::ident::ident_raw;
|
||||
use crate::sql::serde::is_internal_serialization;
|
||||
use crate::sql::value::Value;
|
||||
use nom::branch::alt;
|
||||
use nom::character::complete::char;
|
||||
|
@ -13,7 +12,6 @@ use nom::combinator::map;
|
|||
use nom::combinator::opt;
|
||||
use nom::sequence::preceded;
|
||||
use nom::sequence::terminated;
|
||||
use serde::ser::SerializeStruct;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::cmp::Ordering;
|
||||
use std::fmt;
|
||||
|
@ -21,7 +19,8 @@ use std::ops::Bound;
|
|||
|
||||
pub(crate) const TOKEN: &str = "$surrealdb::private::sql::Range";
|
||||
|
||||
#[derive(Clone, Debug, Eq, PartialEq, Deserialize, Hash)]
|
||||
#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize, Hash)]
|
||||
#[serde(rename = "$surrealdb::private::sql::Range")]
|
||||
pub struct Range {
|
||||
pub tb: String,
|
||||
pub beg: Bound<Id>,
|
||||
|
@ -126,23 +125,6 @@ impl fmt::Display for Range {
|
|||
}
|
||||
}
|
||||
|
||||
impl Serialize for Range {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: serde::Serializer,
|
||||
{
|
||||
if is_internal_serialization() {
|
||||
let mut val = serializer.serialize_struct(TOKEN, 3)?;
|
||||
val.serialize_field("tb", &self.tb)?;
|
||||
val.serialize_field("beg", &self.beg)?;
|
||||
val.serialize_field("end", &self.end)?;
|
||||
val.end()
|
||||
} else {
|
||||
serializer.serialize_none()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn range(i: &str) -> IResult<&str, Range> {
|
||||
let (i, tb) = ident_raw(i)?;
|
||||
let (i, _) = char(':')(i)?;
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
use crate::sql::error::IResult;
|
||||
use crate::sql::serde::is_internal_serialization;
|
||||
use nom::bytes::complete::escaped;
|
||||
use nom::bytes::complete::is_not;
|
||||
use nom::character::complete::anychar;
|
||||
|
@ -78,11 +77,7 @@ impl Serialize for Regex {
|
|||
where
|
||||
S: Serializer,
|
||||
{
|
||||
if is_internal_serialization() {
|
||||
serializer.serialize_newtype_struct(TOKEN, self.0.as_str())
|
||||
} else {
|
||||
serializer.serialize_none()
|
||||
}
|
||||
serializer.serialize_newtype_struct(TOKEN, self.0.as_str())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,48 +0,0 @@
|
|||
use std::sync::atomic::AtomicBool;
|
||||
use std::sync::atomic::Ordering;
|
||||
|
||||
thread_local! {
|
||||
static INTERNAL_SERIALIZATION: AtomicBool = AtomicBool::new(false);
|
||||
}
|
||||
|
||||
/// *Advanced use only*. Enables a function to be run, whilst ensuring
|
||||
/// that internal serialization is enabled for [`Value`](crate::sql::Value)
|
||||
/// types. When using internal serialization the non-simplified
|
||||
/// [`Value`](crate::sql::Value) type information is used, for
|
||||
/// serialization to storage or for use in the binary WebSocket protocol.
|
||||
pub fn serialize_internal<T, F: FnOnce() -> T>(f: F) -> T {
|
||||
beg_internal_serialization();
|
||||
let out = f();
|
||||
end_internal_serialization();
|
||||
out
|
||||
}
|
||||
|
||||
/// *Advanced use only*. Checks if internal serialization is enabled for
|
||||
/// [`Value`](crate::sql::Value) types. When using internal serialization
|
||||
/// the non-simplified [`Value`](crate::sql::Value) type information is
|
||||
/// used, for serialization to storage or for use in the binary WebSocket
|
||||
/// protocol.
|
||||
#[inline]
|
||||
pub(crate) fn is_internal_serialization() -> bool {
|
||||
INTERNAL_SERIALIZATION.with(|v| v.load(Ordering::Relaxed))
|
||||
}
|
||||
|
||||
/// *Advanced use only*. Marks the beginning of internal serialization for
|
||||
/// [`Value`](crate::sql::Value) types. When using internal serialization
|
||||
/// the non-simplified [`Value`](crate::sql::Value) type information is
|
||||
/// used, for serialization to storage or for use in the binary WebSocket
|
||||
/// protocol.
|
||||
#[inline]
|
||||
pub(crate) fn beg_internal_serialization() {
|
||||
INTERNAL_SERIALIZATION.with(|v| v.store(true, Ordering::Relaxed))
|
||||
}
|
||||
|
||||
/// *Advanced use only*. Marks the end of internal serialization for
|
||||
/// [`Value`](crate::sql::Value) types. When using internal serialization
|
||||
/// the non-simplified [`Value`](crate::sql::Value) type information is
|
||||
/// used, for serialization to storage or for use in the binary WebSocket
|
||||
/// protocol.
|
||||
#[inline]
|
||||
pub(crate) fn end_internal_serialization() {
|
||||
INTERNAL_SERIALIZATION.with(|v| v.store(false, Ordering::Relaxed))
|
||||
}
|
|
@ -1,7 +1,6 @@
|
|||
use crate::sql::error::Error::Parser;
|
||||
use crate::sql::error::IResult;
|
||||
use crate::sql::escape::escape_str;
|
||||
use crate::sql::serde::is_internal_serialization;
|
||||
use nom::branch::alt;
|
||||
use nom::bytes::complete::escaped_transform;
|
||||
use nom::bytes::complete::is_not;
|
||||
|
@ -25,7 +24,8 @@ const DOUBLE_ESC: &str = r#"\""#;
|
|||
|
||||
const SURROGATES: [u32; 2] = [55296, 57343];
|
||||
|
||||
#[derive(Clone, Debug, Default, Eq, PartialEq, PartialOrd, Deserialize, Hash)]
|
||||
#[derive(Clone, Debug, Default, Eq, PartialEq, PartialOrd, Serialize, Deserialize, Hash)]
|
||||
#[serde(rename = "$surrealdb::private::sql::Strand")]
|
||||
pub struct Strand(pub String);
|
||||
|
||||
impl From<String> for Strand {
|
||||
|
@ -74,19 +74,6 @@ impl Display for Strand {
|
|||
}
|
||||
}
|
||||
|
||||
impl Serialize for Strand {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: serde::Serializer,
|
||||
{
|
||||
if is_internal_serialization() {
|
||||
serializer.serialize_newtype_struct(TOKEN, &self.0)
|
||||
} else {
|
||||
serializer.serialize_some(&self.0)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ops::Add for Strand {
|
||||
type Output = Self;
|
||||
fn add(self, other: Self) -> Self {
|
||||
|
|
|
@ -5,7 +5,6 @@ use crate::err::Error;
|
|||
use crate::sql::comment::mightbespace;
|
||||
use crate::sql::ending::subquery as ending;
|
||||
use crate::sql::error::IResult;
|
||||
use crate::sql::serde::is_internal_serialization;
|
||||
use crate::sql::statements::create::{create, CreateStatement};
|
||||
use crate::sql::statements::delete::{delete, DeleteStatement};
|
||||
use crate::sql::statements::ifelse::{ifelse, IfelseStatement};
|
||||
|
@ -230,20 +229,16 @@ impl Serialize for Subquery {
|
|||
where
|
||||
S: serde::Serializer,
|
||||
{
|
||||
if is_internal_serialization() {
|
||||
match self {
|
||||
Self::Value(v) => serializer.serialize_newtype_variant(TOKEN, 0, "Value", v),
|
||||
Self::Ifelse(v) => serializer.serialize_newtype_variant(TOKEN, 1, "Ifelse", v),
|
||||
Self::Output(v) => serializer.serialize_newtype_variant(TOKEN, 2, "Output", v),
|
||||
Self::Select(v) => serializer.serialize_newtype_variant(TOKEN, 3, "Select", v),
|
||||
Self::Create(v) => serializer.serialize_newtype_variant(TOKEN, 4, "Create", v),
|
||||
Self::Update(v) => serializer.serialize_newtype_variant(TOKEN, 5, "Update", v),
|
||||
Self::Delete(v) => serializer.serialize_newtype_variant(TOKEN, 6, "Delete", v),
|
||||
Self::Relate(v) => serializer.serialize_newtype_variant(TOKEN, 7, "Relate", v),
|
||||
Self::Insert(v) => serializer.serialize_newtype_variant(TOKEN, 8, "Insert", v),
|
||||
}
|
||||
} else {
|
||||
serializer.serialize_none()
|
||||
match self {
|
||||
Self::Value(v) => serializer.serialize_newtype_variant(TOKEN, 0, "Value", v),
|
||||
Self::Ifelse(v) => serializer.serialize_newtype_variant(TOKEN, 1, "Ifelse", v),
|
||||
Self::Output(v) => serializer.serialize_newtype_variant(TOKEN, 2, "Output", v),
|
||||
Self::Select(v) => serializer.serialize_newtype_variant(TOKEN, 3, "Select", v),
|
||||
Self::Create(v) => serializer.serialize_newtype_variant(TOKEN, 4, "Create", v),
|
||||
Self::Update(v) => serializer.serialize_newtype_variant(TOKEN, 5, "Update", v),
|
||||
Self::Delete(v) => serializer.serialize_newtype_variant(TOKEN, 6, "Delete", v),
|
||||
Self::Relate(v) => serializer.serialize_newtype_variant(TOKEN, 7, "Relate", v),
|
||||
Self::Insert(v) => serializer.serialize_newtype_variant(TOKEN, 8, "Insert", v),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,7 +4,6 @@ use crate::sql::escape::escape_ident;
|
|||
use crate::sql::fmt::Fmt;
|
||||
use crate::sql::id::Id;
|
||||
use crate::sql::ident::{ident_raw, Ident};
|
||||
use crate::sql::serde::is_internal_serialization;
|
||||
use crate::sql::thing::Thing;
|
||||
use nom::multi::separated_list1;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
@ -41,7 +40,8 @@ pub fn tables(i: &str) -> IResult<&str, Tables> {
|
|||
Ok((i, Tables(v)))
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Default, Eq, PartialEq, PartialOrd, Deserialize, Hash)]
|
||||
#[derive(Clone, Debug, Default, Eq, PartialEq, PartialOrd, Serialize, Deserialize, Hash)]
|
||||
#[serde(rename = "$surrealdb::private::sql::Table")]
|
||||
pub struct Table(pub String);
|
||||
|
||||
impl From<String> for Table {
|
||||
|
@ -84,19 +84,6 @@ impl Display for Table {
|
|||
}
|
||||
}
|
||||
|
||||
impl Serialize for Table {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: serde::Serializer,
|
||||
{
|
||||
if is_internal_serialization() {
|
||||
serializer.serialize_newtype_struct(TOKEN, &self.0)
|
||||
} else {
|
||||
serializer.serialize_none()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn table(i: &str) -> IResult<&str, Table> {
|
||||
let (i, v) = ident_raw(i)?;
|
||||
Ok((i, Table(v)))
|
||||
|
|
|
@ -6,7 +6,6 @@ use crate::sql::error::IResult;
|
|||
use crate::sql::escape::escape_rid;
|
||||
use crate::sql::id::{id, Id};
|
||||
use crate::sql::ident::ident_raw;
|
||||
use crate::sql::serde::is_internal_serialization;
|
||||
use crate::sql::strand::Strand;
|
||||
use crate::sql::value::Value;
|
||||
use derive::Store;
|
||||
|
@ -15,14 +14,14 @@ use nom::bytes::complete::tag;
|
|||
use nom::character::complete::char;
|
||||
use nom::combinator::map;
|
||||
use nom::sequence::delimited;
|
||||
use serde::ser::SerializeStruct;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::fmt;
|
||||
use std::str::FromStr;
|
||||
|
||||
pub(crate) const TOKEN: &str = "$surrealdb::private::sql::Thing";
|
||||
|
||||
#[derive(Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Deserialize, Store, Hash)]
|
||||
#[derive(Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Serialize, Deserialize, Store, Hash)]
|
||||
#[serde(rename = "$surrealdb::private::sql::Thing")]
|
||||
pub struct Thing {
|
||||
pub tb: String,
|
||||
pub id: Id,
|
||||
|
@ -108,23 +107,6 @@ impl Thing {
|
|||
}
|
||||
}
|
||||
|
||||
impl Serialize for Thing {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: serde::Serializer,
|
||||
{
|
||||
if is_internal_serialization() {
|
||||
let mut val = serializer.serialize_struct(TOKEN, 2)?;
|
||||
val.serialize_field("tb", &self.tb)?;
|
||||
val.serialize_field("id", &self.id)?;
|
||||
val.end()
|
||||
} else {
|
||||
let output = self.to_string();
|
||||
serializer.serialize_some(&output)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn thing(i: &str) -> IResult<&str, Thing> {
|
||||
alt((thing_raw, thing_single, thing_double))(i)
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
use crate::sql::common::is_hex;
|
||||
use crate::sql::error::IResult;
|
||||
use crate::sql::escape::escape_str;
|
||||
use crate::sql::serde::is_internal_serialization;
|
||||
use crate::sql::strand::Strand;
|
||||
use nom::branch::alt;
|
||||
use nom::bytes::complete::take_while_m_n;
|
||||
|
@ -17,7 +16,8 @@ use std::str::FromStr;
|
|||
|
||||
pub(crate) const TOKEN: &str = "$surrealdb::private::sql::Uuid";
|
||||
|
||||
#[derive(Clone, Debug, Default, Eq, Ord, PartialEq, PartialOrd, Deserialize, Hash)]
|
||||
#[derive(Clone, Debug, Default, Eq, Ord, PartialEq, PartialOrd, Serialize, Deserialize, Hash)]
|
||||
#[serde(rename = "$surrealdb::private::sql::Uuid")]
|
||||
pub struct Uuid(pub uuid::Uuid);
|
||||
|
||||
impl From<uuid::Uuid> for Uuid {
|
||||
|
@ -103,19 +103,6 @@ impl Display for Uuid {
|
|||
}
|
||||
}
|
||||
|
||||
impl Serialize for Uuid {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: serde::Serializer,
|
||||
{
|
||||
if is_internal_serialization() {
|
||||
serializer.serialize_newtype_struct(TOKEN, &self.0)
|
||||
} else {
|
||||
serializer.serialize_some(&self.0)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn uuid(i: &str) -> IResult<&str, Uuid> {
|
||||
alt((uuid_single, uuid_double))(i)
|
||||
}
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
mod ser;
|
||||
|
||||
pub(crate) use ser::to_value;
|
||||
pub use ser::to_value;
|
||||
|
|
|
@ -69,77 +69,76 @@ impl ser::Serializer for Serializer {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::sql::serde::serialize_internal;
|
||||
use ser::Serializer as _;
|
||||
use serde::Serialize;
|
||||
|
||||
#[test]
|
||||
fn value() {
|
||||
let entry = Entry::Value(Default::default());
|
||||
let serialized = serialize_internal(|| entry.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = entry.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(entry, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn set() {
|
||||
let entry = Entry::Set(Default::default());
|
||||
let serialized = serialize_internal(|| entry.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = entry.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(entry, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ifelse() {
|
||||
let entry = Entry::Ifelse(Default::default());
|
||||
let serialized = serialize_internal(|| entry.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = entry.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(entry, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn select() {
|
||||
let entry = Entry::Select(Default::default());
|
||||
let serialized = serialize_internal(|| entry.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = entry.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(entry, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn create() {
|
||||
let entry = Entry::Create(Default::default());
|
||||
let serialized = serialize_internal(|| entry.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = entry.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(entry, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn update() {
|
||||
let entry = Entry::Update(Default::default());
|
||||
let serialized = serialize_internal(|| entry.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = entry.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(entry, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn delete() {
|
||||
let entry = Entry::Delete(Default::default());
|
||||
let serialized = serialize_internal(|| entry.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = entry.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(entry, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn relate() {
|
||||
let entry = Entry::Relate(Default::default());
|
||||
let serialized = serialize_internal(|| entry.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = entry.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(entry, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn insert() {
|
||||
let entry = Entry::Insert(Default::default());
|
||||
let serialized = serialize_internal(|| entry.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = entry.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(entry, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn output() {
|
||||
let entry = Entry::Output(Default::default());
|
||||
let serialized = serialize_internal(|| entry.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = entry.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(entry, serialized);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -60,19 +60,18 @@ impl serde::ser::SerializeSeq for SerializeEntryVec {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::sql::serde::serialize_internal;
|
||||
|
||||
#[test]
|
||||
fn empty() {
|
||||
let vec: Vec<Entry> = Vec::new();
|
||||
let serialized = serialize_internal(|| vec.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = vec.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(vec, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn vec() {
|
||||
let vec = vec![Entry::Value(Default::default())];
|
||||
let serialized = serialize_internal(|| vec.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = vec.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(vec, serialized);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,20 +37,19 @@ impl ser::Serializer for Serializer {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::sql::serde::serialize_internal;
|
||||
use ser::Serializer as _;
|
||||
|
||||
#[test]
|
||||
fn none() {
|
||||
let option: Option<Cond> = None;
|
||||
let serialized = serialize_internal(|| option.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = option.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(option, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn some() {
|
||||
let option = Some(Cond::default());
|
||||
let serialized = serialize_internal(|| option.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = option.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(option, serialized);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -55,140 +55,139 @@ impl ser::Serializer for Serializer {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::sql::serde::serialize_internal;
|
||||
use ser::Serializer as _;
|
||||
use serde::Serialize;
|
||||
|
||||
#[test]
|
||||
fn math_e() {
|
||||
let constant = Constant::MathE;
|
||||
let serialized = serialize_internal(|| constant.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = constant.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(constant, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn math_frac_1pi() {
|
||||
let constant = Constant::MathFrac1Pi;
|
||||
let serialized = serialize_internal(|| constant.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = constant.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(constant, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn math_frac_1sqrt2() {
|
||||
let constant = Constant::MathFrac1Sqrt2;
|
||||
let serialized = serialize_internal(|| constant.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = constant.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(constant, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn math_frac_2pi() {
|
||||
let constant = Constant::MathFrac2Pi;
|
||||
let serialized = serialize_internal(|| constant.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = constant.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(constant, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn math_frac_2sqrt_pi() {
|
||||
let constant = Constant::MathFrac2SqrtPi;
|
||||
let serialized = serialize_internal(|| constant.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = constant.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(constant, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn math_frac_pi2() {
|
||||
let constant = Constant::MathFracPi2;
|
||||
let serialized = serialize_internal(|| constant.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = constant.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(constant, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn math_frac_pi3() {
|
||||
let constant = Constant::MathFracPi3;
|
||||
let serialized = serialize_internal(|| constant.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = constant.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(constant, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn math_frac_pi4() {
|
||||
let constant = Constant::MathFracPi4;
|
||||
let serialized = serialize_internal(|| constant.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = constant.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(constant, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn math_frac_pi6() {
|
||||
let constant = Constant::MathFracPi6;
|
||||
let serialized = serialize_internal(|| constant.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = constant.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(constant, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn math_frac_pi8() {
|
||||
let constant = Constant::MathFracPi8;
|
||||
let serialized = serialize_internal(|| constant.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = constant.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(constant, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn math_ln10() {
|
||||
let constant = Constant::MathLn10;
|
||||
let serialized = serialize_internal(|| constant.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = constant.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(constant, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn math_ln2() {
|
||||
let constant = Constant::MathLn2;
|
||||
let serialized = serialize_internal(|| constant.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = constant.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(constant, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn math_log102() {
|
||||
let constant = Constant::MathLog102;
|
||||
let serialized = serialize_internal(|| constant.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = constant.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(constant, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn math_log10_e() {
|
||||
let constant = Constant::MathLog10E;
|
||||
let serialized = serialize_internal(|| constant.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = constant.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(constant, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn math_log210() {
|
||||
let constant = Constant::MathLog210;
|
||||
let serialized = serialize_internal(|| constant.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = constant.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(constant, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn math_log2_e() {
|
||||
let constant = Constant::MathLog2E;
|
||||
let serialized = serialize_internal(|| constant.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = constant.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(constant, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn math_pi() {
|
||||
let constant = Constant::MathPi;
|
||||
let serialized = serialize_internal(|| constant.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = constant.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(constant, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn math_sqrt2() {
|
||||
let constant = Constant::MathSqrt2;
|
||||
let serialized = serialize_internal(|| constant.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = constant.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(constant, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn math_tau() {
|
||||
let constant = Constant::MathTau;
|
||||
let serialized = serialize_internal(|| constant.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = constant.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(constant, serialized);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -336,12 +336,11 @@ impl serde::ser::SerializeTuple for SerializeIdiomValueTuple {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::sql::serde::serialize_internal;
|
||||
|
||||
#[test]
|
||||
fn empty_expression() {
|
||||
let data = Data::EmptyExpression;
|
||||
let serialized = serialize_internal(|| data.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = data.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(data, serialized);
|
||||
}
|
||||
|
||||
|
@ -349,49 +348,49 @@ mod tests {
|
|||
fn set_expression() {
|
||||
let data =
|
||||
Data::SetExpression(vec![(Default::default(), Default::default(), Default::default())]);
|
||||
let serialized = serialize_internal(|| data.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = data.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(data, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn patch_expression() {
|
||||
let data = Data::PatchExpression(Default::default());
|
||||
let serialized = serialize_internal(|| data.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = data.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(data, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn merge_expression() {
|
||||
let data = Data::MergeExpression(Default::default());
|
||||
let serialized = serialize_internal(|| data.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = data.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(data, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn replace_expression() {
|
||||
let data = Data::ReplaceExpression(Default::default());
|
||||
let serialized = serialize_internal(|| data.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = data.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(data, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn content_expression() {
|
||||
let data = Data::ContentExpression(Default::default());
|
||||
let serialized = serialize_internal(|| data.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = data.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(data, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn single_expression() {
|
||||
let data = Data::SingleExpression(Default::default());
|
||||
let serialized = serialize_internal(|| data.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = data.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(data, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn values_expression() {
|
||||
let data = Data::ValuesExpression(vec![vec![(Default::default(), Default::default())]]);
|
||||
let serialized = serialize_internal(|| data.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = data.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(data, serialized);
|
||||
}
|
||||
|
||||
|
@ -402,7 +401,7 @@ mod tests {
|
|||
Default::default(),
|
||||
Default::default(),
|
||||
)]);
|
||||
let serialized = serialize_internal(|| data.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = data.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(data, serialized);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,20 +37,19 @@ impl ser::Serializer for Serializer {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::sql::serde::serialize_internal;
|
||||
use ser::Serializer as _;
|
||||
|
||||
#[test]
|
||||
fn none() {
|
||||
let option: Option<Data> = None;
|
||||
let serialized = serialize_internal(|| option.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = option.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(option, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn some() {
|
||||
let option = Some(Data::default());
|
||||
let serialized = serialize_internal(|| option.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = option.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(option, serialized);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -47,14 +47,13 @@ impl ser::Serializer for Serializer {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::sql::serde::serialize_internal;
|
||||
use ser::Serializer as _;
|
||||
use serde::Serialize;
|
||||
|
||||
#[test]
|
||||
fn now() {
|
||||
let dt = Utc::now();
|
||||
let serialized = serialize_internal(|| dt.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = dt.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(dt, serialized);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,14 +33,13 @@ impl ser::Serializer for Serializer {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::sql::serde::serialize_internal;
|
||||
use ser::Serializer as _;
|
||||
use serde::Serialize;
|
||||
|
||||
#[test]
|
||||
fn from_i32() {
|
||||
let decimal = BigDecimal::from(25);
|
||||
let serialized = serialize_internal(|| decimal.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = decimal.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(decimal, serialized);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,28 +39,27 @@ impl ser::Serializer for Serializer {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::sql::serde::serialize_internal;
|
||||
use ser::Serializer as _;
|
||||
use serde::Serialize;
|
||||
|
||||
#[test]
|
||||
fn r#in() {
|
||||
let dir = Dir::In;
|
||||
let serialized = serialize_internal(|| dir.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = dir.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(dir, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn out() {
|
||||
let dir = Dir::Out;
|
||||
let serialized = serialize_internal(|| dir.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = dir.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(dir, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn both() {
|
||||
let dir = Dir::Both;
|
||||
let serialized = serialize_internal(|| dir.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = dir.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(dir, serialized);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -85,13 +85,12 @@ impl serde::ser::SerializeStruct for SerializeDuration {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::sql::serde::serialize_internal;
|
||||
use serde::Serialize;
|
||||
|
||||
#[test]
|
||||
fn default() {
|
||||
let duration = Duration::default();
|
||||
let serialized = serialize_internal(|| duration.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = duration.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(duration, serialized);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,20 +37,19 @@ impl ser::Serializer for Serializer {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::sql::serde::serialize_internal;
|
||||
use ser::Serializer as _;
|
||||
|
||||
#[test]
|
||||
fn none() {
|
||||
let option: Option<Duration> = None;
|
||||
let serialized = serialize_internal(|| option.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = option.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(option, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn some() {
|
||||
let option = Some(Duration::default());
|
||||
let serialized = serialize_internal(|| option.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = option.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(option, serialized);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -82,7 +82,6 @@ impl serde::ser::SerializeStruct for SerializeEdges {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::sql::serde::serialize_internal;
|
||||
use crate::sql::thing;
|
||||
use serde::Serialize;
|
||||
|
||||
|
@ -93,7 +92,7 @@ mod tests {
|
|||
from: thing("foo:bar").unwrap(),
|
||||
what: Tables(Vec::new()),
|
||||
};
|
||||
let serialized = serialize_internal(|| edges.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = edges.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(edges, serialized);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -81,13 +81,12 @@ impl serde::ser::SerializeStruct for SerializeExpression {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::sql::serde::serialize_internal;
|
||||
use serde::Serialize;
|
||||
|
||||
#[test]
|
||||
fn default() {
|
||||
let expression = Expression::default();
|
||||
let serialized = serialize_internal(|| expression.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = expression.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(expression, serialized);
|
||||
}
|
||||
|
||||
|
@ -98,7 +97,7 @@ mod tests {
|
|||
o: Operator::Equal,
|
||||
r: "Bar".into(),
|
||||
};
|
||||
let serialized = serialize_internal(|| expression.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = expression.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(expression, serialized);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -63,19 +63,18 @@ impl serde::ser::SerializeSeq for SerializeFetchVec {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::sql::serde::serialize_internal;
|
||||
|
||||
#[test]
|
||||
fn empty() {
|
||||
let vec: Vec<Fetch> = Vec::new();
|
||||
let serialized = serialize_internal(|| vec.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = vec.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(vec, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn vec() {
|
||||
let vec = vec![Fetch::default()];
|
||||
let serialized = serialize_internal(|| vec.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = vec.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(vec, serialized);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,20 +37,19 @@ impl ser::Serializer for Serializer {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::sql::serde::serialize_internal;
|
||||
use ser::Serializer as _;
|
||||
|
||||
#[test]
|
||||
fn none() {
|
||||
let option: Option<Vec<Fetch>> = None;
|
||||
let serialized = serialize_internal(|| option.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = option.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(option, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn some() {
|
||||
let option = Some(vec![Fetch::default()]);
|
||||
let serialized = serialize_internal(|| option.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = option.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(option, serialized);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -113,27 +113,26 @@ impl serde::ser::SerializeTupleVariant for SerializeValueIdiomTuple {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::sql::serde::serialize_internal;
|
||||
use serde::Serialize;
|
||||
|
||||
#[test]
|
||||
fn all() {
|
||||
let field = Field::All;
|
||||
let serialized = serialize_internal(|| field.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = field.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(field, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn alone() {
|
||||
let field = Field::Alone(Default::default());
|
||||
let serialized = serialize_internal(|| field.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = field.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(field, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn alias() {
|
||||
let field = Field::Alias(Default::default(), Default::default());
|
||||
let serialized = serialize_internal(|| field.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = field.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(field, serialized);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -60,19 +60,18 @@ impl serde::ser::SerializeSeq for SerializeFieldVec {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::sql::serde::serialize_internal;
|
||||
|
||||
#[test]
|
||||
fn empty() {
|
||||
let vec: Vec<Field> = Vec::new();
|
||||
let serialized = serialize_internal(|| vec.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = vec.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(vec, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn vec() {
|
||||
let vec = vec![Field::default()];
|
||||
let serialized = serialize_internal(|| vec.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = vec.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(vec, serialized);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -73,19 +73,18 @@ impl serde::ser::SerializeTupleStruct for SerializeFields {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::sql::serde::serialize_internal;
|
||||
|
||||
#[test]
|
||||
fn default() {
|
||||
let fields = Fields::default();
|
||||
let serialized = serialize_internal(|| fields.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = fields.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(fields, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn all() {
|
||||
let fields = Fields(vec![Field::All], true);
|
||||
let serialized = serialize_internal(|| fields.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = fields.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(fields, serialized);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -119,34 +119,33 @@ impl serde::ser::SerializeTupleVariant for SerializeFunction {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::sql::serde::serialize_internal;
|
||||
use serde::Serialize;
|
||||
|
||||
#[test]
|
||||
fn cast() {
|
||||
let function = Function::Cast(Default::default(), Default::default());
|
||||
let serialized = serialize_internal(|| function.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = function.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(function, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn normal() {
|
||||
let function = Function::Normal(Default::default(), vec![Default::default()]);
|
||||
let serialized = serialize_internal(|| function.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = function.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(function, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn custom() {
|
||||
let function = Function::Custom(Default::default(), vec![Default::default()]);
|
||||
let serialized = serialize_internal(|| function.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = function.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(function, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn script() {
|
||||
let function = Function::Script(Default::default(), vec![Default::default()]);
|
||||
let serialized = serialize_internal(|| function.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = function.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(function, serialized);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -88,12 +88,11 @@ impl serde::ser::SerializeStruct for SerializeCoord {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::sql::serde::serialize_internal;
|
||||
|
||||
#[test]
|
||||
fn default() {
|
||||
let coord = Coord::default();
|
||||
let serialized = serialize_internal(|| coord.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = coord.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(coord, serialized);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -60,19 +60,18 @@ impl serde::ser::SerializeSeq for SerializeCoordVec {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::sql::serde::serialize_internal;
|
||||
|
||||
#[test]
|
||||
fn empty() {
|
||||
let vec: Vec<Coord<f64>> = Vec::new();
|
||||
let serialized = serialize_internal(|| vec.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = vec.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(vec, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn vec() {
|
||||
let vec = vec![Coord::default()];
|
||||
let serialized = serialize_internal(|| vec.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = vec.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(vec, serialized);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -60,20 +60,19 @@ impl serde::ser::SerializeSeq for SerializeLineStringVec {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::sql::serde::serialize_internal;
|
||||
use geo::Coord;
|
||||
|
||||
#[test]
|
||||
fn empty() {
|
||||
let vec: Vec<LineString<f64>> = Vec::new();
|
||||
let serialized = serialize_internal(|| vec.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = vec.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(vec, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn vec() {
|
||||
let vec = vec![LineString(vec![Coord::default()])];
|
||||
let serialized = serialize_internal(|| vec.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = vec.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(vec, serialized);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -98,7 +98,6 @@ impl serde::ser::SerializeSeq for SerializeGeometryVec {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::sql::serde::serialize_internal;
|
||||
use geo::Coord;
|
||||
use geo::Polygon;
|
||||
use ser::Serializer as _;
|
||||
|
@ -107,14 +106,14 @@ mod tests {
|
|||
#[test]
|
||||
fn point() {
|
||||
let geometry = Geometry::Point(Default::default());
|
||||
let serialized = serialize_internal(|| geometry.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = geometry.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(geometry, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn line() {
|
||||
let geometry = Geometry::Line(LineString(vec![Coord::default()]));
|
||||
let serialized = serialize_internal(|| geometry.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = geometry.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(geometry, serialized);
|
||||
}
|
||||
|
||||
|
@ -122,35 +121,35 @@ mod tests {
|
|||
fn polygon() {
|
||||
let polygon = Polygon::new(LineString(Vec::new()), Vec::new());
|
||||
let geometry = Geometry::Polygon(polygon);
|
||||
let serialized = serialize_internal(|| geometry.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = geometry.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(geometry, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn multi_point() {
|
||||
let geometry = Geometry::MultiPoint(vec![(0., 0.), (1., 2.)].into());
|
||||
let serialized = serialize_internal(|| geometry.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = geometry.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(geometry, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn multi_line() {
|
||||
let geometry = Geometry::MultiLine(MultiLineString::new(Vec::new()));
|
||||
let serialized = serialize_internal(|| geometry.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = geometry.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(geometry, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn multi_polygon() {
|
||||
let geometry = Geometry::MultiPolygon(MultiPolygon::new(Vec::new()));
|
||||
let serialized = serialize_internal(|| geometry.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = geometry.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(geometry, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn collection() {
|
||||
let geometry = Geometry::Collection(vec![Geometry::Point(Default::default())]);
|
||||
let serialized = serialize_internal(|| geometry.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = geometry.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(geometry, serialized);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -60,19 +60,18 @@ impl serde::ser::SerializeSeq for SerializePointVec {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::sql::serde::serialize_internal;
|
||||
|
||||
#[test]
|
||||
fn empty() {
|
||||
let vec: Vec<Point<f64>> = Vec::new();
|
||||
let serialized = serialize_internal(|| vec.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = vec.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(vec, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn vec() {
|
||||
let vec = vec![Point::default()];
|
||||
let serialized = serialize_internal(|| vec.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = vec.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(vec, serialized);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -77,12 +77,11 @@ impl serde::ser::SerializeStruct for SerializePolygon {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::sql::serde::serialize_internal;
|
||||
|
||||
#[test]
|
||||
fn default() {
|
||||
let polygon = Polygon::new(LineString(Vec::new()), Vec::new());
|
||||
let serialized = serialize_internal(|| polygon.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = polygon.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(polygon, serialized);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -60,20 +60,19 @@ impl serde::ser::SerializeSeq for SerializePolygonVec {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::sql::serde::serialize_internal;
|
||||
use geo::LineString;
|
||||
|
||||
#[test]
|
||||
fn empty() {
|
||||
let vec: Vec<Polygon<f64>> = Vec::new();
|
||||
let serialized = serialize_internal(|| vec.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = vec.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(vec, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn vec() {
|
||||
let vec = vec![Polygon::new(LineString(Vec::new()), Vec::new())];
|
||||
let serialized = serialize_internal(|| vec.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = vec.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(vec, serialized);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -48,19 +48,18 @@ impl serde::ser::SerializeSeq for SerializeGeometryVec {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::sql::serde::serialize_internal;
|
||||
|
||||
#[test]
|
||||
fn empty() {
|
||||
let vec: Vec<Geometry> = Vec::new();
|
||||
let serialized = serialize_internal(|| vec.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = vec.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(vec, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn vec() {
|
||||
let vec = vec![Geometry::Point(Default::default())];
|
||||
let serialized = serialize_internal(|| vec.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = vec.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(vec, serialized);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -124,13 +124,12 @@ impl serde::ser::SerializeStruct for SerializeGraph {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::sql::serde::serialize_internal;
|
||||
use serde::Serialize;
|
||||
|
||||
#[test]
|
||||
fn default() {
|
||||
let graph = Graph::default();
|
||||
let serialized = serialize_internal(|| graph.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = graph.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(graph, serialized);
|
||||
}
|
||||
|
||||
|
@ -140,7 +139,7 @@ mod tests {
|
|||
cond: Some(Default::default()),
|
||||
..Default::default()
|
||||
};
|
||||
let serialized = serialize_internal(|| graph.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = graph.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(graph, serialized);
|
||||
}
|
||||
|
||||
|
@ -150,7 +149,7 @@ mod tests {
|
|||
alias: Some(Default::default()),
|
||||
..Default::default()
|
||||
};
|
||||
let serialized = serialize_internal(|| graph.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = graph.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(graph, serialized);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -63,19 +63,18 @@ impl serde::ser::SerializeSeq for SerializeGroupVec {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::sql::serde::serialize_internal;
|
||||
|
||||
#[test]
|
||||
fn empty() {
|
||||
let vec: Vec<Group> = Vec::new();
|
||||
let serialized = serialize_internal(|| vec.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = vec.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(vec, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn vec() {
|
||||
let vec = vec![Group::default()];
|
||||
let serialized = serialize_internal(|| vec.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = vec.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(vec, serialized);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,20 +37,19 @@ impl ser::Serializer for Serializer {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::sql::serde::serialize_internal;
|
||||
use ser::Serializer as _;
|
||||
|
||||
#[test]
|
||||
fn none() {
|
||||
let option: Option<Vec<Group>> = None;
|
||||
let serialized = serialize_internal(|| option.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = option.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(option, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn some() {
|
||||
let option = Some(vec![Group::default()]);
|
||||
let serialized = serialize_internal(|| option.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = option.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(option, serialized);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -51,35 +51,34 @@ impl ser::Serializer for Serializer {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::sql::serde::serialize_internal;
|
||||
use ser::Serializer as _;
|
||||
use serde::Serialize;
|
||||
|
||||
#[test]
|
||||
fn number() {
|
||||
let id = Id::Number(Default::default());
|
||||
let serialized = serialize_internal(|| id.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = id.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(id, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn string() {
|
||||
let id = Id::String(Default::default());
|
||||
let serialized = serialize_internal(|| id.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = id.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(id, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn array() {
|
||||
let id = Id::Array(Default::default());
|
||||
let serialized = serialize_internal(|| id.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = id.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(id, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn object() {
|
||||
let id = Id::Object(Default::default());
|
||||
let serialized = serialize_internal(|| id.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = id.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(id, serialized);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -144,158 +144,157 @@ impl serde::ser::SerializeTupleVariant for SerializeKindTuple {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::sql::serde::serialize_internal;
|
||||
|
||||
#[test]
|
||||
fn any() {
|
||||
let kind = Kind::Any;
|
||||
let serialized = serialize_internal(|| kind.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = kind.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(kind, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn bool() {
|
||||
let kind = Kind::Bool;
|
||||
let serialized = serialize_internal(|| kind.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = kind.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(kind, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn bytes() {
|
||||
let kind = Kind::Bytes;
|
||||
let serialized = serialize_internal(|| kind.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = kind.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(kind, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn datetime() {
|
||||
let kind = Kind::Datetime;
|
||||
let serialized = serialize_internal(|| kind.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = kind.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(kind, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn decimal() {
|
||||
let kind = Kind::Decimal;
|
||||
let serialized = serialize_internal(|| kind.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = kind.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(kind, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn duration() {
|
||||
let kind = Kind::Duration;
|
||||
let serialized = serialize_internal(|| kind.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = kind.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(kind, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn float() {
|
||||
let kind = Kind::Float;
|
||||
let serialized = serialize_internal(|| kind.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = kind.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(kind, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn int() {
|
||||
let kind = Kind::Int;
|
||||
let serialized = serialize_internal(|| kind.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = kind.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(kind, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn number() {
|
||||
let kind = Kind::Number;
|
||||
let serialized = serialize_internal(|| kind.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = kind.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(kind, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn object() {
|
||||
let kind = Kind::Object;
|
||||
let serialized = serialize_internal(|| kind.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = kind.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(kind, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn point() {
|
||||
let kind = Kind::Point;
|
||||
let serialized = serialize_internal(|| kind.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = kind.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(kind, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn string() {
|
||||
let kind = Kind::String;
|
||||
let serialized = serialize_internal(|| kind.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = kind.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(kind, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn uuid() {
|
||||
let kind = Kind::Uuid;
|
||||
let serialized = serialize_internal(|| kind.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = kind.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(kind, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn record() {
|
||||
let kind = Kind::Record(Default::default());
|
||||
let serialized = serialize_internal(|| kind.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = kind.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(kind, serialized);
|
||||
|
||||
let kind = Kind::Record(vec![Default::default()]);
|
||||
let serialized = serialize_internal(|| kind.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = kind.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(kind, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn geometry() {
|
||||
let kind = Kind::Geometry(Default::default());
|
||||
let serialized = serialize_internal(|| kind.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = kind.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(kind, serialized);
|
||||
|
||||
let kind = Kind::Geometry(vec![Default::default()]);
|
||||
let serialized = serialize_internal(|| kind.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = kind.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(kind, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn option() {
|
||||
let kind = Kind::Option(Box::new(Default::default()));
|
||||
let serialized = serialize_internal(|| kind.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = kind.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(kind, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn either() {
|
||||
let kind = Kind::Either(Default::default());
|
||||
let serialized = serialize_internal(|| kind.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = kind.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(kind, serialized);
|
||||
|
||||
let kind = Kind::Either(vec![Default::default()]);
|
||||
let serialized = serialize_internal(|| kind.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = kind.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(kind, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn set() {
|
||||
let kind = Kind::Set(Box::new(Default::default()), None);
|
||||
let serialized = serialize_internal(|| kind.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = kind.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(kind, serialized);
|
||||
|
||||
let kind = Kind::Set(Box::new(Default::default()), Some(Default::default()));
|
||||
let serialized = serialize_internal(|| kind.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = kind.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(kind, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn array() {
|
||||
let kind = Kind::Array(Box::new(Default::default()), None);
|
||||
let serialized = serialize_internal(|| kind.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = kind.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(kind, serialized);
|
||||
|
||||
let kind = Kind::Array(Box::new(Default::default()), Some(Default::default()));
|
||||
let serialized = serialize_internal(|| kind.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = kind.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(kind, serialized);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -60,19 +60,18 @@ impl serde::ser::SerializeSeq for SerializeKindVec {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::sql::serde::serialize_internal;
|
||||
|
||||
#[test]
|
||||
fn empty() {
|
||||
let vec: Vec<Kind> = Vec::new();
|
||||
let serialized = serialize_internal(|| vec.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = vec.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(vec, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn vec() {
|
||||
let vec = vec![Kind::default()];
|
||||
let serialized = serialize_internal(|| vec.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = vec.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(vec, serialized);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,20 +37,19 @@ impl ser::Serializer for Serializer {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::sql::serde::serialize_internal;
|
||||
use ser::Serializer as _;
|
||||
|
||||
#[test]
|
||||
fn none() {
|
||||
let option: Option<Limit> = None;
|
||||
let serialized = serialize_internal(|| option.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = option.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(option, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn some() {
|
||||
let option = Some(Limit::default());
|
||||
let serialized = serialize_internal(|| option.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = option.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(option, serialized);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -49,7 +49,7 @@ use serde::ser::SerializeTupleStruct;
|
|||
use serde::ser::SerializeTupleVariant;
|
||||
use std::fmt::Display;
|
||||
|
||||
pub(crate) use value::to_value;
|
||||
pub use value::to_value;
|
||||
|
||||
trait Serializer: Sized {
|
||||
type Ok;
|
||||
|
|
|
@ -97,20 +97,19 @@ impl serde::ser::SerializeTupleVariant for SerializeModel {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::sql::serde::serialize_internal;
|
||||
use serde::Serialize;
|
||||
|
||||
#[test]
|
||||
fn count() {
|
||||
let model = Model::Count(Default::default(), Default::default());
|
||||
let serialized = serialize_internal(|| model.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = model.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(model, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn range() {
|
||||
let model = Model::Range(Default::default(), 1, 2);
|
||||
let serialized = serialize_internal(|| model.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = model.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(model, serialized);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -118,28 +118,27 @@ impl ser::Serializer for Serializer {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::sql::serde::serialize_internal;
|
||||
use ser::Serializer as _;
|
||||
use serde::Serialize;
|
||||
|
||||
#[test]
|
||||
fn int() {
|
||||
let number = Number::Int(Default::default());
|
||||
let serialized = serialize_internal(|| number.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = number.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(number, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn float() {
|
||||
let number = Number::Float(Default::default());
|
||||
let serialized = serialize_internal(|| number.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = number.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(number, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn decimal() {
|
||||
let number = Number::Decimal(Default::default());
|
||||
let serialized = serialize_internal(|| number.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = number.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(number, serialized);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -72,259 +72,258 @@ impl ser::Serializer for Serializer {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::sql::serde::serialize_internal;
|
||||
use ser::Serializer as _;
|
||||
use serde::Serialize;
|
||||
|
||||
#[test]
|
||||
fn or() {
|
||||
let dir = Operator::Or;
|
||||
let serialized = serialize_internal(|| dir.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = dir.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(dir, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn and() {
|
||||
let dir = Operator::And;
|
||||
let serialized = serialize_internal(|| dir.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = dir.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(dir, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tco() {
|
||||
let dir = Operator::Tco;
|
||||
let serialized = serialize_internal(|| dir.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = dir.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(dir, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn nco() {
|
||||
let dir = Operator::Nco;
|
||||
let serialized = serialize_internal(|| dir.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = dir.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(dir, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn add() {
|
||||
let dir = Operator::Add;
|
||||
let serialized = serialize_internal(|| dir.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = dir.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(dir, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn sub() {
|
||||
let dir = Operator::Sub;
|
||||
let serialized = serialize_internal(|| dir.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = dir.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(dir, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn mul() {
|
||||
let dir = Operator::Mul;
|
||||
let serialized = serialize_internal(|| dir.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = dir.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(dir, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn div() {
|
||||
let dir = Operator::Div;
|
||||
let serialized = serialize_internal(|| dir.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = dir.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(dir, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn pow() {
|
||||
let dir = Operator::Pow;
|
||||
let serialized = serialize_internal(|| dir.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = dir.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(dir, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn inc() {
|
||||
let dir = Operator::Inc;
|
||||
let serialized = serialize_internal(|| dir.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = dir.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(dir, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn dec() {
|
||||
let dir = Operator::Dec;
|
||||
let serialized = serialize_internal(|| dir.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = dir.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(dir, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn equal() {
|
||||
let dir = Operator::Equal;
|
||||
let serialized = serialize_internal(|| dir.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = dir.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(dir, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn exact() {
|
||||
let dir = Operator::Exact;
|
||||
let serialized = serialize_internal(|| dir.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = dir.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(dir, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn not_equal() {
|
||||
let dir = Operator::NotEqual;
|
||||
let serialized = serialize_internal(|| dir.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = dir.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(dir, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn all_equal() {
|
||||
let dir = Operator::AllEqual;
|
||||
let serialized = serialize_internal(|| dir.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = dir.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(dir, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn any_equal() {
|
||||
let dir = Operator::AnyEqual;
|
||||
let serialized = serialize_internal(|| dir.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = dir.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(dir, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn like() {
|
||||
let dir = Operator::Like;
|
||||
let serialized = serialize_internal(|| dir.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = dir.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(dir, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn not_like() {
|
||||
let dir = Operator::NotLike;
|
||||
let serialized = serialize_internal(|| dir.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = dir.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(dir, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn all_like() {
|
||||
let dir = Operator::AllLike;
|
||||
let serialized = serialize_internal(|| dir.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = dir.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(dir, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn any_like() {
|
||||
let dir = Operator::AnyLike;
|
||||
let serialized = serialize_internal(|| dir.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = dir.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(dir, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn less_than() {
|
||||
let dir = Operator::LessThan;
|
||||
let serialized = serialize_internal(|| dir.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = dir.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(dir, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn less_than_or_equal() {
|
||||
let dir = Operator::LessThanOrEqual;
|
||||
let serialized = serialize_internal(|| dir.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = dir.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(dir, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn more_than() {
|
||||
let dir = Operator::MoreThan;
|
||||
let serialized = serialize_internal(|| dir.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = dir.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(dir, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn more_than_or_equal() {
|
||||
let dir = Operator::MoreThanOrEqual;
|
||||
let serialized = serialize_internal(|| dir.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = dir.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(dir, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn contain() {
|
||||
let dir = Operator::Contain;
|
||||
let serialized = serialize_internal(|| dir.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = dir.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(dir, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn not_contain() {
|
||||
let dir = Operator::NotContain;
|
||||
let serialized = serialize_internal(|| dir.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = dir.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(dir, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn contain_all() {
|
||||
let dir = Operator::ContainAll;
|
||||
let serialized = serialize_internal(|| dir.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = dir.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(dir, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn contain_any() {
|
||||
let dir = Operator::ContainAny;
|
||||
let serialized = serialize_internal(|| dir.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = dir.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(dir, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn contain_none() {
|
||||
let dir = Operator::ContainNone;
|
||||
let serialized = serialize_internal(|| dir.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = dir.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(dir, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn inside() {
|
||||
let dir = Operator::Inside;
|
||||
let serialized = serialize_internal(|| dir.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = dir.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(dir, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn not_inside() {
|
||||
let dir = Operator::NotInside;
|
||||
let serialized = serialize_internal(|| dir.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = dir.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(dir, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn all_inside() {
|
||||
let dir = Operator::AllInside;
|
||||
let serialized = serialize_internal(|| dir.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = dir.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(dir, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn any_inside() {
|
||||
let dir = Operator::AnyInside;
|
||||
let serialized = serialize_internal(|| dir.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = dir.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(dir, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn none_inside() {
|
||||
let dir = Operator::NoneInside;
|
||||
let serialized = serialize_internal(|| dir.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = dir.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(dir, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn outside() {
|
||||
let dir = Operator::Outside;
|
||||
let serialized = serialize_internal(|| dir.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = dir.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(dir, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn intersects() {
|
||||
let dir = Operator::Intersects;
|
||||
let serialized = serialize_internal(|| dir.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = dir.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(dir, serialized);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -94,13 +94,12 @@ impl serde::ser::SerializeStruct for SerializeOrder {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::sql::serde::serialize_internal;
|
||||
use serde::Serialize;
|
||||
|
||||
#[test]
|
||||
fn default() {
|
||||
let order = Order::default();
|
||||
let serialized = serialize_internal(|| order.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = order.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(order, serialized);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -62,19 +62,18 @@ impl serde::ser::SerializeSeq for SerializeOrderVec {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::sql::serde::serialize_internal;
|
||||
|
||||
#[test]
|
||||
fn empty() {
|
||||
let vec: Vec<Order> = Vec::new();
|
||||
let serialized = serialize_internal(|| vec.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = vec.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(vec, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn vec() {
|
||||
let vec = vec![Order::default()];
|
||||
let serialized = serialize_internal(|| vec.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = vec.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(vec, serialized);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,20 +37,19 @@ impl ser::Serializer for Serializer {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::sql::serde::serialize_internal;
|
||||
use ser::Serializer as _;
|
||||
|
||||
#[test]
|
||||
fn none() {
|
||||
let option: Option<Vec<Order>> = None;
|
||||
let serialized = serialize_internal(|| option.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = option.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(option, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn some() {
|
||||
let option = Some(vec![Order::default()]);
|
||||
let serialized = serialize_internal(|| option.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = option.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(option, serialized);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -62,49 +62,48 @@ impl ser::Serializer for Serializer {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::sql::serde::serialize_internal;
|
||||
use ser::Serializer as _;
|
||||
use serde::Serialize;
|
||||
|
||||
#[test]
|
||||
fn none() {
|
||||
let output = Output::None;
|
||||
let serialized = serialize_internal(|| output.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = output.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(output, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn null() {
|
||||
let output = Output::Null;
|
||||
let serialized = serialize_internal(|| output.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = output.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(output, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn diff() {
|
||||
let output = Output::Diff;
|
||||
let serialized = serialize_internal(|| output.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = output.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(output, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn after() {
|
||||
let output = Output::After;
|
||||
let serialized = serialize_internal(|| output.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = output.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(output, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn before() {
|
||||
let output = Output::Before;
|
||||
let serialized = serialize_internal(|| output.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = output.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(output, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn fields() {
|
||||
let output = Output::Fields(Default::default());
|
||||
let serialized = serialize_internal(|| output.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = output.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(output, serialized);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,20 +37,19 @@ impl ser::Serializer for Serializer {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::sql::serde::serialize_internal;
|
||||
use ser::Serializer as _;
|
||||
|
||||
#[test]
|
||||
fn none() {
|
||||
let option: Option<Output> = None;
|
||||
let serialized = serialize_internal(|| option.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = option.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(option, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn some() {
|
||||
let option = Some(Output::default());
|
||||
let serialized = serialize_internal(|| option.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = option.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(option, serialized);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -67,63 +67,62 @@ impl ser::Serializer for Serializer {
|
|||
mod tests {
|
||||
use super::*;
|
||||
use crate::sql;
|
||||
use crate::sql::serde::serialize_internal;
|
||||
use ser::Serializer as _;
|
||||
use serde::Serialize;
|
||||
|
||||
#[test]
|
||||
fn all() {
|
||||
let part = Part::All;
|
||||
let serialized = serialize_internal(|| part.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = part.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(part, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn last() {
|
||||
let part = Part::Last;
|
||||
let serialized = serialize_internal(|| part.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = part.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(part, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn first() {
|
||||
let part = Part::First;
|
||||
let serialized = serialize_internal(|| part.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = part.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(part, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn field() {
|
||||
let part = Part::Field(Default::default());
|
||||
let serialized = serialize_internal(|| part.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = part.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(part, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn index() {
|
||||
let part = Part::Index(Default::default());
|
||||
let serialized = serialize_internal(|| part.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = part.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(part, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn r#where() {
|
||||
let part = Part::Where(Default::default());
|
||||
let serialized = serialize_internal(|| part.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = part.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(part, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn graph() {
|
||||
let part = Part::Graph(Default::default());
|
||||
let serialized = serialize_internal(|| part.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = part.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(part, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn value() {
|
||||
let part = Part::Value(sql::thing("foo:bar").unwrap().into());
|
||||
let serialized = serialize_internal(|| part.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = part.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(part, serialized);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -62,19 +62,18 @@ impl serde::ser::SerializeSeq for SerializePartVec {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::sql::serde::serialize_internal;
|
||||
|
||||
#[test]
|
||||
fn empty() {
|
||||
let vec: Vec<Part> = Vec::new();
|
||||
let serialized = serialize_internal(|| vec.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = vec.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(vec, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn vec() {
|
||||
let vec = vec![Part::All];
|
||||
let serialized = serialize_internal(|| vec.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = vec.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(vec, serialized);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,20 +37,19 @@ impl ser::Serializer for Serializer {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::sql::serde::serialize_internal;
|
||||
use ser::Serializer as _;
|
||||
|
||||
#[test]
|
||||
fn none() {
|
||||
let option: Option<Vec<Part>> = None;
|
||||
let serialized = serialize_internal(|| option.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = option.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(option, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn some() {
|
||||
let option = Some(vec![Part::All]);
|
||||
let serialized = serialize_internal(|| option.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = option.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(option, serialized);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,20 +36,19 @@ impl ser::Serializer for Serializer {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::sql::serde::serialize_internal;
|
||||
use ser::Serializer as _;
|
||||
|
||||
#[test]
|
||||
fn none() {
|
||||
let option: Option<u64> = None;
|
||||
let serialized = serialize_internal(|| option.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = option.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(option, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn some() {
|
||||
let option = Some(u64::default());
|
||||
let serialized = serialize_internal(|| option.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = option.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(option, serialized);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -59,27 +59,26 @@ impl ser::Serializer for Serializer {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::sql::serde::serialize_internal;
|
||||
use ser::Serializer as _;
|
||||
|
||||
#[test]
|
||||
fn unbounded() {
|
||||
let bound = Bound::Unbounded;
|
||||
let serialized = serialize_internal(|| bound.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = bound.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(bound, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn included() {
|
||||
let bound = Bound::Included(Id::rand());
|
||||
let serialized = serialize_internal(|| bound.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = bound.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(bound, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn excluded() {
|
||||
let bound = Bound::Excluded(Id::rand());
|
||||
let serialized = serialize_internal(|| bound.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = bound.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(bound, serialized);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -83,7 +83,6 @@ impl serde::ser::SerializeStruct for SerializeRange {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::sql::serde::serialize_internal;
|
||||
use serde::Serialize;
|
||||
|
||||
#[test]
|
||||
|
@ -93,7 +92,7 @@ mod tests {
|
|||
beg: Bound::Included("bar".into()),
|
||||
end: Bound::Excluded("foo".into()),
|
||||
};
|
||||
let serialized = serialize_internal(|| range.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = range.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(range, serialized);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -63,19 +63,18 @@ impl serde::ser::SerializeSeq for SerializeSplitVec {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::sql::serde::serialize_internal;
|
||||
|
||||
#[test]
|
||||
fn empty() {
|
||||
let vec: Vec<Split> = Vec::new();
|
||||
let serialized = serialize_internal(|| vec.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = vec.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(vec, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn vec() {
|
||||
let vec = vec![Split::default()];
|
||||
let serialized = serialize_internal(|| vec.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = vec.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(vec, serialized);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,20 +37,19 @@ impl ser::Serializer for Serializer {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::sql::serde::serialize_internal;
|
||||
use ser::Serializer as _;
|
||||
|
||||
#[test]
|
||||
fn none() {
|
||||
let option: Option<Vec<Split>> = None;
|
||||
let serialized = serialize_internal(|| option.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = option.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(option, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn some() {
|
||||
let option = Some(vec![Split::default()]);
|
||||
let serialized = serialize_internal(|| option.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = option.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(option, serialized);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,20 +37,19 @@ impl ser::Serializer for Serializer {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::sql::serde::serialize_internal;
|
||||
use ser::Serializer as _;
|
||||
|
||||
#[test]
|
||||
fn none() {
|
||||
let option: Option<Start> = None;
|
||||
let serialized = serialize_internal(|| option.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = option.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(option, serialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn some() {
|
||||
let option = Some(Start::default());
|
||||
let serialized = serialize_internal(|| option.serialize(Serializer.wrap())).unwrap();
|
||||
let serialized = option.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(option, serialized);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -96,13 +96,11 @@ impl serde::ser::SerializeStruct for SerializeCreateStatement {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::sql::serde::serialize_internal;
|
||||
|
||||
#[test]
|
||||
fn default() {
|
||||
let stmt = CreateStatement::default();
|
||||
let value: CreateStatement =
|
||||
serialize_internal(|| stmt.serialize(Serializer.wrap())).unwrap();
|
||||
let value: CreateStatement = stmt.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(value, stmt);
|
||||
}
|
||||
|
||||
|
@ -112,8 +110,7 @@ mod tests {
|
|||
data: Some(Default::default()),
|
||||
..Default::default()
|
||||
};
|
||||
let value: CreateStatement =
|
||||
serialize_internal(|| stmt.serialize(Serializer.wrap())).unwrap();
|
||||
let value: CreateStatement = stmt.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(value, stmt);
|
||||
}
|
||||
|
||||
|
@ -123,8 +120,7 @@ mod tests {
|
|||
output: Some(Default::default()),
|
||||
..Default::default()
|
||||
};
|
||||
let value: CreateStatement =
|
||||
serialize_internal(|| stmt.serialize(Serializer.wrap())).unwrap();
|
||||
let value: CreateStatement = stmt.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(value, stmt);
|
||||
}
|
||||
|
||||
|
@ -134,8 +130,7 @@ mod tests {
|
|||
timeout: Some(Default::default()),
|
||||
..Default::default()
|
||||
};
|
||||
let value: CreateStatement =
|
||||
serialize_internal(|| stmt.serialize(Serializer.wrap())).unwrap();
|
||||
let value: CreateStatement = stmt.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(value, stmt);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -93,13 +93,11 @@ impl serde::ser::SerializeStruct for SerializeDeleteStatement {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::sql::serde::serialize_internal;
|
||||
|
||||
#[test]
|
||||
fn default() {
|
||||
let stmt = DeleteStatement::default();
|
||||
let value: DeleteStatement =
|
||||
serialize_internal(|| stmt.serialize(Serializer.wrap())).unwrap();
|
||||
let value: DeleteStatement = stmt.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(value, stmt);
|
||||
}
|
||||
|
||||
|
@ -109,8 +107,7 @@ mod tests {
|
|||
cond: Some(Default::default()),
|
||||
..Default::default()
|
||||
};
|
||||
let value: DeleteStatement =
|
||||
serialize_internal(|| stmt.serialize(Serializer.wrap())).unwrap();
|
||||
let value: DeleteStatement = stmt.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(value, stmt);
|
||||
}
|
||||
|
||||
|
@ -120,8 +117,7 @@ mod tests {
|
|||
output: Some(Default::default()),
|
||||
..Default::default()
|
||||
};
|
||||
let value: DeleteStatement =
|
||||
serialize_internal(|| stmt.serialize(Serializer.wrap())).unwrap();
|
||||
let value: DeleteStatement = stmt.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(value, stmt);
|
||||
}
|
||||
|
||||
|
@ -131,8 +127,7 @@ mod tests {
|
|||
timeout: Some(Default::default()),
|
||||
..Default::default()
|
||||
};
|
||||
let value: DeleteStatement =
|
||||
serialize_internal(|| stmt.serialize(Serializer.wrap())).unwrap();
|
||||
let value: DeleteStatement = stmt.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(value, stmt);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -175,13 +175,11 @@ impl serde::ser::SerializeTuple for SerializeValueValueTuple {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::sql::serde::serialize_internal;
|
||||
|
||||
#[test]
|
||||
fn default() {
|
||||
let stmt = IfelseStatement::default();
|
||||
let value: IfelseStatement =
|
||||
serialize_internal(|| stmt.serialize(Serializer.wrap())).unwrap();
|
||||
let value: IfelseStatement = stmt.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(value, stmt);
|
||||
}
|
||||
|
||||
|
@ -191,8 +189,7 @@ mod tests {
|
|||
exprs: vec![(Default::default(), Default::default())],
|
||||
..Default::default()
|
||||
};
|
||||
let value: IfelseStatement =
|
||||
serialize_internal(|| stmt.serialize(Serializer.wrap())).unwrap();
|
||||
let value: IfelseStatement = stmt.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(value, stmt);
|
||||
}
|
||||
|
||||
|
@ -202,8 +199,7 @@ mod tests {
|
|||
close: Some(Default::default()),
|
||||
..Default::default()
|
||||
};
|
||||
let value: IfelseStatement =
|
||||
serialize_internal(|| stmt.serialize(Serializer.wrap())).unwrap();
|
||||
let value: IfelseStatement = stmt.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(value, stmt);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -103,13 +103,11 @@ impl serde::ser::SerializeStruct for SerializeInsertStatement {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::sql::serde::serialize_internal;
|
||||
|
||||
#[test]
|
||||
fn default() {
|
||||
let stmt = InsertStatement::default();
|
||||
let value: InsertStatement =
|
||||
serialize_internal(|| stmt.serialize(Serializer.wrap())).unwrap();
|
||||
let value: InsertStatement = stmt.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(value, stmt);
|
||||
}
|
||||
|
||||
|
@ -119,8 +117,7 @@ mod tests {
|
|||
update: Some(Default::default()),
|
||||
..Default::default()
|
||||
};
|
||||
let value: InsertStatement =
|
||||
serialize_internal(|| stmt.serialize(Serializer.wrap())).unwrap();
|
||||
let value: InsertStatement = stmt.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(value, stmt);
|
||||
}
|
||||
|
||||
|
@ -130,8 +127,7 @@ mod tests {
|
|||
output: Some(Default::default()),
|
||||
..Default::default()
|
||||
};
|
||||
let value: InsertStatement =
|
||||
serialize_internal(|| stmt.serialize(Serializer.wrap())).unwrap();
|
||||
let value: InsertStatement = stmt.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(value, stmt);
|
||||
}
|
||||
|
||||
|
@ -141,8 +137,7 @@ mod tests {
|
|||
timeout: Some(Default::default()),
|
||||
..Default::default()
|
||||
};
|
||||
let value: InsertStatement =
|
||||
serialize_internal(|| stmt.serialize(Serializer.wrap())).unwrap();
|
||||
let value: InsertStatement = stmt.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(value, stmt);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -76,13 +76,11 @@ impl serde::ser::SerializeStruct for SerializeOutputStatement {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::sql::serde::serialize_internal;
|
||||
|
||||
#[test]
|
||||
fn default() {
|
||||
let stmt = OutputStatement::default();
|
||||
let value: OutputStatement =
|
||||
serialize_internal(|| stmt.serialize(Serializer.wrap())).unwrap();
|
||||
let value: OutputStatement = stmt.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(value, stmt);
|
||||
}
|
||||
|
||||
|
@ -92,8 +90,7 @@ mod tests {
|
|||
fetch: Some(Default::default()),
|
||||
..Default::default()
|
||||
};
|
||||
let value: OutputStatement =
|
||||
serialize_internal(|| stmt.serialize(Serializer.wrap())).unwrap();
|
||||
let value: OutputStatement = stmt.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(value, stmt);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -110,13 +110,11 @@ impl serde::ser::SerializeStruct for SerializeRelateStatement {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::sql::serde::serialize_internal;
|
||||
|
||||
#[test]
|
||||
fn default() {
|
||||
let stmt = RelateStatement::default();
|
||||
let value: RelateStatement =
|
||||
serialize_internal(|| stmt.serialize(Serializer.wrap())).unwrap();
|
||||
let value: RelateStatement = stmt.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(value, stmt);
|
||||
}
|
||||
|
||||
|
@ -126,8 +124,7 @@ mod tests {
|
|||
data: Some(Default::default()),
|
||||
..Default::default()
|
||||
};
|
||||
let value: RelateStatement =
|
||||
serialize_internal(|| stmt.serialize(Serializer.wrap())).unwrap();
|
||||
let value: RelateStatement = stmt.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(value, stmt);
|
||||
}
|
||||
|
||||
|
@ -137,8 +134,7 @@ mod tests {
|
|||
output: Some(Default::default()),
|
||||
..Default::default()
|
||||
};
|
||||
let value: RelateStatement =
|
||||
serialize_internal(|| stmt.serialize(Serializer.wrap())).unwrap();
|
||||
let value: RelateStatement = stmt.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(value, stmt);
|
||||
}
|
||||
|
||||
|
@ -148,8 +144,7 @@ mod tests {
|
|||
timeout: Some(Default::default()),
|
||||
..Default::default()
|
||||
};
|
||||
let value: RelateStatement =
|
||||
serialize_internal(|| stmt.serialize(Serializer.wrap())).unwrap();
|
||||
let value: RelateStatement = stmt.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(value, stmt);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -135,13 +135,11 @@ impl serde::ser::SerializeStruct for SerializeSelectStatement {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::sql::serde::serialize_internal;
|
||||
|
||||
#[test]
|
||||
fn default() {
|
||||
let stmt = SelectStatement::default();
|
||||
let value: SelectStatement =
|
||||
serialize_internal(|| stmt.serialize(Serializer.wrap())).unwrap();
|
||||
let value: SelectStatement = stmt.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(value, stmt);
|
||||
}
|
||||
|
||||
|
@ -151,8 +149,7 @@ mod tests {
|
|||
cond: Some(Default::default()),
|
||||
..Default::default()
|
||||
};
|
||||
let value: SelectStatement =
|
||||
serialize_internal(|| stmt.serialize(Serializer.wrap())).unwrap();
|
||||
let value: SelectStatement = stmt.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(value, stmt);
|
||||
}
|
||||
|
||||
|
@ -162,8 +159,7 @@ mod tests {
|
|||
split: Some(Default::default()),
|
||||
..Default::default()
|
||||
};
|
||||
let value: SelectStatement =
|
||||
serialize_internal(|| stmt.serialize(Serializer.wrap())).unwrap();
|
||||
let value: SelectStatement = stmt.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(value, stmt);
|
||||
}
|
||||
|
||||
|
@ -173,8 +169,7 @@ mod tests {
|
|||
group: Some(Default::default()),
|
||||
..Default::default()
|
||||
};
|
||||
let value: SelectStatement =
|
||||
serialize_internal(|| stmt.serialize(Serializer.wrap())).unwrap();
|
||||
let value: SelectStatement = stmt.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(value, stmt);
|
||||
}
|
||||
|
||||
|
@ -184,8 +179,7 @@ mod tests {
|
|||
order: Some(Default::default()),
|
||||
..Default::default()
|
||||
};
|
||||
let value: SelectStatement =
|
||||
serialize_internal(|| stmt.serialize(Serializer.wrap())).unwrap();
|
||||
let value: SelectStatement = stmt.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(value, stmt);
|
||||
}
|
||||
|
||||
|
@ -195,8 +189,7 @@ mod tests {
|
|||
limit: Some(Default::default()),
|
||||
..Default::default()
|
||||
};
|
||||
let value: SelectStatement =
|
||||
serialize_internal(|| stmt.serialize(Serializer.wrap())).unwrap();
|
||||
let value: SelectStatement = stmt.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(value, stmt);
|
||||
}
|
||||
|
||||
|
@ -206,8 +199,7 @@ mod tests {
|
|||
start: Some(Default::default()),
|
||||
..Default::default()
|
||||
};
|
||||
let value: SelectStatement =
|
||||
serialize_internal(|| stmt.serialize(Serializer.wrap())).unwrap();
|
||||
let value: SelectStatement = stmt.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(value, stmt);
|
||||
}
|
||||
|
||||
|
@ -217,8 +209,7 @@ mod tests {
|
|||
fetch: Some(Default::default()),
|
||||
..Default::default()
|
||||
};
|
||||
let value: SelectStatement =
|
||||
serialize_internal(|| stmt.serialize(Serializer.wrap())).unwrap();
|
||||
let value: SelectStatement = stmt.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(value, stmt);
|
||||
}
|
||||
|
||||
|
@ -228,8 +219,7 @@ mod tests {
|
|||
version: Some(Default::default()),
|
||||
..Default::default()
|
||||
};
|
||||
let value: SelectStatement =
|
||||
serialize_internal(|| stmt.serialize(Serializer.wrap())).unwrap();
|
||||
let value: SelectStatement = stmt.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(value, stmt);
|
||||
}
|
||||
|
||||
|
@ -239,8 +229,7 @@ mod tests {
|
|||
timeout: Some(Default::default()),
|
||||
..Default::default()
|
||||
};
|
||||
let value: SelectStatement =
|
||||
serialize_internal(|| stmt.serialize(Serializer.wrap())).unwrap();
|
||||
let value: SelectStatement = stmt.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(value, stmt);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -75,12 +75,11 @@ impl serde::ser::SerializeStruct for SerializeSetStatement {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::sql::serde::serialize_internal;
|
||||
|
||||
#[test]
|
||||
fn default() {
|
||||
let stmt = SetStatement::default();
|
||||
let value: SetStatement = serialize_internal(|| stmt.serialize(Serializer.wrap())).unwrap();
|
||||
let value: SetStatement = stmt.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(value, stmt);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -102,13 +102,11 @@ impl serde::ser::SerializeStruct for SerializeUpdateStatement {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::sql::serde::serialize_internal;
|
||||
|
||||
#[test]
|
||||
fn default() {
|
||||
let stmt = UpdateStatement::default();
|
||||
let value: UpdateStatement =
|
||||
serialize_internal(|| stmt.serialize(Serializer.wrap())).unwrap();
|
||||
let value: UpdateStatement = stmt.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(value, stmt);
|
||||
}
|
||||
|
||||
|
@ -118,8 +116,7 @@ mod tests {
|
|||
data: Some(Default::default()),
|
||||
..Default::default()
|
||||
};
|
||||
let value: UpdateStatement =
|
||||
serialize_internal(|| stmt.serialize(Serializer.wrap())).unwrap();
|
||||
let value: UpdateStatement = stmt.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(value, stmt);
|
||||
}
|
||||
|
||||
|
@ -129,8 +126,7 @@ mod tests {
|
|||
cond: Some(Default::default()),
|
||||
..Default::default()
|
||||
};
|
||||
let value: UpdateStatement =
|
||||
serialize_internal(|| stmt.serialize(Serializer.wrap())).unwrap();
|
||||
let value: UpdateStatement = stmt.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(value, stmt);
|
||||
}
|
||||
|
||||
|
@ -140,8 +136,7 @@ mod tests {
|
|||
output: Some(Default::default()),
|
||||
..Default::default()
|
||||
};
|
||||
let value: UpdateStatement =
|
||||
serialize_internal(|| stmt.serialize(Serializer.wrap())).unwrap();
|
||||
let value: UpdateStatement = stmt.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(value, stmt);
|
||||
}
|
||||
|
||||
|
@ -151,8 +146,7 @@ mod tests {
|
|||
timeout: Some(Default::default()),
|
||||
..Default::default()
|
||||
};
|
||||
let value: UpdateStatement =
|
||||
serialize_internal(|| stmt.serialize(Serializer.wrap())).unwrap();
|
||||
let value: UpdateStatement = stmt.serialize(Serializer.wrap()).unwrap();
|
||||
assert_eq!(value, stmt);
|
||||
}
|
||||
}
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue