A high-performance and easy-to-use Go driver for Apache AGE. This driver is written entirely in Go without any Java dependencies and utilizes an ANTLR4-based query parser.
- Java-Free: Written purely in Go, eliminating external dependencies.
- ANTLR4 Integration: Accurately and efficiently parses Apache AGE's Cypher-like query language.
- Type-Safe Mapping: Easily map database objects (vertices, edges) to Go structs.
- Transaction Support: Provides transaction management with ACID guarantees.
- Simple and Intuitive API: Offers a user-friendly and straightforward API for rapid development.
go get -u github.com/9ssi7/age
To run the tests, you'll need a running Apache AGE instance. You can easily spin one up using Docker:
docker run \
--name age \
-p 5455:5432 \
-e POSTGRES_USER=postgres \
-e POSTGRES_PASSWORD=postgres \
-e POSTGRES_DB=postgres \
-d \
apache/age
If you want to see some examples of how to use the driver, check out the samples repository.
package main
import (
"fmt"
"github.com/9ssi7/age"
)
// ... (Person and WorksWith structs) ...
func main() {
// ... (connection settings) ...
ag := age.New(age.Config{
GraphName: graphName,
Dsn: dsn,
})
ok, err := ag.Prepare()
// ... (query and data processing examples) ...
}
- Creating Vertices:
_, err = tx.Exec(0, "CREATE (n:Person {name: '%s', age: %d})", "Alice", 30)
- Creating Edges:
_, err = tx.Exec(0, "MATCH (a:Person), (b:Person) WHERE a.name = 'Alice' AND b.name = 'Bob' CREATE (a)-[:KNOWS]->(b)")
- Querying and Processing Data:
cursor, err := tx.Exec(1, "MATCH (n:Person) RETURN n")
for cursor.Next() {
entities, _ := cursor.GetRow()
vertex := entities[0].(*age.Vertex)
// Mapping age.Vertex to Person struct
person := &Person{}
mapper.Unmarshal(vertex, person) // Or use ParseStruct for more control
// age.ParseStruct(entities[0], person) // Alternative method
fmt.Println(person)
}
// Assuming entities[0] is a Vertex
person := &Person{}
err := age.ParseStruct(entities[0], person)
if err != nil {
// Handle error
}
Contributions are welcome via pull requests. Bug fixes, new features, and improvements are always appreciated. Please read CONTRIBUTING.md before contributing.
Apache License 2.0