From f1ef3bfd21aea04ffb2a7e5d53a2735b5385a2e6 Mon Sep 17 00:00:00 2001 From: Rushmore Mushambi Date: Wed, 10 May 2023 14:12:47 +0200 Subject: [PATCH] Add a `sql::Value::into_json()` method (#1963) --- lib/src/sql/value/value.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/src/sql/value/value.rs b/lib/src/sql/value/value.rs index fc3789f5..8872a455 100644 --- a/lib/src/sql/value/value.rs +++ b/lib/src/sql/value/value.rs @@ -53,6 +53,7 @@ use nom::multi::separated_list0; use nom::multi::separated_list1; use once_cell::sync::Lazy; use serde::{Deserialize, Serialize}; +use serde_json::Value as Json; use std::cmp::Ordering; use std::collections::BTreeMap; use std::collections::HashMap; @@ -1020,6 +1021,14 @@ impl Value { } } + /// Converts a `surrealdb::sq::Value` into a `serde_json::Value` + /// + /// This converts certain types like `Thing` into their simpler formats + /// instead of the format used internally by SurrealDB. + pub fn into_json(self) -> Json { + self.into() + } + // ----------------------------------- // Simple conversion of value // -----------------------------------