Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rewrite #3

Merged
merged 32 commits into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 0 additions & 50 deletions .circleci/config.yml

This file was deleted.

8 changes: 0 additions & 8 deletions .deepsource.toml

This file was deleted.

33 changes: 33 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# This workflow will build a golang project
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go

name: Go

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]

jobs:

build:
runs-on: ubuntu-latest
services:
falkordb:
image: falkordb/falkordb:edge
ports:
- 6379:6379
steps:
- uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.20'

- name: Build
run: go build -v ./...

- name: Test
run: go test -v ./...
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ get:
examples: get
@echo " "
@echo "Building the examples..."
$(GOBUILD) ./examples/redisgraph_tls_client/.
$(GOBUILD) ./examples/falkordb_tls_client/.

test: get
$(GOTEST) -race -covermode=atomic ./...
Expand Down
78 changes: 23 additions & 55 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,24 @@
[![license](https://img.shields.io/github/license/RedisGraph/redisgraph-go.svg)](https://github.com/RedisGraph/redisgraph-go)
[![CircleCI](https://circleci.com/gh/RedisGraph/redisgraph-go/tree/master.svg?style=svg)](https://circleci.com/gh/RedisGraph/redisgraph-go/tree/master)
[![GitHub issues](https://img.shields.io/github/release/RedisGraph/redisgraph-go.svg)](https://github.com/RedisGraph/redisgraph-go/releases/latest)
[![Codecov](https://codecov.io/gh/RedisGraph/redisgraph-go/branch/master/graph/badge.svg)](https://codecov.io/gh/RedisGraph/redisgraph-go)
[![Go Report Card](https://goreportcard.com/badge/github.com/RedisGraph/redisgraph-go)](https://goreportcard.com/report/github.com/RedisGraph/redisgraph-go)
[![GoDoc](https://godoc.org/github.com/RedisGraph/redisgraph-go?status.svg)](https://godoc.org/github.com/RedisGraph/redisgraph-go)
[![license](https://img.shields.io/github/license/FalkorDB/falkordb-go.svg)](https://github.com/FalkorDB/falkordb-go)
[![GitHub issues](https://img.shields.io/github/release/FalkorDB/falkordb-go.svg)](https://github.com/FalkorDB/falkordb-go/releases/latest)
[![Codecov](https://codecov.io/gh/FalkorDB/falkordb-go/branch/master/graph/badge.svg)](https://codecov.io/gh/FalkorDB/falkordb-go)
[![Go Report Card](https://goreportcard.com/badge/github.com/FalkorDB/falkordb-go)](https://goreportcard.com/report/github.com/FalkorDB/falkordb-go)
[![GoDoc](https://godoc.org/github.com/FalkorDB/falkordb-go?status.svg)](https://godoc.org/github.com/FalkorDB/falkordb-go)

# redisgraph-go
[![Forum](https://img.shields.io/badge/Forum-RedisGraph-blue)](https://forum.redislabs.com/c/modules/redisgraph)
[![Discord](https://img.shields.io/discord/697882427875393627?style=flat-square)](https://discord.gg/gWBRT6P)
# falkordb-go
[![Discord](https://img.shields.io/discord/1146782921294884966?style=flat-square)](https://discord.gg/6M4QwDXn2w)

`redisgraph-go` is a Golang client for the [RedisGraph](https://oss.redislabs.com/redisgraph/) module. It relies on [`redigo`](https://github.com/gomodule/redigo) for Redis connection management and provides support for RedisGraph's QUERY, EXPLAIN, and DELETE commands.
`falkordb-go` is a Golang client for the [FalkorDB](https://falkordb.com) database.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Start the sentence with an uppercase letter to maintain consistency and professionalism in documentation.

- `falkordb-go` is a Golang client for the [FalkorDB](https://falkordb.com) database.
+ `Falkordb-go` is a Golang client for the [FalkorDB](https://falkordb.com) database.

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
`falkordb-go` is a Golang client for the [FalkorDB](https://falkordb.com) database.
`Falkordb-go` is a Golang client for the [FalkorDB](https://falkordb.com) database.

## Installation

Simply do:
```sh
$ go get github.com/redislabs/redisgraph-go
$ go get github.com/FalkorDB/falkordb-go
```

## Usage

The complete `redisgraph-go` API is documented on [GoDoc](https://godoc.org/github.com/RedisGraph/redisgraph-go).
The complete `falkordb-go` API is documented on [GoDoc](https://godoc.org/github.com/FalkorDB/falkordb-go).

```go
package main
Expand All @@ -29,51 +27,23 @@ import (
"fmt"
"os"

"github.com/gomodule/redigo/redis"
rg "github.com/redislabs/redisgraph-go"
"github.com/FalkorDB/falkordb-go"
)

func main() {
conn, _ := redis.Dial("tcp", "127.0.0.1:6379")
defer conn.Close()
db, _ := falkordb.FalkorDBNew(&falkordb.ConnectionOption{Addr: "0.0.0.0:6379"})

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add error handling for FalkorDBNew to promote best practices and robustness in example code.

db, err := falkordb.FalkorDBNew(&falkordb.ConnectionOption{Addr: "0.0.0.0:6379"})
if err != nil {
    log.Fatalf("Failed to create FalkorDB connection: %v", err)
}

graph := rg.GraphNew("social", conn)
graph := db.SelectGraph("social")

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add error handling for SelectGraph to ensure robustness in example code.

graph, err := db.SelectGraph("social")
if err != nil {
    log.Fatalf("Failed to select graph: %v", err)
}

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

john := rg.Node{
Label: "person",
Properties: map[string]interface{}{
"name": "John Doe",
"age": 33,
"gender": "male",
"status": "single",
},
}
graph.AddNode(&john)

japan := rg.Node{
Label: "country",
Properties: map[string]interface{}{
"name": "Japan",
},
}
graph.AddNode(&japan)

edge := rg.Edge{
Source: &john,
Relation: "visited",
Destination: &japan,
query, err := "MATCH (p:Person)-[v:VISITED]->(c:VISITED) RETURN p.name, p.age, c.name"
if err != nil {
os.Exit(1)
}
graph.AddEdge(&edge)

graph.Commit()

query := `MATCH (p:person)-[v:visited]->(c:country)
RETURN p.name, p.age, c.name`

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

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implement error handling for the Query method to enhance code reliability.

result, err := graph.Query(query, nil, nil)
if err != nil {
    log.Fatalf("Query failed: %v", err)
}

// Pretty-print the full result set as a table.
result.PrettyPrint()
Expand All @@ -93,7 +63,7 @@ func main() {

// Path matching example.
query = "MATCH p = (:person)-[:visited]->(:country) RETURN p"
result, err := graph.Query(query)
result, err := graph.Query(query, nil, nil)
if err != nil {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct the type assertion syntax to match the expected type from the Query method.

- p, ok := r.GetByIndex(0).(rg.Path)
+ p, ok := r.GetByIndex(0).(falkordb.Path)

Ensure the type Path is correctly defined within the falkordb package.


Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
result, err := graph.Query(query, nil, nil)
result, err := graph.Query(query, nil, nil)

fmt.Println(err)
os.Exit(1)
Expand Down Expand Up @@ -125,15 +95,13 @@ Age: 33

## Running queries with timeouts

Queries can be run with a millisecond-level timeout as described in [the module documentation](https://oss.redis.com/redisgraph/configuration/#timeout). To take advantage of this feature, the `QueryOptions` struct should be used:
Queries can be run with a millisecond-level timeout as described in [the documentation](https://docs.falkordb.com/configuration.html#timeout). To take advantage of this feature, the `QueryOptions` struct should be used:

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add error handling to the example code to promote best practices.

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

Including error handling in examples encourages developers to write more robust and error-resistant code.

Would you like me to help with updating the documentation to include error handling in all relevant examples?

```go
options := NewQueryOptions().SetTimeout(10) // 10-millisecond timeout
res, err := graph.QueryWithOptions("MATCH (src {name: 'John Doe'})-[*]->(dest) RETURN dest", options)
res, err := graph.Query("MATCH (src {name: 'John Doe'})-[*]->(dest) RETURN dest", nil, options)
```
Comment on lines +98 to +102
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add error handling to the example code to promote best practices.

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

Including error handling in examples encourages developers to write more robust and error-resistant code.


`ParameterizedQueryWithOptions` and `ROQueryWithOptions` endpoints are also exposed by the client.

## Running tests

A simple test suite is provided, and can be run with:
Expand All @@ -142,8 +110,8 @@ A simple test suite is provided, and can be run with:
$ go test
```

The tests expect a Redis server with the RedisGraph module loaded to be available at localhost:6379
The tests expect a FalkorDB server to be available at localhost:6379

## License

redisgraph-go is distributed under the BSD3 license - see [LICENSE](LICENSE)
falkordb-go is distributed under the BSD3 license - see [LICENSE](LICENSE)
Loading
Loading