Star

Created With
You are viewing the documentation for Neogma v1. This version is in maintenance mode, and you can upgrade to v2 following the migration guide. For the latest features and improvements, see the Neogma v2 documentation.

linkCreate

QueryBuilderParameters['Create']

linkCreate a node by using a literal string

A literal string will be used as is.

1linkconst queryBuilder = new QueryBuilder()

2link .create('(a:A { id: 1 })'); /* --> literal string to use */

3link

4linkconsole.log(queryBuilder.getStatement()); // CREATE (a:A { id: 1 })

5linkconsole.log(queryBuilder.getBindParam().get()); // {}

linkCreate a node by using an object

An object can be used to easily create a node with an identifier, label, properties.

1linkconst queryBuilder = new QueryBuilder().create({

2link /* --> (optional) the identifier of the node */

3link identifier: 'n',

4link /* --> (optional) the label of the node */

5link label: 'MyLabel',

6link /* --> (optional) the properties of thie node */

7link properties: {

8link id: '20',

9link },

10link});

11link

12linkconsole.log(queryBuilder.getStatement()); // CREATE (n:MyLabel { id: $id })

13linkconsole.log(queryBuilder.getBindParam().get()); // { id: '20' }

A Model can be used instead of the label attribute. In this case, the Model's label will be used.

1linkconst queryBuilder = new QueryBuilder().create({

2link /* --> (optional) */

3link identifier: 'n',

4link /* --> (optional) the Model whose label will be used */

5link model: MyModel,

6link});

7link

8link/* --> assuming MyModel.getLabel() returns `MyModelLabel` */

9linkconsole.log(queryBuilder.getStatement()); // CREATE (n:`MyModelLabel`)

10linkconsole.log(queryBuilder.getBindParam().get()); // {}

linkCreate multiple nodes

By using the multiple attribute and an array of nodes, multiple nodes can be created.

1linkconst queryBuilder = new QueryBuilder().create({

2link multiple: [

3link /* --> each entry has the same type as creating with a single object, like in the examples above */

4link {

5link identifier: 'a',

6link model: ModelA,

7link properties: {

8link id: '20',

9link },

10link },

11link {

12link label: 'LabelB',

13link },

14link ],

15link});

16link

17link/* --> assuming MyModel.getLabel() returns `MyModelLabel` */

18linkconsole.log(queryBuilder.getStatement()); // CREATE (a:`MyModelLabel` { id: $id }), (:LabelB)

19linkconsole.log(queryBuilder.getBindParam().get()); // { id: '20' }

linkCreate nodes and relationships

By using the related attribute and an array of alternating node-relationship objects, a create between them is created.

1linkconst queryBuilder = new QueryBuilder().create({

2link related: [

3link /* --> each even entry is a "node" object, as defined above */

4link {

5link identifier: 'a',

6link model: ModelA,

7link properties: {

8link nodeProp: '20',

9link },

10link },

11link /* --> each odd entry is a "relationship" object */

12link {

13link /* --> the direction of the relationship, from the node above towards the one below */

14link direction: 'out', // --> 'out' or 'in' or 'none'

15link /* --> (optional) name of the relationship */

16link name: 'RelationshipName',

17link /* --> (optional) identifier of the relationship */

18link identifier: 'r',

19link /* --> (optional) where parameters for matching this relationship. They are of the "WhereParamsI" type */

20link properties: {

21link relProp: 1,

22link },

23link },

24link /* --> the final entry must be a node */

25link {

26link identifier: 'b'

27link }

28link ],

29link});

30link

31link/* --> assuming MyModel.getLabel() returns `MyModelLabel` */

32link// CREATE (a:`MyModelLabel` { nodeProp: $nodeProp })-[r:RelationshipName { relProp: $relProp }]->(b)

33linkconsole.log(queryBuilder.getStatement());

34link// { nodeProp: '20', relProp: 1 }

35linkconsole.log(queryBuilder.getBindParam().get());

A more elaborate example:

1linkconst queryBuilder = new QueryBuilder().create({

2link related: [

3link {

4link identifier: 'a',

5link model: ModelA,

6link properties: {

7link nodeProp: '20',

8link },

9link },

10link /* --> The static `getRelationshipByAlias` of a model can be used as a shortcut. */

11link ModelA.getRelationshipByAlias('Relationship1'),

12link {

13link identifier: 'b'

14link },

15link {

16link direction: 'in'

17link },

18link {

19link ...ModelA.getRelationshipByAlias('Relationship2'),

20link identifier: 'r2'

21link properties: {

22link relProp: 2

23link }

24link },

25link {}

26link ],

27link});

28link

29link/* --> assuming MyModel.getLabel() returns `MyModelLabel` */

30link/* --> assuming 'Relationship1' has configuration: direction: 'out', name: 'Relationship1Name' */

31link/* --> assuming 'Relationship1' has configuration: direction: 'in', name: 'Relationship2Name' */

32link// --> CREATE (a:`MyModelLabel` { nodeProp: $nodeProp })-[:Relationship1Name]->(b)<-[r2:Relationship2Name { relProp: $relProp }]-()

33linkconsole.log(queryBuilder.getStatement());

34link// --> { nodeProp: '20', relProp: 2 }

35linkconsole.log(queryBuilder.getBindParam().get());

For expected behavior, the first and last elements must be a node object.

linkMerge

QueryBuilderParameters['MergeI']

Merge has identical typings and behavior as create. Just replace the create attributy with merge.

For example:

1linkconst queryBuilder = new QueryBuilder().merge({

2link identifier: 'n',

3link label: 'MyLabel',

4link properties: {

5link id: '20',

6link },

7link});

8link

9linkconsole.log(queryBuilder.getStatement()); // MERGE (n:MyLabel { id: $id })

10linkconsole.log(queryBuilder.getBindParam().get()); // { id: '20' }

CreateCreate a node by using a literal stringCreate a node by using an objectCreate multiple nodesCreate nodes and relationshipsMerge

Introduction Getting Started

Modelschevron_right

Sessions and Transactions

Query Builderchevron_right
Query Runnerchevron_right

Bind Parameters

Where Parameters