diff --git a/lib/src/sql/value/value.rs b/lib/src/sql/value/value.rs index 4fa414c8..bc710c7f 100644 --- a/lib/src/sql/value/value.rs +++ b/lib/src/sql/value/value.rs @@ -827,7 +827,9 @@ impl Value { pub fn as_string(self) -> String { match self { - Value::Strand(v) => v.as_string(), + Value::Strand(v) => v.0, + Value::Uuid(v) => v.to_raw(), + Value::Datetime(v) => v.to_raw(), _ => self.to_string(), } } @@ -844,7 +846,7 @@ impl Value { Value::Strand(v) => v.0, Value::Uuid(v) => v.to_raw(), Value::Datetime(v) => v.to_raw(), - _ => self.as_string(), + _ => self.to_string(), } } diff --git a/lib/tests/function.rs b/lib/tests/function.rs index a6d76278..c9dce0f7 100644 --- a/lib/tests/function.rs +++ b/lib/tests/function.rs @@ -481,3 +481,59 @@ async fn function_not() -> Result<(), Error> { // Ok(()) } + +#[tokio::test] +async fn function_type_thing() -> Result<(), Error> { + let sql = r#" + CREATE type::thing('person', 'test'); + CREATE type::thing('person', 1434619); + CREATE type::thing('city', '8e60244d-95f6-4f95-9e30-09a98977efb0'); + CREATE type::thing('temperature', ['London', '2022-09-30T20:25:01.406828Z']); + "#; + let dbs = Datastore::new("memory").await?; + let ses = Session::for_kv().with_ns("test").with_db("test"); + let res = &mut dbs.execute(&sql, &ses, None, false).await?; + assert_eq!(res.len(), 4); + // + let tmp = res.remove(0).result?; + let val = Value::parse( + "[ + { + id: person:test, + } + ]", + ); + assert_eq!(tmp, val); + // + let tmp = res.remove(0).result?; + let val = Value::parse( + "[ + { + id: person:1434619, + } + ]", + ); + assert_eq!(tmp, val); + // + let tmp = res.remove(0).result?; + let val = Value::parse( + "[ + { + id: city:⟨8e60244d-95f6-4f95-9e30-09a98977efb0⟩, + } + ]", + ); + assert_eq!(tmp, val); + // + let tmp = res.remove(0).result?; + let val = Value::parse( + "[ + { + id: temperature:['London', '2022-09-30T20:25:01.406828Z'], + } + ]", + ); + assert_eq!(tmp, val); + // + Ok(()) +}