Skip to content

Quick Start

This guide will help you complete development environment configuration and start your GoGraph graph database journey in 5 minutes.

The fastest way to explore GoGraph is through its command-line interface (CLI).

macOS / Linux (Homebrew):

brew install dotnetage/tap/gograph

Running the Interactive Shell (TUI):

# Running without parameters will automatically open and enter the default database (default.db)
gograph

2. Installing as a Go Library

Execute the following command in your Go Module project directory to get dependencies:

go get github.com/DotNetAge/gograph

3. Basic Usage Example

Below is a complete main.go example.

package main

import (
    "context"
    "fmt"
    "log"

    "github.com/DotNetAge/gograph/pkg/api"
)

func main() {
    // 1. Open or create a graph database instance (default path: default.db)
    db, err := api.Open("default.db")
    if err != nil {
        log.Fatalf("Failed to open db: %v", err)
    }
    defer db.Close()

    ctx := context.Background()

    // 2. Write data using Cypher
    db.Exec(ctx, "CREATE (a:User {name: 'Alice'})-[:KNOWS]->(b:User {name: 'Bob'})")

    // 3. Execute data query (MATCH ... RETURN)
    rows, err := db.Query(ctx, "MATCH (u:User)-[:KNOWS]->(friend:User) RETURN u.name, friend.name")
    if err != nil {
        log.Fatalf("Query failed: %v", err)
    }
    defer rows.Close()

    // 4. Iterate through the result set
    for rows.Next() {
        var uName, fName string
        if err := rows.Scan(&uName, &fName); err == nil {
            fmt.Printf("%s knows %s\n", uName, fName)
        }
    }
}

4. More Resources