4.4.0 • Published 6 months ago
@douglasgabr/cypher-builder v4.4.0
cypher-builder
Fluent CQL Builder for Neo4j
Installation
npm install @douglasgabr/cypher-builderor
yarn add @douglasgabr/cypher-builderUsage
Type inference (required for typescript projects)
First, you must create a *.d.ts file in your project, in order to type the possible nodes, relationships and their properties.
// neo4j-types.d.ts
import '@douglasgabr/cypher-builder';
declare module '@douglasgabr/cypher-builder' {
export interface CypherBuilderNodes {
User: {
id: string;
};
}
export interface CypherBuilderRelationships {
KNOWS: {
level: 'friendship' | 'colleague';
};
}
}That will enable your IDE (tested only in VSCode) to suggest values for your node labels, relationship types and its properties.
Node Label suggestion:

Node Properties suggestion:

Relationship Type suggestion:

Example
import { Builder } from '@douglasgabr/cypher-builder';
const queryBuilder = new Builder()
.match((match) => {
match
.node('person', 'Person', { name: 'Alice' })
.relationship('either', 'KNOWS')
.node('friend', 'Person'),
})
.where((where) => where.and('friend.age', '>=', 18))
.return('person', 'friend');
const { query, parameters } = queryBuilder.buildQueryObject();query:
MATCH (person:Person{ name: $person_name })-[:KNOWS]-(friend:Person)
WHERE friend.age >= $friend_age
RETURN person, friendparameters:
{
person_name: 'Alice',
friend_age: 18
}4.4.0
6 months ago
4.3.0
12 months ago
4.1.0
3 years ago
4.2.0
3 years ago
3.7.0
3 years ago
3.6.0
3 years ago
4.0.0
3 years ago
3.5.0
3 years ago
3.4.1
4 years ago
3.4.0
4 years ago
3.3.0
4 years ago
3.2.0
4 years ago
3.1.0
4 years ago
1.2.0
4 years ago
2.2.0
4 years ago
1.1.0
4 years ago
3.0.0
4 years ago
2.1.0
4 years ago
2.0.0
4 years ago
1.0.0
4 years ago