Giter Club home page Giter Club logo

age's Introduction

Age Go Driver

Go Reference Go Report Card Apache License

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.

Features

  • 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.

Installation

go get -u github.com/9ssi7/age

Running Tests

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

Examples

If you want to see some examples of how to use the driver, check out the samples repository.

Usage

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) ...
}

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)
}

Using ParseStruct

// Assuming entities[0] is a Vertex
person := &Person{}
err := age.ParseStruct(entities[0], person)
if err != nil {
    // Handle error
}

Contributing

Contributions are welcome via pull requests. Bug fixes, new features, and improvements are always appreciated. Please read CONTRIBUTING.md before contributing.

License

Apache License 2.0

age's People

Contributors

9ssi7 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.