gonorm

package module
v0.0.0-...-57c6826 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 17, 2015 License: MIT Imports: 5 Imported by: 1

README

GonormCypher

Neo4j Go library based on Anorm in the Play Framework.

Cypher is an amazing query language and I don't think that it should be abstracted away through incomplete "wrappers". This is my attempt at allowing you to use Cypher to interact with Neo4j in your Go code in a clean, idiomatic way.

Big ups to AnormCypher and Wes Freeman, as this is obviously a rough port of Wes' amazing work.

Installation

Use go get to install GonormCypher:

go get github.com/marpaia/GonormCypher

Unit tests

If you're testing this library on your local machine, just run go test -v, otherwise, edit gonorm_test.go and change http://localhost to whatever you'd like it to be, and then run go test -v.

External dependencies

This project has no external dependencies other than the Go standard library.

Documentation

Like most every other Golang project, this projects documentation can be found on godoc at godoc.org/github.com/marpaia/GonormCypher.

Examples

The unit tests are probably the best source of working examples for this project.

Consider the following example:

package main

import (
    "fmt"
    "github.com/marpaia/GonormCypher"
)

var g *gonorm.Gonorm

func init() {
    g = gonorm.New("http://localhost", 7474)
}

func main() {
    result, err := g.Cypher(`
    MERGE (p1:Person{name:{name1}})
    MERGE (p2:Person{name:{name2}})
    CREATE UNIQUE p1-[:KNOWS]->p2
    RETURN p1.name
    `).On(map[string]interface{}{
        "name1": "Alice",
        "name2": "Bob",
    }).Execute().AsString()

    if err != nil {
        panic(err)
    }

    fmt.Println("The result is:", result)
}

This will print The result is: Alice

Contributing

Please contribute and help improve this project!

  • Fork the repo
  • Make sure the tests pass
  • Improve the code
  • Make sure your feature has test coverage
  • Make sure the tests pass
  • Submit a pull request

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cypher

type Cypher struct {
	Query  string                 `json:"query"`
	Params map[string]interface{} `json:"params"`
	// contains filtered or unexported fields
}

The Cypher type represents the relevant parameters of a cypher query

func (*Cypher) Execute

func (c *Cypher) Execute() *Results

Execute executes the query stored in the Cypher type

func (*Cypher) On

func (c *Cypher) On(params map[string]interface{}) *Cypher

In a function-chaining fashion, On allows you to specify parameters for a cypher query

type Gonorm

type Gonorm struct {
	Host string
	Port int
	// contains filtered or unexported fields
}

The Gonorm type represents the relevant parameters of a Neo4j connection

func New

func New(host string, port int) *Gonorm

New is a factory method that creates a Gonorm type. You should use this instead of manually creating a Gonorm type yourself

func (*Gonorm) Cypher

func (g *Gonorm) Cypher(query string) *Cypher

Cypher allows you to create a Cypher type on top of a Gonorm type

type Neo4jError

type Neo4jError struct {
	Message    string   `json:"message"`
	Exception  string   `json:"exception"`
	Fullname   string   `json:"fullname"`
	Stacktrace []string `json:"stacktrace"`
}

Neo4jError defines an error type that is populated when an erroneous query is executed

func (*Neo4jError) Error

func (neo4jError *Neo4jError) Error() string

The Error method is attached to the Neo4jError type so that it satisfies the Error interface

type Node

type Node struct {
	Params map[string]interface{}
}

The Node type represent the relevant parameters of a Neo4j node

type Relationship

type Relationship struct {
	Params map[string]interface{}
	Type   string
	Start  string
	End    string
}

The Relationship type represent the relevant parameters of a Neo4j relationship

type Results

type Results struct {
	Columns []interface{} `json:"columns"`
	Data    []interface{} `json:"data"`
	Error   error
}

The Results type represents the relevant parameters of a response from the Neo4j API

func (*Results) AsInt

func (r *Results) AsInt() (int, error)

AsInt should be used when you return one integer in your cypher query

func (*Results) AsInts

func (r *Results) AsInts() ([]int, error)

AsInts should be used when you return several integers in your cypher query

func (*Results) AsNode

func (r *Results) AsNode() (*Node, error)

AsNode should be used when you return one node in your cypher query

func (*Results) AsNodes

func (r *Results) AsNodes() ([]*Node, error)

AsNodes should be used when you return several nodes in your cypher query

func (*Results) AsRelationship

func (r *Results) AsRelationship() (*Relationship, error)

AsRelationship should be used when you return one relationship in your cypher query

func (*Results) AsRelationships

func (r *Results) AsRelationships() ([]*Relationship, error)

AsRelationships should be used when you return several relationships in your cypher query

func (*Results) AsString

func (r *Results) AsString() (string, error)

AsString should be used when you return one string in your cypher query

func (*Results) AsStrings

func (r *Results) AsStrings() ([]string, error)

AsStrings should be used when you return several strings in your cypher query

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL