Ensure UUIDs convert to strings correctly

Closes #1650
This commit is contained in:
Tobie Morgan Hitchcock 2023-02-11 18:17:02 +00:00
parent ab124a2e21
commit d2571a6b29
2 changed files with 60 additions and 2 deletions

View file

@ -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(),
}
}

View file

@ -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(())
}