Created
April 19, 2022 15:38
-
-
Save fbiville/75fb086a3773fd7899359711a1c3720a to your computer and use it in GitHub Desktop.
Go Neo4j Driver - 5.0 context.Context example
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
package main | |
import ( | |
"context" | |
"fmt" | |
"github.com/neo4j/neo4j-go-driver/v5/neo4j" | |
"time" | |
) | |
func main() { | |
parentContext := context.Background() | |
ctx, cancelFunc := context.WithTimeout(parentContext, 5*time.Second) | |
defer cancelFunc() | |
driver, err := neo4j.NewDriverWithContext("neo4j://localhost", | |
neo4j.BasicAuth("neo4j", "s3cr3t", ""), | |
func(config *neo4j.Config) { | |
config.Log = neo4j.ConsoleLogger(neo4j.DEBUG) | |
}) | |
if err != nil { | |
panic(err) | |
} | |
defer driver.Close(ctx) | |
session := driver.NewSession(neo4j.SessionConfig{ | |
BoltLogger: neo4j.ConsoleBoltLogger(), | |
}) | |
defer session.Close(ctx) | |
results, err := session.Run(ctx, "CALL apoc.util.sleep(6000) RETURN 42", nil) | |
if err != nil { | |
panic(err) | |
} | |
record, err := results.Single(ctx) | |
if err != nil { | |
panic(err) | |
} | |
fortyTwo, _ := record.Get("42") | |
fmt.Printf("%v\n", fortyTwo) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment