Why querites need to be run within transaction?

Hi, I’m new to Dgraph and now i want to write a c# client for Dgraph. From the Client doc, it says “All mutations and queries run within the context of a transaction.”, is that means i can not directly use the Query and QueryAsync api from auto-generated grpc client? And i need to write a Transaction class like the one in your Java client?

Yes, all queries and mutations run within the context of a transaction so you’ll have a transaction class.

C# supports grpc so that would help generate some API’s. Happy to help with the client. The clients are fairly simple and it should be easy to write one. We also have clients in Go and Javascript apart from Java which you can look at.

That’s because each client will need to keep a linearized reads (lin_read) map? Can i just wrap the client within merging the lin_read in every query, like:

public class DgraphClient{
private Dgraph.DgraphClient _innerClient;
private LinRead _linRead;

 public Response Query(Request req) {
         var res = _innerClient.Query(req);
         MergeLinRead(res.txn.lin_read)
 }
 
 private void MergeLinRead(LinRead updatedLinRead) {
       lock{ 
        _linRead.Merge(updatedLinRead);
      }
}

}

Hi Pavwan,
Can I use the above method to support Query outside Transaction?

Yeah, from what I understand you don’t want to make use of transactions. So you can have a global linRead map that you can update using the result from a query or mutate. This should also be sent as part of queries.

Though by doing so the client becomes limited and can’t do transactions. It can only do a single query or mutate (keys need to be maintained for multiple mutates). So I’d suggest adding transactions if you are building a general purpose client.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.