Skip to content

Add 'connect with drivers' guides #40

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions documentation/connect-drivers-dotnet.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
== Installation

The .NET driver is distributed via the NuGet Gallery.
To find the latest version of the driver, visit
link:https://www.nuget.org/packages/Neo4j.Driver/.

== Connect to the database


[source, csharp, role=nocollapse]
----
using Neo4j.Driver;

const string uri = "{neo4j-database-uri}";
const string user = "<Username>";
const string password = "<Password>";

await using var driver = GraphDatabase.Driver(uri, AuthTokens.Basic(user, password));
await driver.VerifyConnectivityAsync();
----
43 changes: 43 additions & 0 deletions documentation/connect-drivers-go.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
== Installation

From within a module, use `go get` to install the link:https://pkg.go.dev/github.com/neo4j/neo4j-go-driver/v5/[Neo4j Go Driver]:

[source, bash]
----
go get github.com/neo4j/neo4j-go-driver/v5
----

link:https://neo4j.com/docs/go-manual/current/install/#install-driver[More info on installing the driver ^]


== Connect to the database

Connect to a database by creating a `DriverWithContext` object and providing a URL and an authentication token.
Once you have a `DriverWithContext` instance, use the `.VerifyConnectivity()` method to ensure that a working connection can be established.

[source, go, role=nocollapse]
----
package main

import (
"context"
"github.com/neo4j/neo4j-go-driver/v5/neo4j"
)

func main() {
ctx := context.Background()
// URI examples: "neo4j://localhost", "neo4j+s://xxx.databases.neo4j.io"
dbUri := "{neo4j-database-uri}"
dbUser := "<Username>"
dbPassword := "<Password>"
driver, err := neo4j.NewDriverWithContext(
dbUri,
neo4j.BasicAuth(dbUser, dbPassword, ""))
defer driver.Close(ctx)

err = driver.VerifyConnectivity(ctx)
if err != nil {
panic(err)
}
}
----
42 changes: 42 additions & 0 deletions documentation/connect-drivers-java.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
== Install Driver

Add the Neo4j Java driver to the list of dependencies in the `pom.xml` of your Maven project:

[source, xml, subs="attributes+"]
----
<dependency>
<groupId>org.neo4j.driver</groupId>
<artifactId>neo4j-java-driver</artifactId>
<version>5.20.0</version>
</dependency>
----

link:https://neo4j.com/docs/java-manual/current/install/#install-driver[More info on installing the driver ^]

== Connect to the database

Connect to a database by creating a `Driver` object and providing a URL and an authentication token.
Once you have a `Driver` instance, use the `.verifyConnectivity()` method to ensure that a working connection can be established.

[source, java, role=nocollapse]
----
package demo;

import org.neo4j.driver.AuthTokens;
import org.neo4j.driver.GraphDatabase;

public class App {

public static void main(String... args) {

// URI examples: "neo4j://localhost", "neo4j+s://xxx.databases.neo4j.io"
final String dbUri = "{neo4j-database-uri}";
final String dbUser = "<Username>";
final String dbPassword = "<Password>";

try (var driver = GraphDatabase.driver(dbUri, AuthTokens.basic(dbUser, dbPassword))) {
driver.verifyConnectivity();
}
}
}
----
37 changes: 37 additions & 0 deletions documentation/connect-drivers-javascript.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
== Installation

Install the Neo4j JavaScript driver with `npm`:

[source,bash]
----
npm i neo4j-driver
----

link:https://neo4j.com/docs/javascript-manual/current/install/#install-driver[More info on installing the driver ^]


== Connect to the database

Connect to a database by creating a `Driver` object and providing a URL and an authentication token.
Once you have a `Driver` instance, use the `.getServerInfo()` method to ensure that a working connection can be established by retrieving the server information.

[source, javascript]
----
var neo4j = require('neo4j-driver');
(async () => {
// URI examples: 'neo4j://localhost', 'neo4j+s://xxx.databases.neo4j.io'
const URI = '{neo4j-database-uri}'
const USER = '<Username>'
const PASSWORD = '<Password>'
let driver

try {
driver = neo4j.driver(URI, neo4j.auth.basic(USER, PASSWORD))
const serverInfo = await driver.getServerInfo()
console.log('Connection established')
console.log(serverInfo)
} catch(err) {
console.log(`Connection error\n${err}\nCause: ${err.cause}`)
}
})();
----
25 changes: 25 additions & 0 deletions documentation/connect-drivers-python.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
== Install Driver

[source, bash]
----
pip install neo4j
----

link:https://neo4j.com/docs/python-manual/current/install/#install-driver[More info on installing the driver ^]

== Connect to the Database

Connect to a database by creating a `Driver` object and providing a URL and an authentication token.
Once you have a `Driver` instance, use the `.verify_connectivity()` method to ensure that a working connection can be established.

[source, python]
----
from neo4j import GraphDatabase

# URI examples: "neo4j://localhost", "neo4j+s://xxx.databases.neo4j.io"
URI = "{neo4j-database-uri}"
AUTH = ("<Username>", "<Password>")

with GraphDatabase.driver(URI, auth=AUTH) as driver:
driver.verify_connectivity()
----