### Go Driver Authentication Setup Source: https://pkg.go.dev/github.com/neo4j/neo4j-go-driver/v5/%40v5.8.0/neo4j/auth_tab=importedby Demonstrates how to set up authentication when creating a new Neo4j driver instance in Go. It shows examples for basic and custom authentication. ```go package main import ( "context" "log" "github.com/neo4j/neo4j-go-driver/v5/neo4j" ) func main() { // Example 1: Basic Authentication dbasicAuth := neo4j.BasicAuth("neo4j", "password") ddriver, err := neo4j.NewDriver("bolt://localhost:7687", basicAuth) if err != nil { log.Fatalf("Failed to create driver with basic auth: %v", err) } defer driver.Close(context.Background()) // Example 2: Custom Authentication (Illustrative) // Define your custom authentication function myCustomAuth := func(ctx context.Context) (neo4j.AuthToken, error) { // Replace with your actual custom authentication logic return neo4j.PasswordAuth("custom_user", "custom_password"), nil } dcustomDriver, err := neo4j.NewDriver("bolt://localhost:7687", neo4j.CustomAuth(myCustomAuth)) if err != nil { log.Fatalf("Failed to create driver with custom auth: %v", err) } defer customDriver.Close(context.Background()) log.Println("Drivers created successfully.") } ``` -------------------------------- ### Neo4j Go Driver v5 Examples Source: https://pkg.go.dev/github.com/neo4j/neo4j-go-driver/v5/%40v5.20.0/neo4j This section provides various examples demonstrating how to use the Neo4j Go driver v5. Examples cover configuration, authentication, query execution, and session management. ```go // Config (DisableNoCategories) // Example demonstrating how to configure the driver to disable no categories. // See: https://pkg.go.dev/github.com/neo4j/neo4j-go-driver/v5%40v5.20.0/neo4j#example-Config-DisableNoCategories // Config (DisableSomeCategories) // Example demonstrating how to configure the driver to disable specific categories. // See: https://pkg.go.dev/github.com/neo4j/neo4j-go-driver/v5%40v5.20.0/neo4j#example-Config-DisableSomeCategories // Config (MinimumSeverityLevel) // Example demonstrating how to set the minimum severity level for logging. // See: https://pkg.go.dev/github.com/neo4j/neo4j-go-driver/v5%40v5.20.0/neo4j#example-Config-MinimumSeverityLevel // DriverWithContext (VerifyAuthentication) // Example demonstrating how to verify authentication with the driver. // See: https://pkg.go.dev/github.com/neo4j/neo4j-go-driver/v5%40v5.20.0/neo4j#example-DriverWithContext-VerifyAuthentication // DriverWithContext (VerifyAuthenticationDriverLevel) // Example demonstrating driver-level authentication verification. // See: https://pkg.go.dev/github.com/neo4j/neo4j-go-driver/v5%40v5.20.0/neo4j#example-DriverWithContext-VerifyAuthenticationDriverLevel // ExecuteQuery // Example demonstrating how to execute a query. // See: https://pkg.go.dev/github.com/neo4j/neo4j-go-driver/v5%40v5.20.0/neo4j#example-ExecuteQuery // ExecuteQuery (DefaultBookmarkManagerExplicitReuse) // Example showing explicit reuse of the default bookmark manager. // See: https://pkg.go.dev/github.com/neo4j/neo4j-go-driver/v5%40v5.20.0/neo4j#example-ExecuteQuery-DefaultBookmarkManagerExplicitReuse // ExecuteQuery (SelfCausalConsistency) // Example demonstrating self-causal consistency in query execution. // See: https://pkg.go.dev/github.com/neo4j/neo4j-go-driver/v5%40v5.20.0/neo4j#example-ExecuteQuery-SelfCausalConsistency // ExecuteRead // Example demonstrating how to execute a read operation. // See: https://pkg.go.dev/github.com/neo4j/neo4j-go-driver/v5%40v5.20.0/neo4j#example-ExecuteRead // ExecuteWrite // Example demonstrating how to execute a write operation. // See: https://pkg.go.dev/github.com/neo4j/neo4j-go-driver/v5%40v5.20.0/neo4j#example-ExecuteWrite // GetProperty // Example demonstrating how to retrieve a property. // See: https://pkg.go.dev/github.com/neo4j/neo4j-go-driver/v5%40v5.20.0/neo4j#example-GetProperty // GetRecordValue // Example demonstrating how to get a value from a record. // See: https://pkg.go.dev/github.com/neo4j/neo4j-go-driver/v5%40v5.20.0/neo4j#example-GetRecordValue // SessionConfig (DisableNoCategories) // Example showing session configuration to disable no categories. // See: https://pkg.go.dev/github.com/neo4j/neo4j-go-driver/v5%40v5.20.0/neo4j#example-SessionConfig-DisableNoCategories // SessionConfig (DisableSomeCategories) // Example showing session configuration to disable specific categories. // See: https://pkg.go.dev/github.com/neo4j/neo4j-go-driver/v5%40v5.20.0/neo4j#example-SessionConfig-DisableSomeCategories // SessionConfig (MinimumSeverityLevel) // Example showing session configuration for minimum severity level. // See: https://pkg.go.dev/github.com/neo4j/neo4j-go-driver/v5%40v5.20.0/neo4j#example-SessionConfig-MinimumSeverityLevel ``` -------------------------------- ### Neo4j Session Configuration Examples Source: https://pkg.go.dev/github.com/neo4j/neo4j-go-driver/v5/%40v5.12.0/neo4j Examples demonstrating how to configure Neo4j sessions, specifically for notification settings. ```go // Example (DisableNoCategories) // Example (DisableSomeCategories) // Example (MinimumSeverityLevel) ``` -------------------------------- ### Neo4j Go Driver Usage Example Source: https://pkg.go.dev/github.com/neo4j/neo4j-go-driver/v5/%40v5 Demonstrates basic usage of the neo4j-go-driver to establish a connection and execute a Cypher query. This snippet shows how to create a driver, get a session, and run a simple query. ```go package main import ( "context" "fmt" "log" "github.com/neo4j/neo4j-go-driver/v5/neo4j" ) func main() { ctx := context.Background() driver, err := neo4j.NewDriver("bolt://localhost:7687", neo4j.NoAuth()) if err != nil { log.Fatalf("Failed to create driver: %v", err) } defer driver.Close(ctx) ssession := driver.AcquireSession(ctx, neo4j.SessionConfig{DatabaseName: "neo4j"}) defer session.Close(ctx) result, err := session.ExecuteWrite(ctx, func(tx neo4j.ManagedTransaction) (any, error) { _, err := tx.Run(ctx, "CREATE (a:Person {name: $name})", map[string]interface{}{"name": "Alice"}) if err != nil { return nil, err } return nil, nil }) if err != nil { log.Fatalf("Failed to execute write: %v", err) } fmt.Printf("Write operation result: %v\n", result) readResult, err := session.ExecuteRead(ctx, func(tx neo4j.ManagedTransaction) (any, error) { result, err := tx.Run(ctx, "MATCH (a:Person {name: $name}) RETURN a.name AS name", map[string]interface{}{"name": "Alice"}) if err != nil { return nil, err } record, err := result.Single(ctx) if err != nil { return nil, err } return record.Values[0], nil }) if err != nil { log.Fatalf("Failed to execute read: %v", err) } fmt.Printf("Read operation result: %v\n", readResult) } ``` -------------------------------- ### Neo4j Go Driver v5 Examples Source: https://pkg.go.dev/github.com/neo4j/neo4j-go-driver/v5/%40v5.19.0/neo4j This section provides various examples demonstrating the usage of the Neo4j Go driver v5. Examples cover configuration settings, authentication, query execution, and session management. ```go // Example: Config (DisableNoCategories) // Demonstrates configuring the driver to disable no-category logging. // import "github.com/neo4j/neo4j-go-driver/v5/neo4j" // config := neo4j.Config{ LogCategory: neo4j.LogCategoryNone } // Example: Config (DisableSomeCategories) // Demonstrates configuring the driver to disable specific logging categories. // import "github.com/neo4j/neo4j-go-driver/v5/neo4j" // config := neo4j.Config{ LogCategory: neo4j.LogCategoryBolt | neo4j.LogCategoryDriver } // Example: Config (MinimumSeverityLevel) // Demonstrates setting the minimum severity level for logging. // import "github.com/neo4j/neo4j-go-driver/v5/neo4j" // config := neo4j.Config{ LogSeverityLevel: neo4j.Error } // Example: DriverWithContext (VerifyAuthentication) // Demonstrates verifying authentication with the driver. // import "context" // import "github.com/neo4j/neo4j-go-driver/v5/neo4j" // ctx := context.Background() // driver, _ := neo4j.NewDriverWithContext("bolt://localhost:7687", neo4j.AuthNone()) // defer driver.Close(ctx) // err := driver.VerifyAuthentication(ctx) // Example: DriverWithContext (VerifyAuthenticationDriverLevel) // Demonstrates verifying authentication at the driver level. // import "context" // import "github.com/neo4j/neo4j-go-driver/v5/neo4j" // ctx := context.Background() // driver, _ := neo4j.NewDriverWithContext("bolt://localhost:7687", neo4j.AuthNone()) // defer driver.Close(ctx) // err := driver.VerifyAuthentication(ctx) // Example: ExecuteQuery // Demonstrates executing a read query. // import "context" // import "github.com/neo4j/neo4j-go-driver/v5/neo4j" // ctx := context.Background() // driver, _ := neo4j.NewDriverWithContext("bolt://localhost:7687", neo4j.AuthNone()) // defer driver.Close(ctx) // session := driver.NewSession(neo4j.SessionConfig{DatabaseName: "neo4j"}) // defer session.Close(ctx) // result, _ := session.ExecuteQuery(ctx, "RETURN 1", nil, neo4j.ExecuteQuerySettings{}) // Example: ExecuteQuery (DefaultBookmarkManagerExplicitReuse) // Demonstrates explicit reuse of the default bookmark manager. // import "context" // import "github.com/neo4j/neo4j-go-driver/v5/neo4j" // ctx := context.Background() // driver, _ := neo4j.NewDriverWithContext("bolt://localhost:7687", neo4j.AuthNone()) // defer driver.Close(ctx) // session := driver.NewSession(neo4j.SessionConfig{DatabaseName: "neo4j"}) // defer session.Close(ctx) // result, _ := session.ExecuteQuery(ctx, "RETURN 1", nil, neo4j.ExecuteQuerySettings{}) // Example: ExecuteQuery (SelfCausalConsistency) // Demonstrates self-causal consistency in query execution. // import "context" // import "github.com/neo4j/neo4j-go-driver/v5/neo4j" // ctx := context.Background() // driver, _ := neo4j.NewDriverWithContext("bolt://localhost:7687", neo4j.AuthNone()) // defer driver.Close(ctx) // session := driver.NewSession(neo4j.SessionConfig{DatabaseName: "neo4j"}) // defer session.Close(ctx) // result, _ := session.ExecuteQuery(ctx, "RETURN 1", nil, neo4j.ExecuteQuerySettings{}) // Example: ExecuteRead // Demonstrates executing a read operation within a session. // import "context" // import "github.com/neo4j/neo4j-go-driver/v5/neo4j" // ctx := context.Background() // driver, _ := neo4j.NewDriverWithContext("bolt://localhost:7687", neo4j.AuthNone()) // defer driver.Close(ctx) // session := driver.NewSession(neo4j.SessionConfig{DatabaseName: "neo4j"}) // defer session.Close(ctx) // result, _ := session.ExecuteRead(ctx, func(tx neo4j.Transaction) (interface{}, error) { return nil, nil }, neo4j.ExecuteReadSettings{}) // Example: ExecuteWrite // Demonstrates executing a write operation within a session. // import "context" // import "github.com/neo4j/neo4j-go-driver/v5/neo4j" // ctx := context.Background() // driver, _ := neo4j.NewDriverWithContext("bolt://localhost:7687", neo4j.AuthNone()) // defer driver.Close(ctx) // session := driver.NewSession(neo4j.SessionConfig{DatabaseName: "neo4j"}) // defer session.Close(ctx) // result, _ := session.ExecuteWrite(ctx, func(tx neo4j.Transaction) (interface{}, error) { return nil, nil }, neo4j.ExecuteWriteSettings{}) // Example: GetProperty // Demonstrates retrieving a property from a record. // import "github.com/neo4j/neo4j-go-driver/v5/neo4j" // // Assuming 'record' is a neo4j.Record // // value := record.GetProperty("propertyName") // Example: GetRecordValue // Demonstrates retrieving a value from a record by index. // import "github.com/neo4j/neo4j-go-driver/v5/neo4j" // // Assuming 'record' is a neo4j.Record // // value := record.GetRecordValue(0) // Example: SessionConfig (DisableNoCategories) // Demonstrates configuring a session to disable no-category logging. // import "github.com/neo4j/neo4j-go-driver/v5/neo4j" // sessionConfig := neo4j.SessionConfig{ LogCategory: neo4j.LogCategoryNone } // Example: SessionConfig (DisableSomeCategories) // Demonstrates configuring a session to disable specific logging categories. // import "github.com/neo4j/neo4j-go-driver/v5/neo4j" // sessionConfig := neo4j.SessionConfig{ LogCategory: neo4j.LogCategoryBolt | neo4j.LogCategoryDriver } // Example: SessionConfig (MinimumSeverityLevel) // Demonstrates setting the minimum severity level for session logging. // import "github.com/neo4j/neo4j-go-driver/v5/neo4j" // sessionConfig := neo4j.SessionConfig{ LogSeverityLevel: neo4j.Error } ``` -------------------------------- ### Neo4j Go Driver v5 Examples Source: https://pkg.go.dev/github.com/neo4j/neo4j-go-driver/v5/%40v5.28.1/neo4j This section provides various examples demonstrating how to use the Neo4j Go driver v5. Examples cover configuration settings like disabling categories and setting severity levels, driver and session configurations, authentication verification, and executing read/write queries. ```go // Config (DisableNoCategories) // Example demonstrating how to disable no-categories logging in the driver configuration. // Config (DisableSomeCategories) // Example demonstrating how to disable specific categories of logging in the driver configuration. // Config (MinimumSeverityLevel) // Example demonstrating how to set the minimum severity level for logging in the driver configuration. // DriverWithContext (VerifyAuthentication) // Example showing how to verify authentication using the driver with context. // DriverWithContext (VerifyAuthenticationDriverLevel) // Example demonstrating driver-level authentication verification. // ExecuteQuery // Basic example of executing a Cypher query. // ExecuteQuery (DefaultBookmarkManagerExplicitReuse) // Example of explicitly reusing the default bookmark manager when executing queries. // ExecuteQuery (SelfCausalConsistency) // Example demonstrating self-causal consistency when executing queries. // ExecuteRead // Example of executing a read-only operation. // ExecuteWrite // Example of executing a write operation. // GetProperty // Example of retrieving a property from a record. // GetRecordValue // Example of retrieving a value from a record. // SessionConfig (DisableNoCategories) // Example demonstrating how to disable no-categories logging in the session configuration. // SessionConfig (DisableSomeCategories) // Example demonstrating how to disable specific categories of logging in the session configuration. // SessionConfig (MinimumSeverityLevel) // Example demonstrating how to set the minimum severity level for logging in the session configuration. ``` -------------------------------- ### Neo4j Go Driver v5 Examples Source: https://pkg.go.dev/github.com/neo4j/neo4j-go-driver/v5/%40v5.25.0/neo4j This section provides various code examples for using the Neo4j Go driver v5. The examples cover driver configuration, authentication verification, executing read and write queries, retrieving properties and record values, and session configuration. ```go // Example: Config (DisableNoCategories) // Example: Config (DisableSomeCategories) // Example: Config (MinimumSeverityLevel) // Example: DriverWithContext (VerifyAuthentication) // Example: DriverWithContext (VerifyAuthenticationDriverLevel) // Example: ExecuteQuery // Example: ExecuteQuery (DefaultBookmarkManagerExplicitReuse) // Example: ExecuteQuery (SelfCausalConsistency) // Example: ExecuteRead // Example: ExecuteWrite // Example: GetProperty // Example: GetRecordValue // Example: SessionConfig (DisableNoCategories) // Example: SessionConfig (DisableSomeCategories) // Example: SessionConfig (MinimumSeverityLevel) ``` -------------------------------- ### Neo4j Go Driver v5 Examples Source: https://pkg.go.dev/github.com/neo4j/neo4j-go-driver/v5/%40v5.24.0/neo4j This section provides various examples demonstrating the usage of the Neo4j Go driver v5. These examples cover configuration options, authentication, query execution, and session management. ```go // Example: Config (DisableNoCategories) // Demonstrates configuring the driver to disable logging for 'NoCategories'. // See: https://pkg.go.dev/github.com/neo4j/neo4j-go-driver/v5@v5.24.0/neo4j#example-Config-DisableNoCategories // Example: Config (DisableSomeCategories) // Demonstrates configuring the driver to disable logging for specific categories. // See: https://pkg.go.dev/github.com/neo4j/neo4j-go-driver/v5@v5.24.0/neo4j#example-Config-DisableSomeCategories // Example: Config (MinimumSeverityLevel) // Demonstrates setting a minimum severity level for driver logs. // See: https://pkg.go.dev/github.com/neo4j/neo4j-go-driver/v5@v5.24.0/neo4j#example-Config-MinimumSeverityLevel // Example: DriverWithContext (VerifyAuthentication) // Shows how to verify authentication using a driver with context. // See: https://pkg.go.dev/github.com/neo4j/neo4j-go-driver/v5@v5.24.0/neo4j#example-DriverWithContext-VerifyAuthentication // Example: DriverWithContext (VerifyAuthenticationDriverLevel) // Demonstrates driver-level authentication verification. // See: https://pkg.go.dev/github.com/neo4j/neo4j-go-driver/v5@v5.24.0/neo4j#example-DriverWithContext-VerifyAuthenticationDriverLevel // Example: ExecuteQuery // A basic example of executing a Cypher query. // See: https://pkg.go.dev/github.com/neo4j/neo4j-go-driver/v5@v5.24.0/neo4j#example-ExecuteQuery // Example: ExecuteQuery (DefaultBookmarkManagerExplicitReuse) // Demonstrates explicit reuse of the default bookmark manager when executing queries. // See: https://pkg.go.dev/github.com/neo4j/neo4j-go-driver/v5@v5.24.0/neo4j#example-ExecuteQuery-DefaultBookmarkManagerExplicitReuse // Example: ExecuteQuery (SelfCausalConsistency) // Shows how to achieve self-causal consistency when executing queries. // See: https://pkg.go.dev/github.com/neo4j/neo4j-go-driver/v5@v5.24.0/neo4j#example-ExecuteQuery-SelfCausalConsistency // Example: ExecuteRead // Demonstrates executing a read-only operation. // See: https://pkg.go.dev/github.com/neo4j/neo4j-go-driver/v5@v5.24.0/neo4j#example-ExecuteRead // Example: ExecuteWrite // Demonstrates executing a write operation. // See: https://pkg.go.dev/github.com/neo4j/neo4j-go-driver/v5@v5.24.0/neo4j#example-ExecuteWrite // Example: GetProperty // Shows how to retrieve a property from a Neo4j record. // See: https://pkg.go.dev/github.com/neo4j/neo4j-go-driver/v5@v5.24.0/neo4j#example-GetProperty // Example: GetRecordValue // Demonstrates how to get a value from a Neo4j record. // See: https://pkg.go.dev/github.com/neo4j/neo4j-go-driver/v5@v5.24.0/neo4j#example-GetRecordValue // Example: SessionConfig (DisableNoCategories) // Demonstrates configuring a session to disable logging for 'NoCategories'. // See: https://pkg.go.dev/github.com/neo4j/neo4j-go-driver/v5@v5.24.0/neo4j#example-SessionConfig-DisableNoCategories // Example: SessionConfig (DisableSomeCategories) // Demonstrates configuring a session to disable logging for specific categories. // See: https://pkg.go.dev/github.com/neo4j/neo4j-go-driver/v5@v5.24.0/neo4j#example-SessionConfig-DisableSomeCategories // Example: SessionConfig (MinimumSeverityLevel) // Demonstrates setting a minimum severity level for session logs. // See: https://pkg.go.dev/github.com/neo4j/neo4j-go-driver/v5@v5.24.0/neo4j#example-SessionConfig-MinimumSeverityLevel ``` -------------------------------- ### Neo4j Go Driver v5 Examples Source: https://pkg.go.dev/github.com/neo4j/neo4j-go-driver/v5/%40v5.21.0/neo4j Code examples demonstrating various functionalities of the Neo4j Go driver v5. These examples cover configuration, authentication, query execution, and session management. ```go // Config (DisableNoCategories) // Example demonstrating how to configure the driver to disable no-category logging. // See: https://pkg.go.dev/github.com/neo4j/neo4j-go-driver/v5@v5.21.0/neo4j#example-Config-DisableNoCategories // Config (DisableSomeCategories) // Example demonstrating how to configure the driver to disable specific logging categories. // See: https://pkg.go.dev/github.com/neo4j/neo4j-go-driver/v5@v5.21.0/neo4j#example-Config-DisableSomeCategories // Config (MinimumSeverityLevel) // Example demonstrating how to set the minimum severity level for driver logs. // See: https://pkg.go.dev/github.com/neo4j/neo4j-go-driver/v5@v5.21.0/neo4j#example-Config-MinimumSeverityLevel // DriverWithContext (VerifyAuthentication) // Example demonstrating how to verify authentication with the Neo4j driver. // See: https://pkg.go.dev/github.com/neo4j/neo4j-go-driver/v5@v5.21.0/neo4j#example-DriverWithContext-VerifyAuthentication // DriverWithContext (VerifyAuthenticationDriverLevel) // Example demonstrating driver-level authentication verification. // See: https://pkg.go.dev/github.com/neo4j/neo4j-go-driver/v5@v5.21.0/neo4j#example-DriverWithContext-VerifyAuthenticationDriverLevel // ExecuteQuery // Example demonstrating how to execute a Cypher query. // See: https://pkg.go.dev/github.com/neo4j/neo4j-go-driver/v5@v5.21.0/neo4j#example-ExecuteQuery // ExecuteQuery (DefaultBookmarkManagerExplicitReuse) // Example showing explicit reuse of the default bookmark manager when executing queries. // See: https://pkg.go.dev/github.com/neo4j/neo4j-go-driver/v5@v5.21.0/neo4j#example-ExecuteQuery-DefaultBookmarkManagerExplicitReuse // ExecuteQuery (SelfCausalConsistency) // Example demonstrating self-causal consistency when executing queries. // See: https://pkg.go.dev/github.com/neo4j/neo4j-go-driver/v5@v5.21.0/neo4j#example-ExecuteQuery-SelfCausalConsistency // ExecuteRead // Example demonstrating how to execute a read operation. // See: https://pkg.go.dev/github.com/neo4j/neo4j-go-driver/v5@v5.21.0/neo4j#example-ExecuteRead // ExecuteWrite // Example demonstrating how to execute a write operation. // See: https://pkg.go.dev/github.com/neo4j/neo4j-go-driver/v5@v5.21.0/neo4j#example-ExecuteWrite // GetProperty // Example demonstrating how to retrieve a property value. // See: https://pkg.go.dev/github.com/neo4j/neo4j-go-driver/v5@v5.21.0/neo4j#example-GetProperty // GetRecordValue // Example demonstrating how to retrieve a value from a record. // See: https://pkg.go.dev/github.com/neo4j/neo4j-go-driver/v5@v5.21.0/neo4j#example-GetRecordValue // SessionConfig (DisableNoCategories) // Example showing session configuration to disable no-category logging. // See: https://pkg.go.dev/github.com/neo4j/neo4j-go-driver/v5@v5.21.0/neo4j#example-SessionConfig-DisableNoCategories // SessionConfig (DisableSomeCategories) // Example showing session configuration to disable specific logging categories. // See: https://pkg.go.dev/github.com/neo4j/neo4j-go-driver/v5@v5.21.0/neo4j#example-SessionConfig-DisableSomeCategories // SessionConfig (MinimumSeverityLevel) // Example showing session configuration to set the minimum severity level for logs. // See: https://pkg.go.dev/github.com/neo4j/neo4j-go-driver/v5@v5.21.0/neo4j#example-SessionConfig-MinimumSeverityLevel ``` -------------------------------- ### Neo4j Go Driver v5 Usage Source: https://pkg.go.dev/github.com/neo4j/neo4j-go-driver/v5/%40v5.13.0/neo4j_tab=importedby This snippet demonstrates the basic usage of the Neo4j Go driver v5. It covers establishing a connection, executing Cypher queries, and handling results. This is a foundational example for developers starting with the driver. ```go package main import ( "context" "fmt" "log" "github.com/neo4j/neo4j-go-driver/v5/neo4j" ) func main() { // Replace with your Neo4j connection details uri := "neo4j://localhost:7687" username := "neo4j" password := "password" driver, err := neo4j.NewDriverWithContext(uri, neo4j.AuthNPlain(username, password), func(conf *neo4j.Config) { conf.Encrypted = false // Set to true if using Bolt+TLS }) if err != nil { log.Fatalf("Failed to create driver: %v", err) } defer driver.Close(context.Background()) session := driver.NewSession(neo4j.SessionConfig{DatabaseName: "neo4j"}) defer session.Close(context.Background()) // Example: Create a node _, err = session.ExecuteWrite(context.Background(), func(tx neo4j.ManagedTransaction) (any, error) { result, err := tx.Run( "CREATE (a:Person {name: $name})", map[string]any{ "name": "Alice", }, ) if err != nil { return nil, err } return result.Summary().Counters().NodesCreated(), nil }) if err != nil { log.Fatalf("Failed to create node: %v", err) } fmt.Println("Node created successfully.") // Example: Read nodes result, err := session.ExecuteRead(context.Background(), func(tx neo4j.ManagedTransaction) (any, error) { result, err := tx.Run( "MATCH (a:Person) RETURN a.name AS name", nil, ) if err != nil { return nil, err } var names []string for result.Next(context.Background()) { name, ok := result.Record().Values("name")[0].(string) if ok { names = append(names, name) } } return names, result.Err() }) if err != nil { log.Fatalf("Failed to read nodes: %v", err) } fmt.Printf("Found nodes: %v\n", result) } ``` -------------------------------- ### Neo4j Go Driver v5 Usage Source: https://pkg.go.dev/github.com/neo4j/neo4j-go-driver/v5/%40v5.1.0/neo4j_tab=importedby This snippet demonstrates the basic usage of the Neo4j Go Driver v5. It covers establishing a connection, executing Cypher queries, and handling results. This is a foundational example for developers starting with the driver. ```go package main import ( "context" "fmt" "log" "github.com/neo4j/neo4j-go-driver/v5/neo4j" ) func main() { // Replace with your Neo4j connection details uri := "neo4j://localhost:7687" user := "neo4j" password := "password" driver, err := neo4j.NewDriverWithContext(uri, neo4j.BasicAuth(user, password, "")) if err != nil { log.Fatalf("Failed to create driver: %v", err) } defer driver.Close(context.Background()) session := driver.AcquireSession(context.Background(), neo4j.SessionConfig{DatabaseName: "neo4j"}) defer session.Close(context.Background()) // Example: Create a node _, err = session.ExecuteWrite(context.Background(), func(tx neo4j.ManagedTransaction) (any, error) { result, err := tx.Run(context.Background(), "CREATE (a:Person {name: $name}) RETURN a.name AS name", map[string]interface{}{ "name": "Alice", }) if err != nil { return nil, err } record, err := result.Single() if err != nil { return nil, err } return record.Values[0], nil }) if err != nil { log.Fatalf("Failed to create node: %v", err) } fmt.Println("Node created successfully.") // Example: Query nodes _, err = session.ExecuteRead(context.Background(), func(tx neo4j.ManagedTransaction) (any, error) { result, err := tx.Run(context.Background(), "MATCH (a:Person) RETURN a.name AS name", nil) if err != nil { return nil, err } for result.Next(context.Background()) { fmt.Printf("Found person: %v\n", result.Record().Values[0]) } return nil, result.Err() }) if err != nil { log.Fatalf("Failed to query nodes: %v", err) } } ``` -------------------------------- ### Record.AsMap Example Source: https://pkg.go.dev/github.com/neo4j/neo4j-go-driver/v5/%40v5.25.0/neo4j/db An example demonstrating how to use the AsMap method on a Neo4j Record to convert it into a map. ```go package main import ( "fmt" "github.com/neo4j/neo4j-go-driver/v5/neo4j/db" ) func main() { // Assuming 'record' is a valid neo4j.Record object obtained from a query // For demonstration purposes, we'll create a mock record. // In a real scenario, you would get this from a driver session. // Mocking a Record with some data mockRecord := db.Record{ Keys: []string{"name", "age"}, Values: []any{"Alice", 30}, } recordMap := mockRecord.AsMap() fmt.Printf("Record as map: %v\n", recordMap) // Example of using Get name, ok := recordMap["name"].(string) if ok { fmt.Printf("Name: %s\n", name) } age, ok := recordMap["age"].(int) if ok { fmt.Printf("Age: %d\n", age) } } ``` -------------------------------- ### SessionConfig Examples Source: https://pkg.go.dev/github.com/neo4j/neo4j-go-driver/v5/%40v5.21.0/neo4j Examples demonstrating how to configure session settings, including disabling notification categories and setting minimum severity levels. ```go // Example (DisableNoCategories) // Example (DisableSomeCategories) // Example (MinimumSeverityLevel) ``` -------------------------------- ### Go Development Resources Source: https://pkg.go.dev/github.com/neo4j/neo4j-go-driver/v5/%40v5.0.0-alpha1/test-stress_tab=licenses A collection of links to essential Go development resources, including the Go solutions page, case studies, getting started guides, the Go Playground, and community support channels. ```text [ Why Go ](https://go.dev/solutions) [ Use Cases ](https://go.dev/solutions#use-cases) [ Case Studies ](https://go.dev/solutions#case-studies) [ Get Started ](https://learn.go.dev/) [ Playground ](https://play.golang.org) [ Tour ](https://tour.golang.org) [ Stack Overflow ](https://stackoverflow.com/questions/tagged/go?tab=Newest) [ Help ](https://go.dev/help) [ Packages ](https://pkg.go.dev) [ Standard Library ](https://pkg.go.dev/std) [ Sub-repositories ](https://pkg.go.dev/golang.org/x) [ About Go Packages ](https://pkg.go.dev/about) [ About ](https://go.dev/project) [Download](https://go.dev/dl/) [Blog](https://go.dev/blog) [ Issue Tracker ](https://github.com/golang/go/issues) [ Release Notes ](https://go.dev/doc/devel/release.html) [ Brand Guidelines ](https://go.dev/brand) [ Code of Conduct ](https://go.dev/conduct) [ Connect ](https://www.twitter.com/golang) [ Twitter ](https://www.twitter.com/golang) [GitHub](https://github.com/golang) [ Slack ](https://invite.slack.golangbridge.org/) [ r/golang ](https://reddit.com/r/golang) [ Meetup ](https://www.meetup.com/pro/go) [ Golang Weekly ](https://golangweekly.com/) * [Copyright](https://go.dev/copyright) * [Terms of Service](https://go.dev/tos) * [ Privacy Policy ](http://www.google.com/intl/en/policies/privacy/) * [ Report an Issue ](https://go.dev/s/pkgsite-feedback) * Theme Toggle * Shortcuts Modal [ ](https://google.com) ``` -------------------------------- ### Go Development Resources Source: https://pkg.go.dev/github.com/neo4j/neo4j-go-driver/v5/%40v5.0.0-alpha1/neo4j/test-integration_tab=licenses A collection of links to essential Go development resources, including the Go solutions page, case studies, getting started guides, the Go Playground, and community support channels. ```text [ Why Go ](https://go.dev/solutions) [ Use Cases ](https://go.dev/solutions#use-cases) [ Case Studies ](https://go.dev/solutions#case-studies) [ Get Started ](https://learn.go.dev/) [ Playground ](https://play.golang.org) [ Tour ](https://tour.golang.org) [ Stack Overflow ](https://stackoverflow.com/questions/tagged/go?tab=Newest) [ Help ](https://go.dev/help) [ Packages ](https://pkg.go.dev) [ Standard Library ](https://pkg.go.dev/std) [ Sub-repositories ](https://pkg.go.dev/golang.org/x) [ About Go Packages ](https://pkg.go.dev/about) [ About ](https://go.dev/project) [Download](https://go.dev/dl/) [Blog](https://go.dev/blog) [ Issue Tracker ](https://github.com/golang/go/issues) [ Release Notes ](https://go.dev/doc/devel/release.html) [ Brand Guidelines ](https://go.dev/brand) [ Code of Conduct ](https://go.dev/conduct) [ Connect ](https://www.twitter.com/golang) [ Twitter ](https://www.twitter.com/golang) [GitHub](https://github.com/golang) [ Slack ](https://invite.slack.golangbridge.org/) [ r/golang ](https://reddit.com/r/golang) [ Meetup ](https://www.meetup.com/pro/go) [ Golang Weekly ](https://golangweekly.com/) * [Copyright](https://go.dev/copyright) * [Terms of Service](https://go.dev/tos) * [ Privacy Policy ](http://www.google.com/intl/en/policies/privacy/) * [ Report an Issue ](https://go.dev/s/pkgsite-feedback) * Theme Toggle * Shortcuts Modal [ ](https://google.com) ``` -------------------------------- ### Go Development Resources Source: https://pkg.go.dev/github.com/neo4j/neo4j-go-driver/v5/%40v5.0.0-alpha1/neo4j/internal/testutil_tab=licenses A collection of links to essential Go development resources, including the Go solutions page, case studies, getting started guides, the Go Playground, and community support channels. ```text [ Why Go ](https://go.dev/solutions) [ Use Cases ](https://go.dev/solutions#use-cases) [ Case Studies ](https://go.dev/solutions#case-studies) [ Get Started ](https://learn.go.dev/) [ Playground ](https://play.golang.org) [ Tour ](https://tour.golang.org) [ Stack Overflow ](https://stackoverflow.com/questions/tagged/go?tab=Newest) [ Help ](https://go.dev/help) [ Packages ](https://pkg.go.dev) [ Standard Library ](https://pkg.go.dev/std) [ Sub-repositories ](https://pkg.go.dev/golang.org/x) [ About Go Packages ](https://pkg.go.dev/about) [ About ](https://go.dev/project) [Download](https://go.dev/dl/) [Blog](https://go.dev/blog) [ Issue Tracker ](https://github.com/golang/go/issues) [ Release Notes ](https://go.dev/doc/devel/release.html) [ Brand Guidelines ](https://go.dev/brand) [ Code of Conduct ](https://go.dev/conduct) [ Connect ](https://www.twitter.com/golang) [ Twitter ](https://www.twitter.com/golang) [GitHub](https://github.com/golang) [ Slack ](https://invite.slack.golangbridge.org/) [ r/golang ](https://reddit.com/r/golang) [ Meetup ](https://www.meetup.com/pro/go) [ Golang Weekly ](https://golangweekly.com/) * [Copyright](https://go.dev/copyright) * [Terms of Service](https://go.dev/tos) * [ Privacy Policy ](http://www.google.com/intl/en/policies/privacy/) * [ Report an Issue ](https://go.dev/s/pkgsite-feedback) * Theme Toggle * Shortcuts Modal [ ](https://google.com) ``` -------------------------------- ### Neo4j Driver Initialization and Configuration Source: https://pkg.go.dev/github.com/neo4j/neo4j-go-driver/v5/%40v5.12.0/neo4j Demonstrates how to create a new Neo4j driver instance with various configuration options, including authentication, bookmark management, and routing. ```go import ( "context" "github.com/neo4j/neo4j-go-driver/v5/neo4j" ) func main() { // Example using Basic Authentication aauth := neo4j.BasicAuth("username", "password", "") // Example with custom configuration options configurers := []neo4j.Neo4jConfigurator{ neo4j.WithDatabase("neo4j"), neo4j.WithDriverName("my-go-driver"), } driver, err := neo4j.NewDriver("neo4j://localhost:7687", auth, configurers...) if err != nil { panic(err) } defer driver.Close(context.Background()) // Example using Bearer Authentication authBearer := neo4j.BearerAuth("your_bearer_token") driverBearer, err := neo4j.NewDriver("neo4j://localhost:7687", authBearer) if err != nil { panic(err) } defer driverBearer.Close(context.Background()) // Example with no authentication authNone := neo4j.NoAuth() driverNoAuth, err := neo4j.NewDriver("neo4j://localhost:7687", authNone) if err != nil { panic(err) } defer driverNoAuth.Close(context.Background()) } ``` -------------------------------- ### Go Development Resources Source: https://pkg.go.dev/github.com/neo4j/neo4j-go-driver/v5/%40v5.0.0-alpha1/neo4j/internal/router_tab=licenses A collection of links to essential Go development resources, including the Go solutions page, case studies, getting started guides, the Go Playground, and community support channels. ```text [ Why Go ](https://go.dev/solutions) [ Use Cases ](https://go.dev/solutions#use-cases) [ Case Studies ](https://go.dev/solutions#case-studies) [ Get Started ](https://learn.go.dev/) [ Playground ](https://play.golang.org) [ Tour ](https://tour.golang.org) [ Stack Overflow ](https://stackoverflow.com/questions/tagged/go?tab=Newest) [ Help ](https://go.dev/help) [ Packages ](https://pkg.go.dev) [ Standard Library ](https://pkg.go.dev/std) [ Sub-repositories ](https://pkg.go.dev/golang.org/x) [ About Go Packages ](https://pkg.go.dev/about) [ About ](https://go.dev/project) [Download](https://go.dev/dl/) [Blog](https://go.dev/blog) [ Issue Tracker ](https://github.com/golang/go/issues) [ Release Notes ](https://go.dev/doc/devel/release.html) [ Brand Guidelines ](https://go.dev/brand) [ Code of Conduct ](https://go.dev/conduct) [ Connect ](https://www.twitter.com/golang) [ Twitter ](https://www.twitter.com/golang) [GitHub](https://github.com/golang) [ Slack ](https://invite.slack.golangbridge.org/) [ r/golang ](https://reddit.com/r/golang) [ Meetup ](https://www.meetup.com/pro/go) [ Golang Weekly ](https://golangweekly.com/) * [Copyright](https://go.dev/copyright) * [Terms of Service](https://go.dev/tos) * [ Privacy Policy ](http://www.google.com/intl/en/policies/privacy/) * [ Report an Issue ](https://go.dev/s/pkgsite-feedback) * Theme Toggle * Shortcuts Modal [ ](https://google.com) ``` -------------------------------- ### Go Development Resources Source: https://pkg.go.dev/github.com/neo4j/neo4j-go-driver/v5/%40v5.0.0-alpha1/neo4j/internal/retry_tab=licenses A collection of links to essential Go development resources, including the Go solutions page, case studies, getting started guides, the Go Playground, and community support channels. ```text [ Why Go ](https://go.dev/solutions) [ Use Cases ](https://go.dev/solutions#use-cases) [ Case Studies ](https://go.dev/solutions#case-studies) [ Get Started ](https://learn.go.dev/) [ Playground ](https://play.golang.org) [ Tour ](https://tour.golang.org) [ Stack Overflow ](https://stackoverflow.com/questions/tagged/go?tab=Newest) [ Help ](https://go.dev/help) [ Packages ](https://pkg.go.dev) [ Standard Library ](https://pkg.go.dev/std) [ Sub-repositories ](https://pkg.go.dev/golang.org/x) [ About Go Packages ](https://pkg.go.dev/about) [ About ](https://go.dev/project) [Download](https://go.dev/dl/) [Blog](https://go.dev/blog) [ Issue Tracker ](https://github.com/golang/go/issues) [ Release Notes ](https://go.dev/doc/devel/release.html) [ Brand Guidelines ](https://go.dev/brand) [ Code of Conduct ](https://go.dev/conduct) [ Connect ](https://www.twitter.com/golang) [ Twitter ](https://www.twitter.com/golang) [GitHub](https://github.com/golang) [ Slack ](https://invite.slack.golangbridge.org/) [ r/golang ](https://reddit.com/r/golang) [ Meetup ](https://www.meetup.com/pro/go) [ Golang Weekly ](https://golangweekly.com/) * [Copyright](https://go.dev/copyright) * [Terms of Service](https://go.dev/tos) * [ Privacy Policy ](http://www.google.com/intl/en/policies/privacy/) * [ Report an Issue ](https://go.dev/s/pkgsite-feedback) * Theme Toggle * Shortcuts Modal [ ](https://google.com) ```