Home Reference Source
import Node from 'neo-maggoo/lib/Node.js'
public class | source

Node

Extends:

Model → Node

Class representing a single node

Static Member Summary

Static Public Members
public static get
public static get
public static get

labels: *

public static get

queryDefaults: {"parameters": *, "variable": string, "variables": *, "links": *}

Default values for query options

public static get

Definitions of the relationships for this Node

Static Method Summary

Static Public Methods
public static

addIndex(property: *, now: boolean): *

public static

addUnique(property: *, now: boolean): *

public static

Fetch Nodes

public static

Build a search query

public static

async count(filters: object | string, parameters: any, o: QueryOptions): number

Count nodes in graph database

public static

async dropIndex(property: *)

public static

async dropUnique(property: *)

public static

async find(filters: object | string | number, o: QueryOptions): NodeCollection

Find Nodes based on filter or Node ID

public static

async get(filters: string | object, o: QueryOptions): Node

Fetch a single Node

public static

Get a Relationship class by name.

public static

getRelationshipQueryOptions(levels: string, variables: object, reference: string): options

Build query options for related nodes Mostly intended for internal usage.

public static

async merge(criteria: object, properties: object, o: QueryOptions): Node

Get a node or a create a new one based on the given properties

public static
public static

Parse search filters

public static

async query(query: string, parameters: object, o: QueryOptions): NodeCollection

Use a query statement to search for Nodes By default returns results for 'n' as Node collection

public static

ID generator, uses ShortId by default

public static

async where(where: string, parameters: object, o: QueryOptions): NodeCollection

Use a query statement to search for Nodes By default returns results for 'n' as Node collection

Constructor Summary

Public Constructor
public

constructor(node: Node | neo4j.types.Node, graph: Graph)

Creates an instance of Node.

Member Summary

Public Members
public get

$base: *

public get

Whether or not the Node has changed properties.

public

$entity: neo4.Node

public
public get

The neo4j entity ID.

public get

Node labels.

public set

$labels(labels: Array): Array

Node labels.

public get

Whether or not the node is already stored in the graph database.

public get

The node ID.

public set

id

Method Summary

Public Methods
public

async addLabel(label: *, tx: undefined)

public

async addLabels(labels: *, tx: undefined)

public

addRelated(name: string, node: Node | NodeCollection | Node[], properties: Object)

Add related node(s).

public
public

async delete(deep: boolean, tx: Transaction)

Delete node from the graph database

public

async deleteRelated(tx: Transaction)

Delete related nodes and their relationships

public

async fetchRelated(relationships: object | array | string): NodeCollection | Object<string, NodeCollection>

Fetch related Nodes connected to the current node.

public

get(key: string): any | RelatedNodeCollection

Get a Node property or related node(s).

public

getLinked(name: string): *

Get linked results.

public

getRelated(name: string): RelatedNodeCollection

Get related node(s).

public

Get a Relationship class by name.

public

has(key: *): *

public

async removeLabel(label: *, tx: undefined)

public

async removeLabels(labels: *, tx: undefined)

public

async save(deep: boolean | string[], tx: any)

Save the Node to the graph database.

public

async saveRelated(keys: Array, tx: Transaction)

Save related nodes and their relationships

public

set(key: string, value: any): boolean

Set a Node property or related node(s).

public

setProperty(key: string, value: any)

Set property value

public

setRelated(name: string, node: Node | NodeCollection | Node[], properties: any, overwrite: boolean)

Set related node(s).

Static Public Members

public static get Collection: * source

public static get baseLabel: * source

public static get labels: * source

public static get queryDefaults: {"parameters": *, "variable": string, "variables": *, "links": *} source

Default values for query options

public static get relationships: object<string, RelationshipDefinition> source

Definitions of the relationships for this Node

Static Public Methods

public static addIndex(property: *, now: boolean): * source

Params:

NameTypeAttributeDescription
property *
now boolean
  • optional
  • default: false

Return:

*

public static addUnique(property: *, now: boolean): * source

Params:

NameTypeAttributeDescription
property *
now boolean
  • optional
  • default: false

Return:

*

public static async all(o: QueryOptions): NodeCollection source

Fetch Nodes

Params:

NameTypeAttributeDescription
o QueryOptions

Query options

Return:

NodeCollection

Results

Example:

const nodes = await Node.all({ limit: 10 })

public static buildQuery(o: object): string source

Build a search query

Params:

NameTypeAttributeDescription
o object

Query options

Return:

string

Query string

public static async count(filters: object | string, parameters: any, o: QueryOptions): number source

Count nodes in graph database

Params:

NameTypeAttributeDescription
filters object | string

Search filters (object) or where clause (string)

parameters any
  • optional
  • default: {}

Parameters used in where clause

o QueryOptions
  • optional
  • default: {}

Query options

Return:

number

Number of nodes

public static async dropIndex(property: *) source

Params:

NameTypeAttributeDescription
property *

public static async dropUnique(property: *) source

Params:

NameTypeAttributeDescription
property *

public static async find(filters: object | string | number, o: QueryOptions): NodeCollection source

Find Nodes based on filter or Node ID

Params:

NameTypeAttributeDescription
filters object | string | number

Search filters, Node ID (string), or neo4j node identifier (number)

o QueryOptions
  • optional
  • default: {}

Query options

Return:

NodeCollection

Results

Example:

// Find by ID
const nodes = Node.find('foo')
// Find by filter
const nodes = Node.find({ foo: 1 })
// Find by filter, with related Nodes
const nodes = Node.find({ foo: 1 }, { with: 'relatives' })
nodes[0].relatives

public static async get(filters: string | object, o: QueryOptions): Node source

Fetch a single Node

Params:

NameTypeAttributeDescription
filters string | object

Filter object or Node id

o QueryOptions
  • optional
  • default: {}

Query options

Return:

Node

Result

Example:

const node = await Node.get('foo')
const node = await Node.get({ id: 'foo' })

public static getRelationship(name: string): Relationship source

Get a Relationship class by name.

Params:

NameTypeAttributeDescription
name string

The name of the relationship

Return:

Relationship

The Relationship class

public static getRelationshipQueryOptions(levels: string, variables: object, reference: string): options source

Build query options for related nodes Mostly intended for internal usage.

Params:

NameTypeAttributeDescription
levels string

Filter for related nodes in dot-format (eg. father.children will fetch the related 'father' and its 'children')

variables object

The variables currently used for building the query

reference string
  • optional
  • default: 'n'

Reference variable for the current node

Return:

options

Query options object

Return Properties:

NameTypeAttributeDescription
matches array

Optional matches for each relationship

variables object

The variables currently used for building the query

public static async merge(criteria: object, properties: object, o: QueryOptions): Node source

Get a node or a create a new one based on the given properties

Params:

NameTypeAttributeDescription
criteria object

Specific properties to match

properties object

Properties to be set on the existing or created node

o QueryOptions
  • optional
  • default: {}

Query options

Return:

Node

Resulting Node

public static normalizeRelationshipLevels(levels: *): * source

Params:

NameTypeAttributeDescription
levels *

Return:

*

public static parseQueryFilters(filters: object | string | number, variable: string): QueryOptions source

Parse search filters

Params:

NameTypeAttributeDescription
filters object | string | number

Search filters, Node ID (string), or neo4j node identifier (number)

variable string

Variable for the current node

Return:

QueryOptions

Filters options object

public static async query(query: string, parameters: object, o: QueryOptions): NodeCollection source

Use a query statement to search for Nodes By default returns results for 'n' as Node collection

Params:

NameTypeAttributeDescription
query string

A search query

parameters object
  • optional
  • default: {}

Parameters used in query

o QueryOptions
  • optional
  • default: {}

Query options

Return:

NodeCollection

Results

Example:

const nodes = await Node.query(`
    MATCH (n:Node)
    WHERE n.foo > {foo}
`, { foo: 1 })

public static uuid(): string source

ID generator, uses ShortId by default

Return:

string

ID

public static async where(where: string, parameters: object, o: QueryOptions): NodeCollection source

Use a query statement to search for Nodes By default returns results for 'n' as Node collection

Params:

NameTypeAttributeDescription
where string

A where clause

parameters object
  • optional
  • default: {}

Parameters used in query

o QueryOptions
  • optional
  • default: {}

Query options

Return:

NodeCollection

Results

Example:

const nodes = await Node.where('n.foo > {foo}', { foo: 1 })

Public Constructors

public constructor(node: Node | neo4j.types.Node, graph: Graph) source

Creates an instance of Node.

Params:

NameTypeAttributeDescription
node Node | neo4j.types.Node

Node data object or neo4j Node

graph Graph
  • optional

The current graph

Public Members

public get $base: * source

public get $dirty: boolean source

Whether or not the Node has changed properties.

public $entity: neo4.Node source

public $graph: Graph source

public get $id: number source

The neo4j entity ID. Note that this could change over time, use id instead.

public get $labels: Array source

Node labels. Will be added the node in the graph database. By default it uses the constructor name.

public set $labels(labels: Array): Array source

Node labels. Will be added the node in the graph database. By default it uses the constructor name.

public get $new: boolean source

Whether or not the node is already stored in the graph database.

public get id: string source

The node ID. This will be automatically generated when the node is saved

public set id source

Public Methods

public async addLabel(label: *, tx: undefined) source

Params:

NameTypeAttributeDescription
label *
tx undefined
  • optional
  • default: undefined

public async addLabels(labels: *, tx: undefined) source

Params:

NameTypeAttributeDescription
labels *
tx undefined
  • optional
  • default: undefined

public addRelated(name: string, node: Node | NodeCollection | Node[], properties: Object) source

Add related node(s). Existing nodes will not be overwritten unless the relationship is singular.

Params:

NameTypeAttributeDescription
name string

The name of the relationship

node Node | NodeCollection | Node[]

Node(s)

properties Object
  • optional
  • default: {}

Properties to set on the relationship(s)

public clearCachedRelationships(relationships: undefined) source

Params:

NameTypeAttributeDescription
relationships undefined
  • optional
  • default: undefined

public async delete(deep: boolean, tx: Transaction) source

Delete node from the graph database

Params:

NameTypeAttributeDescription
deep boolean
  • optional
  • default: false

Delete related nodes

tx Transaction
  • optional
  • default: null

The current database transaction

public async deleteRelated(tx: Transaction) source

Delete related nodes and their relationships

Params:

NameTypeAttributeDescription
tx Transaction
  • optional

The current database transaction

public async fetchRelated(relationships: object | array | string): NodeCollection | Object<string, NodeCollection> source

Fetch related Nodes connected to the current node.

Params:

NameTypeAttributeDescription
relationships object | array | string

Similar to 'with' option in #Node.find

Return:

NodeCollection | Object<string, NodeCollection>

The related nodes

public get(key: string): any | RelatedNodeCollection source

Get a Node property or related node(s).

Params:

NameTypeAttributeDescription
key string

The name of the property or relationship

Return:

any | RelatedNodeCollection

The value or related node(s)

public getLinked(name: string): * source

Get linked results.

Params:

NameTypeAttributeDescription
name string

The name of the link

Return:

*

The related node(s) / value(s) or null if none is found

public getRelated(name: string): RelatedNodeCollection source

Get related node(s).

Params:

NameTypeAttributeDescription
name string

The name of the relationship

Return:

RelatedNodeCollection

The related node(s)

public getRelationship(name: string): Relationship source

Get a Relationship class by name.

Params:

NameTypeAttributeDescription
name string

The name of the relationship

Return:

Relationship

The Relationship class

public has(key: *): * source

Params:

NameTypeAttributeDescription
key *

Return:

*

public async removeLabel(label: *, tx: undefined) source

Params:

NameTypeAttributeDescription
label *
tx undefined
  • optional
  • default: undefined

public async removeLabels(labels: *, tx: undefined) source

Params:

NameTypeAttributeDescription
labels *
tx undefined
  • optional
  • default: undefined

public async save(deep: boolean | string[], tx: any) source

Save the Node to the graph database.

Params:

NameTypeAttributeDescription
deep boolean | string[]
  • optional
  • default: false

If true save all related nodes, or specific relationships defined as an array of strings.

tx any
  • optional
  • default: null

The current database transaction

public async saveRelated(keys: Array, tx: Transaction) source

Save related nodes and their relationships

Params:

NameTypeAttributeDescription
keys Array
  • optional

The relationships to be saved (all by default)

tx Transaction
  • optional

The current database transaction

public set(key: string, value: any): boolean source

Set a Node property or related node(s).

Params:

NameTypeAttributeDescription
key string

The name of the property or relationship

value any

The value or related node(s)

Return:

boolean

Whether or not the property was successfully set

public setProperty(key: string, value: any) source

Set property value

Params:

NameTypeAttributeDescription
key string

Property name

value any

Property value

public setRelated(name: string, node: Node | NodeCollection | Node[], properties: any, overwrite: boolean) source

Set related node(s).

Params:

NameTypeAttributeDescription
name string

The name of the relationship

node Node | NodeCollection | Node[]

Node(s)

properties any
  • optional
  • default: {}

Properties to set on the relationship(s)

overwrite boolean
  • optional
  • default: true

If set to false existing nodes will not be overwritten unless the relationship is singular