Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/vescale/zgraph
An embeddable graph database for large-scale vertices and edges
https://github.com/vescale/zgraph
database embeddable graph graph-database pgql
Last synced: 3 months ago
JSON representation
An embeddable graph database for large-scale vertices and edges
- Host: GitHub
- URL: https://github.com/vescale/zgraph
- Owner: vescale
- License: apache-2.0
- Created: 2022-11-16T05:31:22.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2023-04-16T03:24:47.000Z (over 1 year ago)
- Last Synced: 2024-07-28T16:36:22.764Z (4 months ago)
- Topics: database, embeddable, graph, graph-database, pgql
- Language: Go
- Homepage:
- Size: 1.04 MB
- Stars: 72
- Watchers: 5
- Forks: 4
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# What is zGraph
[![Go Reference](https://pkg.go.dev/badge/github.com/vescale/zgraph.svg)](https://pkg.go.dev/github.com/vescale/zgraph)
[![GitHub Actions](https://github.com/vescale/zgraph/workflows/Check/badge.svg)](https://github.com/vescale/zgraph/actions?query=workflow%3ACheck)zGraph is a [PGQL](https://pgql-lang.org/)-compatible embeddable graph database for large-scale vertices.
You can find the specification [here](https://pgql-lang.org/spec/1.5/).## Installation
```bash
go get -u github.com/vescale/zgraph
```## Quick Start
### Playground
```bash
> make build
> ./bin/zgraph play
```### Build Application
zGraph implements driver for [database/sql](https://golang.org/pkg/database/sql/). To use zGraph, you can simply import zGraph package and use `zgraph` as the driver name in `sql.Open`.Here is an example of how to use create a graph and query it. The graph is an example in [PGQL specification](https://pgql-lang.org/spec/1.5/#edge-patterns).
```go
package mainimport (
"context"
"database/sql"
"fmt"
"log"_ "github.com/vescale/zgraph"
)func main() {
db, err := sql.Open("zgraph", "test.db")
if err != nil {
log.Fatal(err)
}
defer db.Close()ctx, cancel := context.WithCancel(context.Background())
defer cancel()conn, err := db.Conn(ctx)
if err != nil {
log.Fatal(err)
}// Create a graph.
mustExec(ctx, conn, "CREATE GRAPH student_network")// Change the current graph.
mustExec(ctx, conn, "USE student_network")// Create labels.
mustExec(ctx, conn, "CREATE LABEL Person")
mustExec(ctx, conn, "CREATE LABEL University")
mustExec(ctx, conn, "CREATE LABEL knows")
mustExec(ctx, conn, "CREATE LABEL studentOf")// Create vertices.
mustExec(ctx, conn, `INSERT VERTEX x LABELS (Person) PROPERTIES (x.name = 'Kathrine', x.dob = DATE '1994-01-15')`)
mustExec(ctx, conn, `INSERT VERTEX x LABELS (Person) PROPERTIES (x.name = 'Riya', x.dob = DATE '1995-03-20')`)
mustExec(ctx, conn, `INSERT VERTEX x LABELS (Person) PROPERTIES (x.name = 'Lee', x.dob = DATE '1996-01-20')`)
mustExec(ctx, conn, `INSERT VERTEX x LABELS (University) PROPERTIES (x.name = 'UC Berkeley')`)// Create edges.
mustExec(ctx, conn, `INSERT EDGE e BETWEEN x AND y LABELS ( knows ) FROM MATCH (x), MATCH (y) WHERE x.name = 'Kathrine' AND y.name = 'Lee'`)
mustExec(ctx, conn, `INSERT EDGE e BETWEEN x AND y LABELS ( knows ) FROM MATCH (x), MATCH (y) WHERE x.name = 'Kathrine' AND y.name = 'Riya'`)
mustExec(ctx, conn, `INSERT EDGE e BETWEEN x AND y LABELS ( knows ) FROM MATCH (x), MATCH (y) WHERE x.name = 'Lee' AND y.name = 'Kathrine'`)
mustExec(ctx, conn, `INSERT EDGE e BETWEEN x AND y LABELS ( studentOf ) FROM MATCH (x), MATCH (y) WHERE x.name = 'Kathrine' AND y.name = 'UC Berkeley'`)
mustExec(ctx, conn, `INSERT EDGE e BETWEEN x AND y LABELS ( studentOf ) FROM MATCH (x), MATCH (y) WHERE x.name = 'Lee' AND y.name = 'UC Berkeley'`)
mustExec(ctx, conn, `INSERT EDGE e BETWEEN x AND y LABELS ( studentOf ) FROM MATCH (x), MATCH (y) WHERE x.name = 'Riya' AND y.name = 'UC Berkeley'`)// Query the graph.
rows, err := conn.QueryContext(ctx, "SELECT a.name AS a, b.name AS b FROM MATCH (a:Person) -[e:knows]-> (b:Person)")
if err != nil {
log.Fatal(err)
}
var a, b string
for rows.Next() {
if err := rows.Scan(&a, &b); err != nil {
log.Fatal(err)
}
fmt.Printf("'%s' knows '%s'\n", a, b)
}
}func mustExec(ctx context.Context, conn *sql.Conn, query string) {
_, err := conn.ExecContext(ctx, query)
if err != nil {
log.Fatal(err)
}
}
```## Contributing
We welcome contributions from everyone. zGraph is in its early stages, if you have any ideas or suggestions, please feel free to open an issue or pull request.
## License
zGraph is licensed under the Apache 2.0 license. See [LICENSE](LICENSE) for the full license text.