rethinkdb-rs
rethinkdb-rs copied to clipboard
Can not nested command in json object
can not using reql::Command
in serde:json!
because serde::Serialize
behavior
let command = r
.table("users")
.insert(json!({
"id": r.uuid(), // error
"age": r.expr(16), // error
"created": r.now() // error
}));
this problem also hard to solve because we can not serialize json multiple time in rethinkdb
// original body
{ "tags": ["love", "boy", "hate"] }
// after serialize query
{ "tags": [2, ["love", "boy", "hate"]]}
i also try another approch like using r.object([["key", "value"], ["key2", r.uuid()]])
and r.hashMap
is not implemented yet.
any suggestion on this please.
Thanks for reporting this. I will look into it when I get some time.
this problem also hard to solve because we can not serialize json multiple time in rethinkdb
Yes, this is one of the reasons Command
doesn't currently implement Serialize
.
json!({
"id": r.uuid(), // error
"age": r.expr(16), // error
"created": r.now() // error
})
Is that the actual query you wanted to run or it's just an example? If it's the actual query you can work around this by using Uuid
from the uuid
crate instead of r.uuid()
, 16
instead of r.expr(16)
and constructing the time using DateTime instead of r.now()
.
I think the json serialization problem can be solved by implementing our own implementation of the json!
macro. You can see an example implementation in unreql crate
We could write something like this:
use unreql::{r, rjson};
r.table("users")
.get(1)
.update(rjson!({
"name": "John",
"upd_count": r.row().g("upd_count").add(1),
}))