-
Notifications
You must be signed in to change notification settings - Fork 6
🤖 Sandbox code update #3
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
fbiville
merged 1 commit into
master
from
graph-data-science-d71491d70ddc96913353db703635c9f56b2544024d35d12766ac565e82751253
Dec 7, 2020
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
code/csharp/Example.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// install dotnet core on your system | ||
// dotnet new console -o . | ||
// dotnet add package Neo4j.Driver | ||
// paste in this code into Program.cs | ||
// dotnet run | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Neo4j.Driver; | ||
|
||
namespace dotnet { | ||
class Example { | ||
static async Task Main() { | ||
var driver = GraphDatabase.Driver("bolt://<HOST>:<BOLTPORT>", | ||
AuthTokens.Basic("<USERNAME>", "<PASSWORD>")); | ||
|
||
var cypherQuery = | ||
@" | ||
MATCH (c:Person{name:$name})-[r:INTERACTS]->(other) | ||
RETURN other.name as person | ||
"; | ||
|
||
var session = driver.AsyncSession(o => o.WithDatabase("neo4j")); | ||
var result = await session.ReadTransactionAsync(async tx => { | ||
var r = await tx.RunAsync(cypherQuery, | ||
new { name="Jaime Lannister"}); | ||
return await r.ToListAsync(); | ||
}); | ||
|
||
await session?.CloseAsync(); | ||
foreach (var row in result) | ||
Console.WriteLine(row["person"].As<string>()); | ||
|
||
} | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
code/go/example.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// go mod init main | ||
// go run example.go | ||
package main | ||
import ( | ||
"fmt" | ||
"github.com/neo4j/neo4j-go-driver/neo4j" //Go 1.8 | ||
) | ||
func main() { | ||
s, err := runQuery("bolt://<HOST>:<BOLTPORT>", "<USERNAME>", "<PASSWORD>") | ||
if err != nil { | ||
panic(err) | ||
} | ||
fmt.Println(s) | ||
} | ||
func runQuery(uri, username, password string) ([]string, error) { | ||
configForNeo4j4 := func(conf *neo4j.Config) { conf.Encrypted = false } | ||
driver, err := neo4j.NewDriver(uri, neo4j.BasicAuth(username, password, ""), configForNeo4j4) | ||
if err != nil { | ||
return nil, err | ||
} | ||
defer driver.Close() | ||
sessionConfig := neo4j.SessionConfig{AccessMode: neo4j.AccessModeRead, DatabaseName: "neo4j"} | ||
session, err := driver.NewSession(sessionConfig) | ||
if err != nil { | ||
return nil, err | ||
} | ||
defer session.Close() | ||
results, err := session.ReadTransaction(func(transaction neo4j.Transaction) (interface{}, error) { | ||
result, err := transaction.Run( | ||
` | ||
MATCH (c:Person{name:$name})-[r:INTERACTS]->(other) | ||
RETURN other.name as person | ||
`, map[string]interface{}{ | ||
"name": "Jaime Lannister", | ||
}) | ||
if err != nil { | ||
return nil, err | ||
} | ||
var arr []string | ||
for result.Next() { | ||
value, found := result.Record().Get("person") | ||
if found { | ||
arr = append(arr, value.(string)) | ||
} | ||
} | ||
if err = result.Err(); err != nil { | ||
return nil, err | ||
} | ||
return arr, nil | ||
}) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return results.([]string), err | ||
} |
36 changes: 36 additions & 0 deletions
code/java/Example.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Add your the driver dependency to your pom.xml build.gradle etc. | ||
// Java Driver Dependency: http://search.maven.org/#artifactdetails|org.neo4j.driver|neo4j-java-driver|4.0.1|jar | ||
// Reactive Streams http://search.maven.org/#artifactdetails|org.reactivestreams|reactive-streams|1.0.3|jar | ||
// download jars into current directory | ||
// java -cp "*" Example.java | ||
|
||
import org.neo4j.driver.*; | ||
import static org.neo4j.driver.Values.parameters; | ||
|
||
public class Example { | ||
|
||
public static void main(String...args) { | ||
|
||
Driver driver = GraphDatabase.driver("bolt://<HOST>:<BOLTPORT>", | ||
AuthTokens.basic("<USERNAME>","<PASSWORD>")); | ||
|
||
try (Session session = driver.session(SessionConfig.forDatabase("neo4j"))) { | ||
|
||
String cypherQuery = | ||
"MATCH (c:Person{name:$name})-[r:INTERACTS]->(other)" + | ||
"RETURN other.name as person"; | ||
|
||
var result = session.readTransaction( | ||
tx -> tx.run(cypherQuery, | ||
parameters("name","Jaime Lannister")) | ||
.list()); | ||
|
||
for (Record record : result) { | ||
System.out.println(record.get("person").asString()); | ||
} | ||
} | ||
driver.close(); | ||
} | ||
} | ||
|
||
|
28 changes: 28 additions & 0 deletions
code/javascript/example.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// npm install --save neo4j-driver | ||
// node example.js | ||
const neo4j = require('neo4j-driver'); | ||
const driver = neo4j.driver('bolt://<HOST>:<BOLTPORT>', | ||
neo4j.auth.basic('<USERNAME>', '<PASSWORD>'), | ||
{/* encrypted: 'ENCRYPTION_OFF' */}); | ||
|
||
const query = | ||
` | ||
MATCH (c:Person{name:$name})-[r:INTERACTS]->(other) | ||
RETURN other.name as person | ||
`; | ||
|
||
const params = {"name": "Jaime Lannister"}; | ||
|
||
const session = driver.session({database:"neo4j"}); | ||
|
||
session.run(query, params) | ||
.then((result) => { | ||
result.records.forEach((record) => { | ||
console.log(record.get('person')); | ||
}); | ||
session.close(); | ||
driver.close(); | ||
}) | ||
.catch((error) => { | ||
console.error(error); | ||
}); |
23 changes: 23 additions & 0 deletions
code/python/example.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# pip3 install neo4j-driver | ||
# python3 example.py | ||
|
||
from neo4j import GraphDatabase, basic_auth | ||
|
||
driver = GraphDatabase.driver( | ||
"bolt://<HOST>:<BOLTPORT>", | ||
auth=basic_auth("<USERNAME>", "<PASSWORD>")) | ||
|
||
cypher_query = ''' | ||
MATCH (c:Person{name:$name})-[r:INTERACTS]->(other) | ||
RETURN other.name as person | ||
''' | ||
|
||
with driver.session(database="neo4j") as session: | ||
results = session.read_transaction( | ||
lambda tx: tx.run(cypher_query, | ||
name="Jaime Lannister").data()) | ||
|
||
for record in results: | ||
print(record['person']) | ||
|
||
driver.close() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.