diff --git a/lib/src/sql/mod.rs b/lib/src/sql/mod.rs index 43663f05..4fe6e69b 100644 --- a/lib/src/sql/mod.rs +++ b/lib/src/sql/mod.rs @@ -42,7 +42,6 @@ pub(crate) mod query; pub(crate) mod range; pub(crate) mod regex; pub(crate) mod script; -pub(crate) mod serde; pub(crate) mod split; pub(crate) mod start; pub(crate) mod statement; @@ -59,6 +58,7 @@ pub(crate) mod view; #[cfg(test)] pub(crate) mod test; +pub mod serde; pub mod statements; pub use self::parser::*; diff --git a/lib/src/sql/serde.rs b/lib/src/sql/serde.rs index b77510f9..8078f059 100644 --- a/lib/src/sql/serde.rs +++ b/lib/src/sql/serde.rs @@ -5,14 +5,44 @@ 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: 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)) }