graph

package
v0.0.0-...-dda3d19 Latest Latest
Warning

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

Go to latest
Published: May 21, 2020 License: BSD-3-Clause Imports: 7 Imported by: 0

Documentation

Overview

Package graph is a protobuf-based library that can be used to safely generate arbitrary Neo4j graph queries. Its subpackage, graphpb, has five main types

ReadQuery
MergeQuery
CreateQuery
DeleteQuery
RemoveQuery

as well as a wrapper type—Query—that contains one of the above five types.

The goal of package graph is to provide a way to write structured Cypher queries in a safe, easy manner. The structured nature of the five main query types allows the backend server to, for example, reject writes when only reads are allowed or modify the request after it's received. Package graph can also be the base of an ORM.

graph provides some convenience features such as a default LIMIT, type-checked functions, checking for balanced parenthases in mathematical equations, and detection of unused parameters.

Index

Constants

View Source
const DefaultMaxLimit = 100

DefaultMaxLimit is the default maximum LIMIT if, upon creation of a Generator, its limit is <= 0.

Variables

This section is empty.

Functions

func QuoteIdent

func QuoteIdent(s string) string

QuoteIdent quotes a Neo4j identifier in backticks, escaping all backticks.

Types

type Generator

type Generator struct {
	// contains filtered or unexported fields
}

Generator generates Cypher and corresponding parameters from a protocol buffer object. It may be reused, but not concurrently.

func NewGenerator

func NewGenerator(opts ...Option) *Generator

NewGenerator creates a Generator from the provided options.

func (*Generator) Create

func (g *Generator) Create(c *gpb.CreateQuery) (string, map[string]interface{}, error)

Create converts a CreateQuery object to its resulting Cypher query format and returns the query along with any arguments and an error, if any.

func (*Generator) Cypher

func (g *Generator) Cypher(obj interface{}) (string, map[string]interface{}, error)

Cypher converts a queryQuery object to its resulting Cypher query format and returns the query along with any arguments and an error, if any.

func (*Generator) Delete

func (g *Generator) Delete(d *gpb.DeleteQuery) (string, map[string]interface{}, error)

Delete converts a DeleteQuery object to its resulting Cypher query format and returns the query along with any arguments and an error, if any.

func (*Generator) Merge

func (g *Generator) Merge(m *gpb.MergeQuery) (string, map[string]interface{}, error)

Merge converts a MergeQuery object to its resulting Cypher query format and returns the query along with any arguments and an error, if any.

func (*Generator) Read

func (g *Generator) Read(r *gpb.ReadQuery) (string, map[string]interface{}, error)

Read converts a ReadQuery object to its resulting Cypher query format and returns the query along with any arguments and an error, if any.

func (*Generator) Remove

func (g *Generator) Remove(d *gpb.RemoveQuery) (string, map[string]interface{}, error)

Remove converts a RemoveQuery object to its resulting Cypher query format and returns the query along with any arguments and an error, if any.

type Option

type Option func(*Generator)

Option is a configuration option for a Generator.

func WithMaxLimit

func WithMaxLimit(limit int64) Option

WithMaxLimit sets the largest LIMIT value the Generator will allow.

func WithWriter

func WithWriter(w Writer) Option

WithWriter sets the Generator's internal Writer.

type Writer

type Writer interface {
	io.Writer
	io.ByteWriter
	WriteString(string) (int, error)
	Truncate(int)
	Len() int
	fmt.Stringer
}

Writer consists of the methods used by a Generator to create the Cypher query string. It assumes the methods function similarly to bytes.Buffer.

Directories

Path Synopsis
Package graphpb is a generated protocol buffer package.
Package graphpb is a generated protocol buffer package.

Jump to

Keyboard shortcuts

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