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

🔥 feat: Add support for Neo4j #1562

Merged
merged 29 commits into from
Feb 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
bba2cc0
neo4j storage driver config.go
the-real-i9 Jan 28, 2025
de074c5
New and Get mdthods
the-real-i9 Jan 29, 2025
96079e7
(update): other storage interface methods implemented
the-real-i9 Jan 29, 2025
32c31af
(test): all tests passed
the-real-i9 Jan 29, 2025
c7ef3ee
(update): Config doc update
the-real-i9 Jan 29, 2025
3f32afe
(update): Config doc update
the-real-i9 Jan 29, 2025
c58fcf2
(fix): repeated condition check
the-real-i9 Jan 29, 2025
b49ff3a
(fix): typo fix, changed mysql to arangodb
the-real-i9 Jan 29, 2025
fd5f9f7
README update
the-real-i9 Jan 29, 2025
8caf6b9
Merge branch 'gofiber:main' into main
the-real-i9 Jan 30, 2025
c6792f4
Neo4j README update
the-real-i9 Jan 30, 2025
505f371
Neo4j README update
the-real-i9 Jan 30, 2025
cb30085
Neo4j README update
the-real-i9 Jan 30, 2025
c5fa260
fixes
the-real-i9 Jan 30, 2025
9210a55
Merge branch 'gofiber:main' into main
the-real-i9 Jan 30, 2025
ddbe487
readme update
the-real-i9 Jan 30, 2025
41e11d6
test workflow neo4j
the-real-i9 Jan 30, 2025
cf25873
(fixes): neo4j
the-real-i9 Jan 30, 2025
511a96b
Merge branch 'gofiber:main' into main
the-real-i9 Jan 30, 2025
962c314
(fix): neo4j README
the-real-i9 Jan 30, 2025
33d9b48
testcontainer now working fine
the-real-i9 Jan 30, 2025
3fc1b8c
Update neo4j/neo4j_test.go
the-real-i9 Jan 30, 2025
8657520
(fix): neo4j/neo4j_test.go
the-real-i9 Jan 31, 2025
5e5858e
(update): storage.go to include Neo4j package
the-real-i9 Jan 31, 2025
4a7a7f0
(update): main README to include Neo4j test image tag
the-real-i9 Jan 31, 2025
93c211d
review updates
the-real-i9 Feb 3, 2025
7e74ccf
starting separate container for each test is beyond efficient, revert…
the-real-i9 Feb 3, 2025
6e08ff8
Merge branch 'gofiber:main' into main
the-real-i9 Feb 3, 2025
69a51dc
Update README.md
gaby Feb 3, 2025
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
27 changes: 27 additions & 0 deletions .github/workflows/test-neo4j.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
on:
push:
branches:
- master
- main
paths:
- 'neo4j/**'
pull_request:
paths:
- 'neo4j/**'
name: "Tests Neo4j"
jobs:
Tests:
runs-on: ubuntu-latest
strategy:
matrix:
go-version:
- 1.23.x
steps:
- name: Fetch Repository
uses: actions/checkout@v4
- name: Install Go
uses: actions/setup-go@v5
with:
go-version: '${{ matrix.go-version }}'
- name: Run Test
run: cd ./neo4j && go test ./... -v -race
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ type Storage interface {
- [MSSQL](./mssql/README.md) <a href="https://github.com/gofiber/storage/actions?query=workflow%3A%22Tests+MSSQL%22"> <img src="https://img.shields.io/github/actions/workflow/status/gofiber/storage/test-mssql.yml?branch=main&label=%F0%9F%A7%AA%20&style=flat&color=75C46B" /> </a>
- [MySQL](./mysql/README.md) <a href="https://github.com/gofiber/storage/actions?query=workflow%3A%22Tests+MySQL%22"> <img src="https://img.shields.io/github/actions/workflow/status/gofiber/storage/test-mysql.yml?branch=main&label=%F0%9F%A7%AA%20&style=flat&color=75C46B" /> </a>
- [NATS](./nats/README.md) <a href="https://github.com/gofiber/storage/actions?query=workflow%3A%22Tests%20Nats%20Driver%22"> <img src="https://img.shields.io/github/actions/workflow/status/gofiber/storage/test-nats.yml?branch=main&label=%F0%9F%A7%AA%20&style=flat&color=75C46B" /> </a>
- [Neo4j](./neo4j/README.md) <a href="https://github.com/gofiber/storage/actions?query=workflow%3A%22Tests+Neo4j%22"> <img src="https://img.shields.io/github/actions/workflow/status/gofiber/storage/test-neo4j.yml?branch=main&label=%F0%9F%A7%AA%20&style=flat&color=75C46B" /> </a>
- [Pebble](./pebble/README.md) <a href="https://github.com/gofiber/storage/actions?query=workflow%3A%22Tests+Pebble%22"> <img src="https://img.shields.io/github/actions/workflow/status/gofiber/storage/test-pebble.yml?branch=main&label=%F0%9F%A7%AA%20&style=flat&color=75C46B" /> </a>
- [Postgres](./postgres/README.md) <a href="https://github.com/gofiber/storage/actions?query=workflow%3A%22Tests+Postgres%22"> <img src="https://img.shields.io/github/actions/workflow/status/gofiber/storage/test-postgres.yml?branch=main&label=%F0%9F%A7%AA%20&style=flat&color=75C46B" /> </a>
- [Redis](./redis/README.md) <a href="https://github.com/gofiber/storage/actions?query=workflow%3A%22Tests+Redis%22"> <img src="https://img.shields.io/github/actions/workflow/status/gofiber/storage/test-redis.yml?branch=main&label=%F0%9F%A7%AA%20&style=flat&color=75C46B" /> </a>
Expand Down
2 changes: 1 addition & 1 deletion arangodb/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ ArangoDB is tested on the 2 last (1.14/1.15) [Go versions](https://golang.org/dl
```bash
go mod init github.com/<user>/<repo>
```
And then install the mysql implementation:
And then install the arangodb implementation:
```bash
go get github.com/gofiber/storage/arangodb/v2
```
Expand Down
146 changes: 146 additions & 0 deletions neo4j/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
---
id: neo4j
title: Neo4j
---

A Neo4j storage driver using [neo4j/neo4j-go-driver](https://github.com/neo4j/neo4j-go-driver).

> **Note: Requires latest two release of Golang**
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Grammar Correction for Go Version Note

The note currently reads "Requires latest two release of Golang." Please update it to "Requires latest two releases of Golang" to correct the pluralization.

🧰 Tools
🪛 LanguageTool

[grammar] ~8-~8: After the number ‘two’, use a plural noun. Did you mean “releases”?
Context: ...driver). > Note: Requires latest two release of Golang ### Table of Contents - [...

(CD_NNU)


### Table of Contents

- [Signatures](#signatures)
- [Installation](#installation)
- [Examples](#examples)
- [Config](#config)
- [Default Config](#default-config)

### Signatures

```go
func New(config ...Config) Storage
func (s *Storage) Get(key string) ([]byte, error)
func (s *Storage) Set(key string, val []byte, exp time.Duration) error
func (s *Storage) Delete(key string) error
func (s *Storage) Reset() error
func (s *Storage) Close() error
func (s *Storage) Conn() neo4j.DriverWithContext
```

### Installation

Neo4j is tested on the 2 last [Go versions](https://golang.org/dl/) with support for modules. So make sure to initialize one first if you didn't do that yet:

```bash
go mod init github.com/<user>/<repo>
```

And then install the neo4j implementation:

```bash
go get github.com/gofiber/storage/neo4j
```

### Examples

Import the storage package.

```go
import neo4jstore "github.com/gofiber/storage/neo4j"
```

You can use the following possibilities to create a storage:

```go
// Initialize default config
store := neo4j.New()

// Initialize custom config
store := neo4j.New(neo4jstore.Config{
DB: driver,
Node: "fiber_storage",
Reset: false,
GCInterval: 10 * time.Second,
})
```

### Config

```go
// Config defines the config for storage.
type Config struct {
// Connection pool
//
// DB neo4j.DriverWithContext object will override connection uri and other connection fields.
//
// Optional. Default is nil.
DB neo4j.DriverWithContext

// Target Server
//
// Optional. Default is "neo4j://localhost"
URI string

// Connection authentication
//
// Auth auth.TokenManager will override Username and Password fields
//
// Optional. Default is nil.
Auth auth.TokenManager

// Connection configurations
//
// Optional. Default is nil
Configurations []func(*config.Config)

// Server username
//
// Optional. Default is ""
Username string

// Server password
//
// Optional. Default is ""
Password string

// Node name
//
// Optional. Default is "fiber_storage"
Node string

// Reset clears any existing keys in existing Table
//
// Optional. Default is false
Reset bool

// Time before deleting expired keys
//
// Optional. Default is 10 * time.Second
GCInterval time.Duration
}
```

#### A note on Authentication

If auth is enabled on your server, then authentication must be provided in one of the three ways (the previous overrides the next):

- Via the connection pool, `neo4j.DriverWithContext`, provided on the `DB` field.
- Via the `Auth` field: it must be an `auth.TokenManager` whose value is any one but `neo4j.NoAuth()`.
- By setting both `Username` and `Password` fields: This will cause this storage driver to use Basic Auth.

Otherwise, your neo4j driver will panic with authorization error.

In contrast, if auth is disabled on your server, there's no need to provide any authentication parameter.

### Default Config

Used only for optional fields

```go
var ConfigDefault = Config{
URI: "neo4j://localhost",
Node: "fiber_storage",
Reset: false,
GCInterval: 10 * time.Second,
}
```
102 changes: 102 additions & 0 deletions neo4j/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
package neo4j

import (
"time"

"github.com/neo4j/neo4j-go-driver/v5/neo4j"
"github.com/neo4j/neo4j-go-driver/v5/neo4j/auth"
"github.com/neo4j/neo4j-go-driver/v5/neo4j/config"
)

type Config struct {
// Connection pool.
//
// DB neo4j.DriverWithContext object will override connection uri and other connection fields.
//
// Optional. Default is nil.
DB neo4j.DriverWithContext

// Target Server
//
// Optional. Default is "neo4j://localhost"
URI string

// Connection authentication.
//
// Auth auth.TokenManager will override Username and Password fields.
//
// Optional. Default is nil.
Auth auth.TokenManager

// Connection configurations
//
// Optional. Default is nil
Configurations []func(*config.Config)

// Server username
//
// Optional. Default is ""
Username string

// Server password
//
// Optional. Default is ""
Password string

// Node name
//
// Optional. Default is "fiber_storage"
Node string

// Reset clears any existing keys (Nodes)
//
// Optional. Default is false
Reset bool

// Time before deleting expired keys (Nodes)
//
// Optional. Default is 10 * time.Second
GCInterval time.Duration
}

var ConfigDefault = Config{
URI: "neo4j://localhost",
Node: "fiber_storage",
Reset: false,
GCInterval: 10 * time.Second,
}

// Helper function to set default values
func configDefault(config ...Config) Config {

// Return default config if nothing provided
if len(config) < 1 {
return ConfigDefault
}

// Override default config
cfg := config[0]

// Set default values
if cfg.URI == "" {
cfg.URI = ConfigDefault.URI
}

if cfg.Auth == nil {
if cfg.Username != "" && cfg.Password != "" {
cfg.Auth = neo4j.BasicAuth(cfg.Username, cfg.Password, "")
} else {
cfg.Auth = neo4j.NoAuth()
}
}

if cfg.Node == "" {
cfg.Node = ConfigDefault.Node
}

if int(cfg.GCInterval.Seconds()) <= 0 {
cfg.GCInterval = ConfigDefault.GCInterval
}

return cfg
}
59 changes: 59 additions & 0 deletions neo4j/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
module github.com/gofiber/storage/neo4j

go 1.23

require (
github.com/neo4j/neo4j-go-driver/v5 v5.27.0
github.com/stretchr/testify v1.9.0
github.com/testcontainers/testcontainers-go/modules/neo4j v0.35.0
)

require (
dario.cat/mergo v1.0.0 // indirect
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect
github.com/Microsoft/go-winio v0.6.2 // indirect
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
github.com/containerd/containerd v1.7.18 // indirect
github.com/containerd/log v0.1.0 // indirect
github.com/containerd/platforms v0.2.1 // indirect
github.com/cpuguy83/dockercfg v0.3.2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/distribution/reference v0.6.0 // indirect
github.com/docker/docker v27.1.1+incompatible // indirect
github.com/docker/go-connections v0.5.0 // indirect
github.com/docker/go-units v0.5.0 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/klauspost/compress v1.17.4 // indirect
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/moby/docker-image-spec v1.3.1 // indirect
github.com/moby/patternmatcher v0.6.0 // indirect
github.com/moby/sys/sequential v0.5.0 // indirect
github.com/moby/sys/user v0.1.0 // indirect
github.com/moby/term v0.5.0 // indirect
github.com/morikuni/aec v1.0.0 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.1.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect
github.com/shirou/gopsutil/v3 v3.23.12 // indirect
github.com/shoenig/go-m1cpu v0.1.6 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/testcontainers/testcontainers-go v0.35.0 // indirect
github.com/tklauser/go-sysconf v0.3.12 // indirect
github.com/tklauser/numcpus v0.6.1 // indirect
github.com/yusufpapurcu/wmi v1.2.3 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0 // indirect
go.opentelemetry.io/otel v1.24.0 // indirect
go.opentelemetry.io/otel/metric v1.24.0 // indirect
go.opentelemetry.io/otel/trace v1.24.0 // indirect
golang.org/x/crypto v0.31.0 // indirect
golang.org/x/sys v0.28.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading