Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/inscapist/neo4j-go-mapper
Neo4J data mapper library with generics support <T>
https://github.com/inscapist/neo4j-go-mapper
mapper neo4j neo4j-driver reflect
Last synced: 14 days ago
JSON representation
Neo4J data mapper library with generics support <T>
- Host: GitHub
- URL: https://github.com/inscapist/neo4j-go-mapper
- Owner: inscapist
- Created: 2019-11-07T14:09:08.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2019-11-07T15:14:53.000Z (about 5 years ago)
- Last Synced: 2024-11-07T09:52:44.268Z (2 months ago)
- Topics: mapper, neo4j, neo4j-driver, reflect
- Language: Go
- Homepage:
- Size: 17.6 KB
- Stars: 2
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Neo4J go mapper
Data mapper library for [Neo4J go driver](https://github.com/neo4j/neo4j-go-driver)
Refer [test](./test) for usage examples.## How it works
Package mapper makes heavy use of `reflect` to construct values out of specified types (an empty, initialized value of a type).
This makes it easy to read arbitrary values from neo4j client. Examples [here](./test/reader_test.go). Supports `slice` and `struct` as return types.
```
Usage:
- pass empty, initialized type(s) as the last argument(s) of `ReadSingleRow` and `ReadSingleRow`
- get back values and cast them back into the required types
```## Interface
```go
// This is the interface implemented by Client
type Mapper interface {
// Ensure Neo4J connection
Ping() error// Closes bolt driver
Close() error// Execute a cypher statement
Exec(cypher string, params map[string]interface{}) error// Query all results/rows from Neo4J
Query(
cypher string,
params map[string]interface{},
transform func(record neo4j.Record) interface{},
) ([]interface{}, error)// Query a single Row from Neo4J, for example when the result is a `count`
QuerySingle(
cypher string,
params map[string]interface{},
transform func(record neo4j.Record) interface{},
) (interface{}, error)// The following 2 functions are Reader utilities for convenience.
// Pass in initiated empty values in the ordering that corresponds to result elements, cast it back such as `val.(MyType)`
ReadSingleRow(cypher string, params map[string]interface{}, blankTypes ...interface{}) ([]interface{}, error)
ReadRows(cypher string, params map[string]interface{}, blankTypes ...interface{}) ([][]interface{}, error)// Use this to run `CREATE INDEX/CONSTRAINTS`
Bootstrap(cypherStmts []string) error
}
```## Installation
```
go get github.com/sagittaros/neo4j-go-mapper/mapper
```