Giter VIP home page Giter VIP logo

falkordb-go's Introduction

license GitHub issues Codecov Go Report Card GoDoc

falkordb-go

Discord

falkordb-go is a Golang client for the FalkorDB database.

Installation

Simply do:

$ go get github.com/FalkorDB/falkordb-go

Usage

The complete falkordb-go API is documented on GoDoc.

package main

import (
	"fmt"
	"os"

	"github.com/FalkorDB/falkordb-go"
)

func main() {
	db, _ := falkordb.FalkorDBNew(&falkordb.ConnectionOption{Addr: "0.0.0.0:6379"})

	graph := db.SelectGraph("social")

	graph.Query("CREATE (:Person {name: 'John Doe', age: 33, gender: 'male', status: 'single'})-[:VISITED]->(:VISITED {name: 'Japan'})", nil, nil)

	query, err := "MATCH (p:Person)-[v:VISITED]->(c:VISITED) RETURN p.name, p.age, c.name"
	if err != nil {
		os.Exit(1)
	}

	// result is a QueryResult struct containing the query's generated records and statistics.
	result, _ := graph.Query(query, nil, nil)

	// Pretty-print the full result set as a table.
	result.PrettyPrint()

	// Iterate over each individual Record in the result.
	fmt.Println("Visited countries by person:")
	for result.Next() { // Next returns true until the iterator is depleted.
		// Get the current Record.
		r := result.Record()

		// Entries in the Record can be accessed by index or key.
		pName := r.GetByIndex(0)
		fmt.Printf("\nName: %s\n", pName)
		pAge, _ := r.Get("p.age")
		fmt.Printf("\nAge: %d\n", pAge)
	}

	// Path matching example.
	query = "MATCH p = (:person)-[:visited]->(:country) RETURN p"
	result, err := graph.Query(query, nil, nil)
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}
	fmt.Println("Pathes of persons visiting countries:")
	for result.Next() {
		r := result.Record()
		p, ok := r.GetByIndex(0).(rg.Path)
		fmt.Printf("%s %v\n", p, ok)
	}
}

Running the above produces the output:

+----------+-------+--------+
|  p.name  | p.age | c.name |
+----------+-------+--------+
| John Doe |    33 | Japan  |
+----------+-------+--------+

Query internal execution time 1.623063

Name: John Doe

Age: 33

Running queries with timeouts

Queries can be run with a millisecond-level timeout as described in the documentation. To take advantage of this feature, the QueryOptions struct should be used:

options := NewQueryOptions().SetTimeout(10) // 10-millisecond timeout
res, err := graph.Query("MATCH (src {name: 'John Doe'})-[*]->(dest) RETURN dest", nil, options)

Running tests

A simple test suite is provided, and can be run with:

$ go test

The tests expect a FalkorDB server to be available at localhost:6379

License

falkordb-go is distributed under the BSD3 license - see LICENSE

falkordb-go's People

Contributors

alonre24 avatar aviavni avatar avitalfineredis avatar chayim avatar dependabot[bot] avatar dvirdukhan avatar epswartz avatar filipecosta90 avatar gkorland avatar hades32 avatar itamarhaber avatar jeffreylovitz avatar maguec avatar mikewilson-dd avatar swilly22 avatar

Stargazers

 avatar

Watchers

 avatar

falkordb-go's Issues

Nodes and Properties duplicate and disappear

I was using this driver and stumbled upon some issues where properties disappear and labels duplicate when running queries.
This same problem doesn't occur when using redis-cli or the Python client.

I wrote about this problem in two issues on FalkorDB:
FalkorDB/FalkorDB#628
FalkorDB/FalkorDB#630

This issue arises in the oldest published version of redisgraph-go, the latest commit in redisgraph-go and the latest commit in this repo.

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.