File tree Expand file tree Collapse file tree 7 files changed +25
-8
lines changed Expand file tree Collapse file tree 7 files changed +25
-8
lines changed Original file line number Diff line number Diff line change @@ -169,6 +169,23 @@ try {
169169}
170170```
171171
172+ To create a read-only transaction, set ` readOnly ` boolean to ` true ` while calling
173+ ` DgraphClient#newTxn() ` method. Read-only transactions cannot contain mutations and
174+ trying to call ` Txn#mutate() ` or ` Txn#commit() ` will result in an error. Calling
175+ ` Txn.Discard() ` will be a no-op.
176+
177+ You can optionally set the ` bestEffort ` boolean to ` true ` . This may yield improved
178+ latencies in read-bound workloads where linearizable reads are not strictly needed.
179+
180+ ``` js
181+ const txn = dgraphClient .newTxn ({
182+ readOnly: true ,
183+ bestEffort: false
184+ });
185+ // ...
186+ const res = await txn .queryWithVars (query, vars);
187+ ```
188+
172189### Running a Mutation
173190
174191` Txn#mutate(Mutation) ` runs a mutation. It takes in a ` Mutation ` object, which
Original file line number Diff line number Diff line change @@ -9,7 +9,7 @@ for Dgraph.
99
1010### Start Dgraph server
1111
12- You will need to install [ Dgraph v1.1 .0 or above] [ releases ] and run it.
12+ You will need to install [ Dgraph v20.03 .0 or above] [ releases ] and run it.
1313
1414[ releases ] : https://github.com/dgraph-io/dgraph/releases
1515
Original file line number Diff line number Diff line change @@ -110,7 +110,7 @@ async function queryData(dgraphClient) {
110110 }
111111 }` ;
112112 const vars = { $a : "Alice" } ;
113- const res = await dgraphClient . newTxn ( ) . queryWithVars ( query , vars ) ;
113+ const res = await dgraphClient . newTxn ( { readOnly : true } ) . queryWithVars ( query , vars ) ;
114114 const ppl = res . getJson ( ) ;
115115
116116 // Print results.
Original file line number Diff line number Diff line change 11{
22 "name" : " simple" ,
33 "dependencies" : {
4- "dgraph-js" : " ^2.1 .0" ,
5- "grpc" : " ^1.23.3 "
4+ "dgraph-js" : " ^20.3 .0" ,
5+ "grpc" : " ^1.24.2 "
66 }
77}
Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ cluster (1 Dgraph Zero and 1 Dgraph Alpha) configured with mutual TLS.
1010
1111### Install Dgraph
1212
13- You will need to [ install Dgraph v1.1 .0 or
13+ You will need to [ install Dgraph v20.03 .0 or
1414above] ( https://github.com/dgraph-io/dgraph/releases ) and run it.
1515
1616A quick-start installation script is available for Linux and Mac:
Original file line number Diff line number Diff line change @@ -122,7 +122,7 @@ async function queryData(dgraphClient) {
122122 }
123123 }` ;
124124 const vars = { $a : "Alice" } ;
125- const res = await dgraphClient . newTxn ( ) . queryWithVars ( query , vars ) ;
125+ const res = await dgraphClient . newTxn ( { readOnly : true } ) . queryWithVars ( query , vars ) ;
126126 const ppl = res . getJson ( ) ;
127127
128128 // Print results.
Original file line number Diff line number Diff line change 11{
22 "name" : " tls" ,
33 "dependencies" : {
4- "dgraph-js" : " ^2.1 .0" ,
5- "grpc" : " ^1.23.3 "
4+ "dgraph-js" : " ^20.3 .0" ,
5+ "grpc" : " ^1.24.2 "
66 }
77}
You can’t perform that action at this time.
0 commit comments