Hemera-neo4j-store package
This is a plugin to use Neo4j with Hemera.
Execute any Cypher query from anywhere. For more details Cypher Query Language
Running the tests
Install and start Neo4j before starting.
See Documentation, for Ubuntu or other Linux distributions please google how to set up and install as a service. Mostly you can use your default package manager after giving it the package origin for Neo4j.
npm run test
Optional change the authentication for the test database by extending the node.js environment variables with the following vars;
Neo4J_URL=bolt://your.server
Neo4J_USER=your-neo4j-user
Neo4J_PASS=your-neo4j-password
Example
'use strict' const Hemera = const HemeraJoi = const nats = const HemeraArango = const hemera = nats logLevel: 'info' hemerahemera hemera
Dependencies
- hemera-joi
API
See Store Interface.
Custom Types
mainly used in patterns / queries
Identity
Represents the decimal id used in neo4j. Please see the Driver Documentation for further explanation.
Identity {
low: number,
heigh: number
}
ListOptions, OrderDescription
Options to set list query parameters to cypher query
OrderDescription {
property: string
desc: boolean // optional, defaulsts to false
}
ListOptions {
orderby: Array // can be string or OrderDescription or mixed
limit: number
offset: number // also known as SKIP
}
NodeQuery
There are two options for this type.
For one you can query a node by its labels as a string-array and a query as object (see below). Both are optional. But one must be given.
NodeQuery {
labels: Array<string>,
query: Object // key = property name, value = value, so far no qualifiers like $lt etc. in Mongo, just equal,
}
The other is to query by the node Id. This can be an Identity object or a numeric string or a number value
NodeQuery {
id: Identity | string | number
}
RelationQuery
There are two options for this type.
For one you can query a node by its labels as a string-array and a query as object (see below). Both are optional. But one must be given.
RelationQuery {
type: string,
query: Object // key = property name, value = value, so far no qualifiers like $lt etc. in Mongo, just equal,
}
The other is to query by the node Id. This can be an Identity object or a numeric string or a number value
RelationQuery {
id: Identity | string | number
}
mainly used in returned objects
data representations
These are plain js objects that stored meta data and can be created from and generated into v and Neo4JRelationModel
INeo4JNodeRepresentation
{
id: string,
_meta: {
labels: Array<string>
}
<Property>: <Value>
}
INeo4JRelationRepresentation
{
id: string,
_meta: {
type: string
}
<Property>: <Value>
}
Neo4JNodeModel
represents a node and its meta-values
Neo4JNodeModel
{
identity: Identity | string | number // node id
properties: object // properties of the node
labels: Array<string>
toObject() // -> returns INeo4JNodeRepresentation
initFromObject(object: object) // sets values as properties and meta data -> returns itself
setLabels(labels: string | Array<string>) // -> returns itself
addLabel(label: string) // -> returns itself
removeLabel(label: string) // -> returns itself
static fromObject(object: object | , label?: string | Array<string>) // label is an optional parameter -> returns new Neo4JNodeModel
static fromArray(objects: Array<object>, labels?: string | Array<string>) // labels is an optional parameter -> returns an array of new Neo4JNodeModel instances
}
Neo4JRelationModel
represents a relation and its meta-values
Neo4JRelationModel
{
identity: Identity | string | number // node id
properties: object // properties of the node
type: string // the relationship type in Neo4j
toObject() // -> returns INeo4JRelationRepresentation
initFromObject(object: any) // sets values as properties and meta data -> returns itself
static fromObject(object: object | , label?: string | Array<string>) // label is an optional parameter -> returns new Neo4JRelationModel
static fromArray(objects: Array<object>, labels?: string | Array<string>) // labels is an optional parameter -> returns an array of new Neo4JRelationModel instances
}
Database specific interface
create
The pattern is:
topic
: is the store name to publish toneo4j-store
cmd
: is the command to executecreate
labels
: the nodesArray<string>
(optional)data
: the node dataobject
ornull
(optional)
Example:
hemera
-> Will return the created node as Neo4JNodeModel
update
The pattern is:
topic
: is the store name to publish toneo4j-store
cmd
: is the command to executeupdate
labels
: the nodesArray<string>
(optional)query
: query which identifies the node by property / propertiesobject
(optional)data
: the node dataobject
ornull
(optional)
Example:
hemera
-> Will return the updated node as Neo4JNodeModel
updateById
The pattern is:
topic
: is the store name to publish toneo4j-store
cmd
: is the command to executeupdateById
id
: the node idnumber
orstring
orIdentity
data
: the node dataobject
ornull
Example:
hemera
-> Will return the updated node as Neo4JNodeModel
replace
The pattern is:
topic
: is the store name to publish toneo4j-store
cmd
: is the command to executereplace
labels
: the nodesArray<string>
(optional)query
: query which identifies the node by property / propertiesobject
data
: the node dataobject
Example:
hemera
-> Will return the replaced nodes as Array<Neo4JNodeModel>
replaceById
The pattern is:
topic
: is the store name to publish toneo4j-store
cmd
: is the command to executereplaceById
id
: the node idnumber
orstring
orIdentity
data
: the node dataobject
Example:
hemera
-> Will return the replaced node as Neo4JNodeModel
remove
The pattern is:
topic
: is the store name to publish toneo4j-store
cmd
: is the command to executeremove
labels
: the nodesArray<string>
(optional)query
: query which identifies the node by property / propertiesobject
(optional)
Example:
hemera
-> Will return the deleted node ids as Array<number>
removeById
The pattern is:
topic
: is the store name to publish toneo4j-store
cmd
: is the command to executeremoveById
id
: the node idnumber
orstring
orIdentity
Example:
hemera
-> Will return the deleted node id as number
find
The pattern is:
topic
: is the store name to publish toneo4j-store
cmd
: is the command to executefind
labels
: the nodesArray<string>
(optional)query
: query which identifies the node by property / propertiesobject
(optional)
Example:
hemera
-> Will return the found nodes as Array<Neo4JNodeModel>
findById
The pattern is:
topic
: is the store name to publish toneo4j-store
cmd
: is the command to executefindById
id
: the node idnumber
orstring
orIdentity
Example:
hemera
-> Will return the found node as Neo4JNodeModel
exists
The pattern is:
topic
: is the store name to publish toneo4j-store
cmd
: is the command to executefindById
labels
: the nodesArray<string>
(optional)query
: query which identifies the node by property / propertiesobject
(optional)id
: the node idnumber
orstring
orIdentity
(optional)
Example:
hemera
-> Will return true if the node exists boolean
createRelation
The pattern is:
topic
: is the store name to publish toneo4j-store
cmd
: is the command to executecreateRelation
type
: the relationship typestring
from
: the start nodeNodeQuery
to
: the target node idNodeQuery
data
: the relationship dataobject
ornull
(optional)
Example:
hemera
-> Will return the created relation as Neo4JRelationModel
updateRelation
The pattern is:
topic
: is the store name to publish toneo4j-store
cmd
: is the command to executeupdateRelation
type
: the relationship typestring
(optional)from
: the start node queryNodeQuery
(optional)to
: the target node queryNodeQuery
(optional)anyDirection
: set this to true if the direction is irrelevantboolean
(optional)query
: a query to find / filter the relation(s)RelationQuery
(optional)data
: the relationship dataobject
Note that one indication for the node must be given
Example:
hemera
hemera
-> Will return the replaced relations as Array<Neo4JRelationModel>
updateRelationById
The pattern is:
topic
: is the store name to publish toneo4j-store
cmd
: is the command to executeupdateRelationById
id
: the relationship id (not id of a node)number
orstring
orIdentity
data
: the relationship dataobject
Example:
hemera
-> Will return the updated relation as Neo4JRelationModel
replaceRelation
The pattern is:
topic
: is the store name to publish toneo4j-store
cmd
: is the command to executereplaceRelation
type
: the relationship typestring
(optional)from
: the start node queryNodeQuery
(optional)to
: the target node queryNodeQuery
(optional)anyDirection
: set this to true if the direction is irrelevantboolean
(optional)query
: a query to find / filter the relation(s)RelationQuery
(optional)data
: the relationship dataobject
Note that one indication for the node must be given
Example:
hemera
hemera
-> Will return the replaced relations as Array<Neo4JRelationModel>
replaceRelationById
The pattern is:
topic
: is the store name to publish toneo4j-store
cmd
: is the command to executereplaceRelationById
id
: the relationship id (not id of a node)number
orstring
orIdentity
data
: the relationship dataobject
Example:
hemera
-> Will return the updated relation as Neo4JRelationModel
removeRelation
The pattern is:
topic
: is the store name to publish toneo4j-store
cmd
: is the command to executeremoveRelation
type
: the relationship typestring
(optional)from
: the start node queryNodeQuery
(optional)to
: the target node queryNodeQuery
(optional)anyDirection
: set this to true if the direction is irrelevantboolean
(optional)query
: a query to find / filter the relation(s)RelationQuery
(optional)
Note that one indication for the node must be given
Example:
hemera
hemera
-> Will return the deleted relation ids Array<number>
removeRelationById
The pattern is:
topic
: is the store name to publish toneo4j-store
cmd
: is the command to executeremoveRelationById
id
: the relationship id (not id of a node)number
orstring
orIdentity
Example:
hemera
-> Will return the deleted relation id number
findRelation
The pattern is:
topic
: is the store name to publish toneo4j-store
cmd
: is the command to executefindRelation
type
: the relationship typestring
(optional)from
: the start node queryNodeQuery
(optional)to
: the target node queryNodeQuery
(optional)anyDirection
: set this to true if the direction is irrelevantboolean
(optional)query
: a query to find / filter the relation(s)RelationQuery
(optional)options
: list options for the responseListOptions
(optional)
Note that one indication for the node must be given
Example:
hemera
hemera
-> Will return the found relations as Array<Neo4JNodeModel>
findRelationById
The pattern is:
topic
: is the store name to publish toneo4j-store
cmd
: is the command to executefindRelationById
id
: the relationship id (not id of a node)number
orstring
orIdentity
Example:
hemera
-> Will return the found relation as Neo4JNodeModel
or null
if not found
relationExists
The pattern is:
topic
: is the store name to publish toneo4j-store
cmd
: is the command to executerelationExists
type
: the relationship typestring
(optional)from
: the start node queryNodeQuery
(optional)to
: the target node queryNodeQuery
(optional)anyDirection
: set this to true if the direction is irrelevantboolean
(optional)query
: a query to find / filter the relation(s)RelationQuery
(optional)
Note that one indication for the node must be given
Example:
hemera
hemera
-> Will return true if the relation exists boolean
findRelationStartNodes
The pattern is:
topic
: is the store name to publish toneo4j-store
cmd
: is the command to executefindRelationStartNodes
type
: the relationship typestring
(optional)to
: the target node queryNodeQuery
(optional)query
: a query to find / filter the relation(s)RelationQuery
(optional)options
: list options for the responseListOptions
(optional)
Note that one indication for the node must be given
Example:
hemera
hemera
-> Will return the replaced nodes as Array<Neo4JNodeModel>
findRelationEndNodes
The pattern is:
topic
: is the store name to publish toneo4j-store
cmd
: is the command to executefindRelationEndNodes
type
: the relationship typestring
(optional)from
: the origin node queryNodeQuery
(optional)query
: a query to find / filter the relation(s)RelationQuery
(optional)options
: list options for the responseListOptions
(optional)
Note that one indication for the node must be given
Example:
hemera
hemera
-> Will return the replaced nodes as Array<Neo4JNodeModel>
findNodesOnRelation
The pattern is:
topic
: is the store name to publish toneo4j-store
cmd
: is the command to executefindNodesOnRelation
type
: the relationship typestring
(optional)anyNode
: any connected node queryNodeQuery
(optional)query
: a query to find / filter the relation(s)RelationQuery
(optional)options
: list options for the responseListOptions
(optional)
Note that one indication for the node must be given
Example:
hemera
hemera
-> Will return the replaced nodes as Array<Neo4JNodeModel>
executeCypherQuery
The pattern is:
topic
: is the store name to publish toneo4j-store
cmd
: is the command to executeexecuteCypherQuery
query
: the Cypher query stringstring
properties
: properties and values used in query placeholdersobject
(optional)
Note that one indication for the node must be given
Example:
hemera
hemera
-> Will return the plan result as coming from Neo4j Driver