Skip to content

Commit 3076f57

Browse files
andrejtonevmatea16
andauthored
Updated go, java, js drivers (#1262)
Co-authored-by: Matea Pesic <[email protected]>
1 parent 3047c2d commit 3076f57

File tree

4 files changed

+88
-7
lines changed

4 files changed

+88
-7
lines changed

pages/client-libraries/go.mdx

+18-3
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ if err != nil {
466466
panic(err)
467467
}
468468
```
469-
The `ExceuteQuery` method returns results in the `EagerResults` format, giving you access to the `Records` field. The records field contains all the records returned by the query. To process the results, you can iterate over the records and access the fields you need.
469+
The `ExecuteQuery` method returns results in the `EagerResults` format, giving you access to the `Records` field. The records field contains all the records returned by the query. To process the results, you can iterate over the records and access the fields you need.
470470
471471
For example:
472472
@@ -651,6 +651,12 @@ If you want to read data from the database, here is an example of a managed tran
651651
}
652652
```
653653
654+
655+
<Callout type="info">
656+
As of Memgraph version 3.2, queries are categorized as read or write and the corresponding storage access is taken. This allows for better query parallelization and higher throughput.
657+
An exception will be thrown if the user tries to execute a write query inside a read transaction. See [transaction accessor misalignment](/help-center/errors/transactions#transaction-accessor-misalignment) for more details.
658+
</Callout>
659+
654660
In the example above the `session.ExecuteRead` gets the function as an argument, the function is executed as a single transaction unit, and the result are returned from the function to the `session.ExecuteRead` method call.
655661
656662
Additional custom processing can be done on the result, such as running a second query inside the same transaction to return the wanted results.
@@ -710,6 +716,11 @@ tx.Run(ctx, "CREATE (n:Technology {name:'Memgraph'});", nil)
710716
tx.Commit(ctx) // or tx.Rollback(ctx)
711717
```
712718

719+
<Callout type="info">
720+
As of Memgraph version 3.2, queries are categorized as read or write and the corresponding storage access is taken. This allows for better query parallelization and higher throughput.
721+
Explicit transactions can cover a number of individual queries, but storage access is given at the start. For best performance, the user needs to declare whether the transaction should use read or write access.
722+
This can be done by setting the session's `AccessMode` to `neo4j.AccessModeRead` or `neo4j.AccessModeWrite`. This will in turn set the access mode of a transaction created via the `BeginTransaction` function. Note that `ExecuteRead` and `ExecuteWrite` will override the session's default access.
723+
</Callout>
713724

714725
Here is the full working example based on the explicit transaction:
715726

@@ -776,11 +787,15 @@ func getDevNodesByName(ctx context.Context, tx neo4j.ExplicitTransaction, name s
776787
777788
```
778789

779-
##### Implicit transaction
790+
##### Implicit transaction
780791

781792
Implicit or auto-commit transactions won't be automatically retried as with `ExecuteQuery()` method or managed transactions.
782-
With implicit transactions, you don't have the same control over transactions as with managed transactions. This is the most primitive way of running transactions:
793+
With implicit transactions, you don't have the same control over transactions as with managed transactions. This is the most primitive way of running transactions:
783794

795+
<Callout type="info">
796+
As of Memgraph version 3.2, queries are categorized as read or write and the corresponding storage access is taken. This allows for better query parallelization and higher throughput.
797+
Access mode is automatically determined when executing single queries through implicit transactions.
798+
</Callout>
784799

785800
```go
786801
session := driver.NewSession(ctx, neo4j.SessionConfig{DatabaseName: "memgraph"})

pages/client-libraries/java.mdx

+34-2
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,11 @@ public void createNode() {
376376
The session object takes a `SessionConfig` object as its argument. The `SessionConfig` object is used to specify the database name and other session configuration options. Session API supports `writeTransaction()` and `readTransaction()` methods.
377377
The `writeTransaction()` method takes a `TransactionWork` functional interface as its argument. The `TransactionWork` interface has a single method `execute()`, which takes a Transaction object `tx` as its argument and returns a value of generic type `T`, `void` in this case.
378378

379+
<Callout type="info">
380+
As of Memgraph version 3.2, queries are categorized as **read** or **write** and the corresponding storage access is taken. This allows for better query parallelization and higher throughput.
381+
Using `writeTransaction` informs Memgraph that the transaction will be modifying data. See [transaction accessor misalignment](/fundamentals/transactions#transaction-accessor-misalignment) for more details.
382+
</Callout>
383+
379384
#### Run a read query
380385

381386
Similar to the write query, `readTranasction()` method can be used to run read queries. The difference is that read will return the results of the query.
@@ -402,6 +407,11 @@ public void readNode() {
402407

403408
In the above query, each `Record` contains a `Node` accessible by the `asMap()` method.
404409

410+
<Callout type="info">
411+
As of Memgraph version 3.2, queries are categorized as **read** or **write** and the corresponding storage access is taken. This allows for better query parallelization and higher throughput.
412+
An exception will be thrown if the user tries to execute a write query inside a read transaction. See [transaction accessor misalignment](/fundamentals/transactions#transaction-accessor-misalignment) for more details.
413+
</Callout>
414+
405415
#### Running queries with property map
406416

407417
If you want to pass a property map to the query, you can do it like this:
@@ -575,7 +585,7 @@ Keep in mind that, at the moment, Memgraph does not support Timezones, ByteArray
575585
576586
Transaction is a unit of work that is executed on the database, it could be some basic read, write or complex set of steps in form of series of queries. There can be multiple ways to mange transaction, but usually, they are managed automatically by the driver or manually by the explicit code steps. Transaction management defines how to handle the transaction, when to commit, rollback, or terminate it.
577587
578-
On the driver side, if a transaction fails because of a transient error, the transaction is retried automatically.
588+
On the driver side, if a transaction fails because of a transient error, the transaction is retried automatically.
579589
The transient error will occur during write conflicts or network failures. The driver will retry the transaction function with an exponentially increasing delay.
580590
581591
#### Simple transaction management
@@ -630,11 +640,22 @@ public void createNode() {
630640
All the previous examples from this guide have used simple transaction management. It allows you to run multiple queries in a single transaction and have control over the transaction. You could have multiple logic blocks in the transaction, rollback or end the transaction if needed.
631641
Also, managed transactions have a retry logic, which means that if the transaction fails, it will be retried. Managed transactions are the most flexible way to run a Cypher query.
632642

643+
<Callout type="info">
644+
As of Memgraph version 3.2, queries are categorized as **read** or **write** and the corresponding storage access is taken. This allows for better query parallelization and higher throughput.
645+
Using `writeTransaction` and `readTransaction` informs Memgraph what type of access is required for the transaction.
646+
An exception will be thrown if the user tries to execute a write query inside a read transaction. See [transaction accessor misalignment](/fundamentals/transactions#transaction-accessor-misalignment) for more details.
647+
</Callout>
648+
633649
##### Implicit transactions
634650

635651
Implicit auto-commit queries are the simplest way to run a Cypher query since they aren't automatically retried like `writeTransaction` and `readTransaction` are.
636652
With implicit auto-commit transactions, you don't have the same control of transactions as with managed explicit transactions.
637653

654+
<Callout type="info">
655+
As of Memgraph version 3.2, queries are categorized as **read** or **write** and the corresponding storage access is taken. This allows for better query parallelization and higher throughput.
656+
For single query implicit transaction, no user input is required, Memgraph will deduce the access type needed at parse-time. See [transaction accessor misalignment](/fundamentals/transactions#transaction-accessor-misalignment) for more details.
657+
</Callout>
658+
638659
Here is an example of an implicit transaction:
639660

640661
```java
@@ -670,6 +691,12 @@ You can use the following transaction management methods via async session API:
670691

671692
##### Managed transactions
672693

694+
<Callout type="info">
695+
As of Memgraph version 3.2, queries are categorized as **read** or **write** and the corresponding storage access is taken. This allows for better query parallelization and higher throughput.
696+
Using `executeReadAsync` and `executeWriteAsync` informs Memgraph what type of access is required for the transaction.
697+
An exception will be thrown if the user tries to execute a write query inside a read transaction. See [transaction accessor misalignment](/fundamentals/transactions#transaction-accessor-misalignment) for more details.
698+
</Callout>
699+
673700
Here is a basic example of reading data from the database via Async session API:
674701

675702
```java
@@ -689,6 +716,11 @@ public CompletionStage<ResultSummary> readNodesAsync() {
689716

690717
Implicit auto-commit queries are the simplest way to run a Cypher query since they aren't automatically retried like `writeTransactionAsync` and `readTransactionAsync` are.
691718
719+
<Callout type="info">
720+
As of Memgraph version 3.2, queries are categorized as **read** or **write** and the corresponding storage access is taken. This allows for better query parallelization and higher throughput.
721+
For single query implicit transaction, no user input is required, Memgraph will deduce the access type needed at parse-time. See [transaction accessor misalignment](/fundamentals/transactions#transaction-accessor-misalignment) for more details.
722+
</Callout>
723+
692724
Here is an example of an implicit transaction:
693725
694726
```java
@@ -706,6 +738,6 @@ public CompletionStage<ResultSummary> createNodeAsync() {
706738
707739
If you encounter serialization errors while using Java client, we recommend
708740
referring to our [Serialization errors](/help-center/errors/serialization) page
709-
for detailed guidance on troubleshooting and best practices.
741+
for detailed guidance on troubleshooting and best practices.
710742
711743
</Callout>

pages/client-libraries/javascript.mdx

+19-2
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,11 @@ a transaction to encapsulate the Cypher queries you're executing. This automatic
500500
transaction management simplifies the process of working with transactions.
501501
That method should be used when transaction control is unnecessary.
502502

503+
<Callout type="info">
504+
As of Memgraph version 3.2, queries are categorized as **read** or **write** and the corresponding storage access is taken. This allows for better query parallelization and higher throughput.
505+
For single query automatic transaction, no user input is required, Memgraph will deduce the access type needed at parse-time. See [transaction accessor misalignment](/fundamentals/transactions#transaction-accessor-misalignment) for more details.
506+
</Callout>
507+
503508
#### Manual transactions
504509

505510
Before running a transaction, you need to obtain a *session*. Sessions act
@@ -567,14 +572,26 @@ Because of this, it is impossible to know how many time the transaction is going
567572
rely on globals. Note that although transaction functions might be
568573
executed multiple times, the queries inside it will always run only once.
569574

575+
<Callout type="info">
576+
As of Memgraph version 3.2, queries are categorized as **read** or **write** and the corresponding storage access is taken. This allows for better query parallelization and higher throughput.
577+
Using `executeRead` and `executeWrite` informs Memgraph what type of access is required for the transaction.
578+
An exception will be thrown if the user tries to execute a write query inside a read transaction. See [transaction accessor misalignment](/fundamentals/transactions#transaction-accessor-misalignment) for more details.
579+
</Callout>
580+
570581
##### Explicit transactions
571582

572583
You can achieve full control over transactions by manually starting them using the
573584
`session.beginTransaction()` method. You run queries inside an explicit transaction
574585
with the `Transaction.run()` method, as you do in transaction functions.
575586

587+
<Callout type="info">
588+
As of Memgraph version 3.2, queries are categorized as **read** or **write** and the corresponding storage access is taken. This allows for better query parallelization and higher throughput.
589+
Explicit transactions can cover a number of individual queries, but storage access is given at the start. For best performance, the user needs to declare whether the transaction should use read or write access.
590+
This can be done by setting the session's `defaultAccessMode` to `'READ'` or `'WRITE'`. This will, in turn, set the access mode of a transaction created via the `begin_transaction` function. Note that `executeRead` and `executeWrite` will override the session's default access.
591+
</Callout>
592+
576593
```js
577-
let session = driver.session({ database: 'neo4j' })
594+
let session = driver.session({ database: 'neo4j', defaultAccessMode: 'READ' })
578595
let transaction = await session.beginTransaction()
579596

580597
// await transaction.run('<QUERY 1>')
@@ -599,4 +616,4 @@ If you encounter serialization errors while using JavaScript client, we recommen
599616
referring to our [Serialization errors](/help-center/errors/serialization) page
600617
for detailed guidance on troubleshooting and best practices.
601618

602-
</Callout>
619+
</Callout>

pages/client-libraries/nodejs.mdx

+17
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,11 @@ a transaction to encapsulate the Cypher queries you're executing. This automatic
550550
transaction management simplifies the process of working with transactions.
551551
That method should be used when transaction control is unnecessary.
552552

553+
<Callout type="info">
554+
As of Memgraph version 3.2, queries are categorized as **read** or **write** and the corresponding storage access is taken. This allows for better query parallelization and higher throughput.
555+
For single query automatic transaction, no user input is required, Memgraph will deduce the access type needed at parse-time. See [transaction accessor misalignment](/fundamentals/transactions#transaction-accessor-misalignment) for more details.
556+
</Callout>
557+
553558
##### Process partial results
554559

555560
When dealing with queries that may take considerable time to execute or have a
@@ -672,13 +677,25 @@ when run several times. This means you shouldn't, for example, edit or rely on
672677
globals. Note that although transaction functions might be executed multiple
673678
times, the queries inside it will always run only once.
674679

680+
<Callout type="info">
681+
As of Memgraph version 3.2, queries are categorized as **read** or **write** and the corresponding storage access is taken. This allows for better query parallelization and higher throughput.
682+
Using `executeRead` and `executeWrite` informs Memgraph what type of access is required for the transaction.
683+
An exception will be thrown if the user tries to execute a write query inside a read transaction. See [transaction accessor misalignment](/fundamentals/transactions#transaction-accessor-misalignment) for more details.
684+
</Callout>
685+
675686
##### Explicit transactions
676687

677688
You can achieve full control over transactions by manually starting them using
678689
the `session.beginTransaction()` method. You run queries inside an explicit
679690
transaction with the `Transaction.run()` method, as you do in transaction
680691
functions.
681692

693+
<Callout type="info">
694+
As of Memgraph version 3.2, queries are categorized as **read** or **write** and the corresponding storage access is taken. This allows for better query parallelization and higher throughput.
695+
Explicit transactions can cover a number of individual queries, but storage access is given at the start. For best performance, the user needs to declare whether the transaction should use read or write access.
696+
This can be done by setting the session's `defaultAccessMode` to `'READ'` or `'WRITE'`. This will, in turn, set the access mode of a transaction created via the `begin_transaction` function. Note that `executeRead` and `executeWrite` will override the session's default access.
697+
</Callout>
698+
682699
```js
683700
let session = driver.session({ database: 'neo4j' })
684701
let transaction = await session.beginTransaction()

0 commit comments

Comments
 (0)