Skip to content

Instantly share code, notes, and snippets.

@fbiville
Created April 19, 2022 15:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fbiville/75fb086a3773fd7899359711a1c3720a to your computer and use it in GitHub Desktop.
Save fbiville/75fb086a3773fd7899359711a1c3720a to your computer and use it in GitHub Desktop.
Go Neo4j Driver - 5.0 context.Context example
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