Skip to content

Commit 45f248d

Browse files
committed
Add yield expression to cypher QB
1 parent 01692d0 commit 45f248d

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

src/core/database/query-augmentation/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ import './map';
1111
import './pattern-formatting';
1212
import './subquery';
1313
import './summary';
14+
import './yield';
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { Many } from '@seedcompany/common';
2+
import { Clause, Query } from 'cypher-query-builder';
3+
4+
declare module 'cypher-query-builder/dist/typings/query' {
5+
interface Query {
6+
yield(...terms: Array<Many<string>>): this;
7+
}
8+
}
9+
10+
Query.prototype.yield = function (this: Query, ...terms: Array<Many<string>>) {
11+
const flattened = terms.flat();
12+
if (flattened.length === 0) return this;
13+
return this.continueChainClause(new Yield(flattened));
14+
};
15+
16+
class Yield extends Clause {
17+
constructor(public terms: readonly string[]) {
18+
super();
19+
}
20+
build() {
21+
return `YIELD ${this.terms.join(', ')}`;
22+
}
23+
}

0 commit comments

Comments
 (0)