diff --git a/src/clauses/index.ts b/src/clauses/index.ts index fc7de614..f0a4dfe4 100644 --- a/src/clauses/index.ts +++ b/src/clauses/index.ts @@ -1,6 +1,7 @@ import { Dictionary, Many } from 'lodash'; import { NodePattern } from './node-pattern'; import { RelationDirection, RelationPattern } from './relation-pattern'; +import { PathNamePattern } from './path-name-pattern'; import { PathLength } from '../utils'; export { Create } from './create'; @@ -10,6 +11,7 @@ export { Unwind } from './unwind'; export { Delete } from './delete'; export { Set } from './set'; export { RelationPattern } from './relation-pattern'; +export { PathNamePattern } from './path-name-pattern'; export { Match } from './match'; export { Remove } from './remove'; export { Return } from './return'; @@ -185,3 +187,18 @@ export function relation( ) { return new RelationPattern(dir, name, labels, conditions, length); } + +/** + * Creates a named path pattern like `p=` for creating named paths. + * + * For more details on node patterns see the cypher + * [docs]{@link + * https://neo4j.com/docs/cypher-manual/current/clauses/match/#named-paths} + * + * @param {string} name + */ +export function pathName( + name: string, +) { + return new PathNamePattern(name); +} diff --git a/src/clauses/path-name-pattern.spec.ts b/src/clauses/path-name-pattern.spec.ts new file mode 100644 index 00000000..6cbe1473 --- /dev/null +++ b/src/clauses/path-name-pattern.spec.ts @@ -0,0 +1,12 @@ +import { PathNamePattern } from './path-name-pattern'; +import { expect } from 'chai'; + +describe('PathNamePattern', () => { + + it('should accept just a name', () => { + const pattern = new PathNamePattern('p'); + expect(pattern.getLabelsString()).to.equal(''); + expect(pattern.getNameString()).to.equal('p'); + expect(pattern.build()).to.equal('p='); + }); +}); diff --git a/src/clauses/path-name-pattern.ts b/src/clauses/path-name-pattern.ts new file mode 100644 index 00000000..296034f2 --- /dev/null +++ b/src/clauses/path-name-pattern.ts @@ -0,0 +1,16 @@ +import { trim } from 'lodash'; +import { Pattern } from './pattern'; + +export class PathNamePattern extends Pattern { + constructor( + name: string, + ) { + super(name); + } + + build() { + let query = this.getNameString(); + query += '='; + return `${trim(query)}`; + } +}