go_cypherdsl

package module
v0.2.6 Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2023 License: MIT Imports: 6 Imported by: 0

README

Go Report Card

go-cypherdsl

Golang Cypher DSL

Documentation

Index

Constants

View Source
const (
	SetEqualTo = "="
	SetMutate  = "+="
)

Variables

This section is empty.

Functions

func RowsTo2dStringArray

func RowsTo2dStringArray(data [][]interface{}) ([][]string, error)

func RowsToStringArray

func RowsToStringArray(data [][]interface{}) ([]string, error)

func SetLogger

func SetLogger(logger *logrus.Entry) error

Types

type BooleanOperator

type BooleanOperator string
const (
	LessThanOperator             BooleanOperator = "<"
	GreaterThanOperator          BooleanOperator = ">"
	LessThanOrEqualToOperator    BooleanOperator = "<="
	GreaterThanOrEqualToOperator BooleanOperator = ">="
	EqualToOperator              BooleanOperator = "="  // TODO: Rename to `EqualityOperator` to match OC9 spec
	NotEqualToOperator           BooleanOperator = "<>" // TODO: Rename to `InequalityOperator` to match OC9 spec
	PlusEqualOperator            BooleanOperator = "+="
	InOperator                   BooleanOperator = "IN"
	IsOperator                   BooleanOperator = "IS"
	RegexEqualToOperator         BooleanOperator = "=~"
	StartsWithOperator           BooleanOperator = "STARTS WITH"
	EndsWithOperator             BooleanOperator = "ENDS WITH"
	ContainsOperator             BooleanOperator = "CONTAINS"
)

func (BooleanOperator) String

func (b BooleanOperator) String() string

type ConditionBuilder

type ConditionBuilder struct {
	Start   *operatorNode
	Current *conditionNode
	// contains filtered or unexported fields
}

func (*ConditionBuilder) And

func (*ConditionBuilder) AndNested

func (c *ConditionBuilder) AndNested(query WhereQuery, err error) ConditionOperator

func (*ConditionBuilder) Build

func (c *ConditionBuilder) Build() (WhereQuery, error)

func (*ConditionBuilder) Not

func (*ConditionBuilder) NotNested

func (c *ConditionBuilder) NotNested(query WhereQuery, err error) ConditionOperator

func (*ConditionBuilder) Or

func (*ConditionBuilder) OrNested

func (c *ConditionBuilder) OrNested(query WhereQuery, err error) ConditionOperator

func (*ConditionBuilder) Xor

func (*ConditionBuilder) XorNested

func (c *ConditionBuilder) XorNested(query WhereQuery, err error) ConditionOperator

type ConditionConfig

type ConditionConfig struct {
	// Either ConditionOperator or ConditionFunction can be set, depending on whether an operator (e.g. '=') is
	// required, or a function (e.g. exists()). Both cannot be specified.
	ConditionOperator BooleanOperator

	//condition functions that can be used
	ConditionFunction string

	// When constructing a conditional, Name must be specified (unless filtering on a Path). Additionally, either
	// Field or Label must be specified (but not both). If Field is specified, FieldManipulationFunction is an
	// optional function that can be specified to manipulate the specified Field during the query. If Label
	// is specified, all other fields (other than Name and NegateCondition) will be ignored.
	Name  string
	Field string // TODO: Rename to `Property` to match OC9 spec
	Label string

	//exclude parentheses
	FieldManipulationFunction string

	// When filtering on a Path, the only other field that can be specified is NegateCondition.
	Path *PathBuilder

	// When using any operator to compare to a specific value (other than InOperator), this field must be specified.
	// If Check and (CheckName, CheckField) are both specified - (CheckName, CheckField) will take precedence.
	Check interface{}

	// When comparing one node to another, CheckField and CheckName must be specified.
	CheckName  string
	CheckField string

	// When using the InOperator, this field must be specified. This will not apply to any other operators.
	CheckSlice []interface{}

	// When NegateCondition is set to true, NOT is appended to the start of this condition to apply a logical
	// negation to the statement.
	NegateCondition bool
}

ConditionConfig is the configuration object for where conditions

func (*ConditionConfig) ToString

func (condition *ConditionConfig) ToString() (string, error)

type ConditionOperator

type ConditionOperator interface {
	And(c *ConditionConfig) ConditionOperator
	AndNested(query WhereQuery, err error) ConditionOperator
	Or(c *ConditionConfig) ConditionOperator
	OrNested(query WhereQuery, err error) ConditionOperator
	Xor(c *ConditionConfig) ConditionOperator
	XorNested(query WhereQuery, err error) ConditionOperator
	Not(c *ConditionConfig) ConditionOperator
	NotNested(query WhereQuery, err error) ConditionOperator
	Build() (WhereQuery, error)
}

func C

func C(condition *ConditionConfig) ConditionOperator

C is used to start a condition chain provided with a ConditionConfig

type ConstraintConfig

type ConstraintConfig struct {
	//specify the name of the variable for the constraint
	Name string

	//specify the type the action takes place on
	Type string

	//specify the field the action takes place on
	Field string

	//require field to be unique
	Unique bool

	//require field to show up
	Exists bool
}

type Create

type Create interface {
	Create(CreateQuery, error) Cypher
}

complete

type CreateQuery

type CreateQuery string

func NewConstraint

func NewConstraint(constraint *ConstraintConfig) (CreateQuery, error)

func NewIndex

func NewIndex(index *IndexConfig) (CreateQuery, error)

func NewNode

func NewNode(builder *PathBuilder) (CreateQuery, error)

func (*CreateQuery) ToString

func (c *CreateQuery) ToString() string

type CustomCypher

type CustomCypher interface {
	Cypher(q string) Cypher
}

type Cypherize

type Cypherize interface {
	ToCypher() (string, error)
}

type Delete

type Delete interface {
	Delete(detach bool, params ...string) Cypher
}

complete

type DeleteQuery

type DeleteQuery string

func (*DeleteQuery) ToString

func (c *DeleteQuery) ToString() string

type Direction

type Direction int
const (
	DirectionOutgoing Direction = 0
	DirectionIncoming Direction = 1
	DirectionNone     Direction = 2
	DirectionBoth     Direction = 3
)

func (Direction) ToString

func (d Direction) ToString() string

func (Direction) ToStringClause

func (d Direction) ToStringClause(clause string) string

type E

type E struct {
	//direction of the edge, if null default to any
	Direction Direction

	//variable name for constraint queries, omit if null
	Name string

	//names in the case that the edge is named or the query could be on multiple edges
	Types []string

	//min jumps to the next node, if null omit
	MinJumps int

	//max jumps to the next node, if null omit
	MaxJumps int

	//params for edges across individual jumps
	Params *Params
}

E represents an edge

func (*E) ToCypher

func (e *E) ToCypher() (string, error)

type EdgeConfig

type EdgeConfig struct {
	Type      string
	StartNode int64
	EndNode   int64
}

type EdgeStep

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

func (*EdgeStep) Done

func (e *EdgeStep) Done() *PathBuilder

func (*EdgeStep) V

func (e *EdgeStep) V(vertices ...V) *VertexStep

type FuncString

type FuncString string

func (*FuncString) ToString

func (p *FuncString) ToString() string

type FunctionConfig

type FunctionConfig struct {
	Name   string
	Params []interface{}
}

func (*FunctionConfig) ToString

func (f *FunctionConfig) ToString() (string, error)

type IndexConfig

type IndexConfig struct {
	Type   string
	Fields []string
}

type Limit

type Limit interface {
	Limit(num int) Cypher
}

type Match

type Match interface {
	Match(p *PathBuilder) Cypher
}

complete

type Merge

type Merge interface {
	Merge(mergeConf *MergeConfig) Cypher
}

complete

type MergeConfig

type MergeConfig struct {
	// the path its merging on
	Path string

	// what it does if its creating the node
	OnCreate *MergeSetConfig

	// what it does if its matching the node
	OnMatch *MergeSetConfig
}

func (*MergeConfig) ToString

func (m *MergeConfig) ToString() (string, error)

type MergeQuery

type MergeQuery string

func (*MergeQuery) ToString

func (c *MergeQuery) ToString() string

type MergeSetConfig

type MergeSetConfig struct {
	// variable name
	Name string

	// member variable of node
	Member string

	// new value
	Target interface{}

	// new value if its a function, do not include
	TargetFunction *FunctionConfig

	// Operator is the operator used in the SET clause. Must be "=" or "+=".
	// If not set, defaults to "=".
	Operator BooleanOperator
}

func (*MergeSetConfig) ToString

func (m *MergeSetConfig) ToString() (string, error)

type OptionalMatch

type OptionalMatch interface {
	OptionalMatch(p *PathBuilder) Cypher
}

type OrderBy

type OrderBy interface {
	OrderBy(orderBys ...OrderByConfig) Cypher
}

type OrderByConfig

type OrderByConfig struct {
	Name   string
	Member string
	Desc   bool
}

func (*OrderByConfig) ToString

func (o *OrderByConfig) ToString() (string, error)

type PStep

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

func (*PStep) Done

func (p *PStep) Done() *PathBuilder

func (*PStep) V

func (p *PStep) V(vertices ...V) *PathBuilder

type ParamString

type ParamString string

func (*ParamString) ToString

func (p *ParamString) ToString() string

type Params

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

func ParamsFromMap

func ParamsFromMap(m map[string]interface{}) (*Params, error)

func (*Params) IsEmpty

func (p *Params) IsEmpty() bool

func (*Params) Set

func (p *Params) Set(key string, value interface{}) error

func (*Params) ToCypherMap

func (p *Params) ToCypherMap() string

type PathBuilder

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

func NewPath

func NewPath() *PathBuilder

func Path

func Path() *PathBuilder

func (*PathBuilder) P

func (m *PathBuilder) P() *PathBuilder

func (*PathBuilder) ToCypher

func (m *PathBuilder) ToCypher() (string, error)

func (*PathBuilder) V

func (m *PathBuilder) V(vertices ...V) *VertexStep

type QueryBuilder

type QueryBuilder struct {
	Start   *queryPartNode
	Current *queryPartNode
	// contains filtered or unexported fields
}

func QB

func QB() *QueryBuilder

func (*QueryBuilder) Create

func (q *QueryBuilder) Create(c CreateQuery, err error) Cypher

func (*QueryBuilder) Cypher

func (q *QueryBuilder) Cypher(c string) Cypher

func (*QueryBuilder) Delete

func (q *QueryBuilder) Delete(detach bool, params ...string) Cypher

func (*QueryBuilder) Limit

func (q *QueryBuilder) Limit(num int) Cypher

func (*QueryBuilder) Match

func (q *QueryBuilder) Match(p *PathBuilder) Cypher

func (*QueryBuilder) Merge

func (q *QueryBuilder) Merge(mergeConf *MergeConfig) Cypher

func (*QueryBuilder) OptionalMatch

func (q *QueryBuilder) OptionalMatch(p *PathBuilder) Cypher

func (*QueryBuilder) OrderBy

func (q *QueryBuilder) OrderBy(orderBys ...OrderByConfig) Cypher

func (*QueryBuilder) Remove

func (q *QueryBuilder) Remove(removes ...RemoveConfig) Cypher

func (*QueryBuilder) Return

func (q *QueryBuilder) Return(distinct bool, parts ...ReturnPart) Cypher

func (*QueryBuilder) Set

func (q *QueryBuilder) Set(sets ...SetConfig) Cypher

func (*QueryBuilder) Skip

func (q *QueryBuilder) Skip(num int) Cypher

func (*QueryBuilder) ToCypher

func (q *QueryBuilder) ToCypher() (string, error)

func (*QueryBuilder) Union

func (q *QueryBuilder) Union(all bool) Cypher

func (*QueryBuilder) Unwind

func (q *QueryBuilder) Unwind(unwind *UnwindConfig) Cypher

func (*QueryBuilder) Where

func (q *QueryBuilder) Where(cb ConditionOperator) Cypher

func (*QueryBuilder) With

func (q *QueryBuilder) With(conf *WithConfig) Cypher

type QueryCompleter

type QueryCompleter interface {
	ToCypher() (string, error)
}

type Remove

type Remove interface {
	Remove(removes ...RemoveConfig) Cypher
}

type RemoveConfig

type RemoveConfig struct {
	Name   string
	Field  string
	Labels []string
}

func (*RemoveConfig) ToString

func (r *RemoveConfig) ToString() (string, error)

type RemoveQuery

type RemoveQuery string

func (*RemoveQuery) ToString

func (c *RemoveQuery) ToString() string

type Return

type Return interface {
	Return(distinct bool, parts ...ReturnPart) Cypher
}

complete

type ReturnPart

type ReturnPart struct {
	Name              string
	Type              string
	Alias             string
	Function          *FunctionConfig
	Literal           interface{}
	BooleanExpression WhereQuery
	Path              string
}

func (*ReturnPart) ToString

func (r *ReturnPart) ToString() (string, error)

type ReturnQuery

type ReturnQuery string

func NewReturnClause

func NewReturnClause(distinct bool, parts ...ReturnPart) (ReturnQuery, error)

func (*ReturnQuery) ToString

func (c *ReturnQuery) ToString() string

type Set

type Set interface {
	Set(sets ...SetConfig) Cypher
}

complete

type SetConfig

type SetConfig struct {
	//name is  required, just the var name
	Name string

	//member is used to set the specific member of a node
	Member string

	//defines whether a variable is being set equal to or mutated
	Operation SetOperation

	//used to set the label of a node, (can give a node many labels)
	Label []string

	//if the target is a literal or a reference to another variable
	Target interface{}

	//if the target is a map
	TargetMap *Params

	//if the target is a function
	TargetFunction *FunctionConfig

	//if the set is being done on a condition
	Condition ConditionOperator
}

func (*SetConfig) ToString

func (s *SetConfig) ToString() (string, error)

type SetOperation

type SetOperation string

type SetQuery

type SetQuery string

func (*SetQuery) ToString

func (c *SetQuery) ToString() string

type Skip

type Skip interface {
	Skip(num int) Cypher
}

type Union

type Union interface {
	Union(all bool) Cypher
}

type Unwind

type Unwind interface {
	Unwind(unwind *UnwindConfig) Cypher
}

type UnwindConfig

type UnwindConfig struct {
	Slice []interface{}
	As    string
}

func (*UnwindConfig) ToString

func (u *UnwindConfig) ToString() (string, error)

type V

type V struct {
	//name of the vertex, omit if null
	Name string

	//type of edge, omit if null
	Type string

	//params for edge to map to, omit if null
	Params *Params
}

v represents a vertex query

func (*V) ToCypher

func (v *V) ToCypher() (string, error)

type VertexStep

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

func (*VertexStep) Build

func (v *VertexStep) Build() *PathBuilder

func (*VertexStep) E

func (v *VertexStep) E(edge E) *EdgeStep

func (*VertexStep) ToCypher

func (v *VertexStep) ToCypher() (string, error)

type Where

type Where interface {
	Where(cb ConditionOperator) Cypher
}

complete

type WhereQuery

type WhereQuery string

func NewCondition

func NewCondition(condition *ConditionConfig) (WhereQuery, error)

func (*WhereQuery) ToString

func (c *WhereQuery) ToString() string

type With

type With interface {
	With(conf *WithConfig) Cypher
}

type WithConfig

type WithConfig struct {
	Parts []WithPart
}

func (*WithConfig) ToString

func (w *WithConfig) ToString() (string, error)

type WithPart

type WithPart struct {
	Function *FunctionConfig
	Name     string
	Field    string
	As       string
}

todo distinct

func (*WithPart) ToString

func (wp *WithPart) ToString() (string, error)

Jump to

Keyboard shortcuts

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