Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can not nested command in json object #58

Open
krist7599555 opened this issue Jul 1, 2021 · 2 comments
Open

Can not nested command in json object #58

krist7599555 opened this issue Jul 1, 2021 · 2 comments

Comments

@krist7599555
Copy link

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.

@krist7599555 krist7599555 changed the title Is there a way to closure command in json! body How to nested command in json object Jul 1, 2021
@krist7599555 krist7599555 changed the title How to nested command in json object Can not nested command in json object Jul 1, 2021
@rushmorem
Copy link
Member

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().

@vettich
Copy link

vettich commented Jan 24, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants