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

Upsert #20

Open
snaumov opened this issue Apr 11, 2020 · 4 comments
Open

Upsert #20

snaumov opened this issue Apr 11, 2020 · 4 comments

Comments

@snaumov
Copy link

snaumov commented Apr 11, 2020

Hi, thanks for the library!

Is there a way to run an Upsert type of query?

@ondrowan
Copy link
Collaborator

Hey,

if you run Dgraph 1.1+ you can use Txn::do_request to perform request consisting of one query and one or more mutations, which should be identical to upsert {} block.

I'll document this and add some examples to the repository.

@snaumov
Copy link
Author

snaumov commented Apr 16, 2020

@ondrowan thanks for your reply

When I try to run this piece of code

     let q = r#"
        upsert {
            query {
              v as var(func: type(Message))
            }
          
            mutation {
              delete {
                uid(v) <message_id> * .
                uid(v) <text> * .
                uid(v) <date> * .
                uid(v) <reply_to> * .
                uid(v) <uid> * .
              }
            }
          }
        "#.to_string();

        let mut request = Request {
            query: q.into(),
            ..Default::default()
        };

        let mut txn = self.db.new_readonly_txn();

        txn.do_request(&mut request)?;

        txn.commit()?;

I'm getting this response back:


Dgraph Grpc error: RpcFailure(RpcStatus { status: Unknown, details: Some("while lexing upsert {\n            query {\n              v as var(func: type(Message))\n            }\n          \n            mutation {\n              delete {\n                uid(v) <message_id> * .\n                uid(v) <text> * .\n                uid(v) <date> * .\n                uid(v) <reply_to> * .\n                uid(v) <uid> * .\n              }\n            }\n          } at line 1 column 0: Invalid operation type: upsert") })

(excuse bad formatting)

So it's complaining about upsert operation being invalid. As long as my q query is not malformed (which I'm not 100% positive about), probably issue might be with Grpc missing an operation?

@ondrowan
Copy link
Collaborator

@snaumov I don't have my development env up and running now, so I might be mistaken, but I think you don't need to use upsert block when using do_request and it converts the whole request into upsert one.

@ondrowan
Copy link
Collaborator

I checked it further and what I mentioned seems to be the case. You'll just have to manually set both query and mutations parts of Request and it'll end up converting it into upsert block internally. I find Dgraph docs to be confusing when it comes to upserts because the examples use HTTP client, but gRPC ones use different way of achieving the same result. Either way, once I have some time and energy, I'll add examples with this since it's confusing.

Repository owner deleted a comment from redtree0 Feb 20, 2024
Repository owner deleted a comment from Jcillo507 Feb 21, 2024
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

2 participants