-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for pipeable query parts + variable length paths + named …
…paths
- Loading branch information
Showing
29 changed files
with
469 additions
and
124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# ROADMAP | ||
|
||
* add support for ```WITH``` | ||
* add support for functions like ```shortestPath``` | ||
* add support for DateTime introduced in neo4j 3.4 | ||
* create alternative api which doesn't use @decorators | ||
* register all types explicitly in Schema object | ||
* use typescript conditional types for getting typescript types from runtime types declaration | ||
* ... | ||
* take all parameters when query is run, not when it's build (performance) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import {IQueryPart} from "../abstract/IQueryPart"; | ||
import {QueryContext} from "./QueryContext"; | ||
import {IBoundQueryPart} from "../abstract/IBoundQueryPart"; | ||
|
||
export class CompositeQueryPart implements IQueryPart { | ||
constructor(private elements:IQueryPart[]) {} | ||
|
||
toCypher(ctx:QueryContext):IBoundQueryPart { | ||
return this.elements.reduce((agg:IBoundQueryPart, el:IQueryPart) => { | ||
const bound = el.toCypher(ctx); | ||
|
||
return { | ||
cypherString: agg.cypherString + bound.cypherString, | ||
params: { | ||
...agg.params, | ||
...bound.params | ||
} | ||
} | ||
|
||
}, {cypherString: '', params: {}}) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import {IBoundQueryPart} from "../abstract/IBoundQueryPart"; | ||
import {IQueryPart} from "../abstract/IQueryPart"; | ||
import {QueryContext} from "./QueryContext"; | ||
|
||
export function joinQueryParts(separator:string, parts:IQueryPart[], ctx:QueryContext):IBoundQueryPart { | ||
let cypherStringParts:string[] = []; | ||
let params = {}; | ||
|
||
parts.forEach((el:IQueryPart) => { | ||
const bound = el.toCypher(ctx); | ||
|
||
cypherStringParts.push(bound.cypherString); | ||
params = {...params, ...bound.params}; | ||
}); | ||
|
||
return { | ||
cypherString: cypherStringParts.join(separator), | ||
params | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,73 +1,30 @@ | ||
import {MatchNodeQueryPart} from "./MatchNodeQueryPart"; | ||
import {MatchRelationQueryPart} from "./MatchRelationQueryPart"; | ||
import {IQueryPart} from "../abstract/IQueryPart"; | ||
import {QueryContext} from "../common/QueryContext"; | ||
import {IBoundQueryPart} from "../abstract/IBoundQueryPart"; | ||
import {NodeRelationConcatenator} from "../utils/NodeRelationConcatenator"; | ||
import {MatchUntypedNodeQueryPart} from "./MatchUntypedNodeQueryPart"; | ||
import {MatchUntypedRelationQueryPart} from "./MatchUntypedRelationQueryPart"; | ||
import {MatchedNodeQueryPart} from "../common/MatchedNodeQueryPart"; | ||
import {INodeMatchQueryPart} from "./INodeMatchQueryPart"; | ||
import {IRelationMatchQueryPart} from "./IRelationMatchQueryPart"; | ||
import {MatchBuilderCallback} from "../builders/QueryBuilder"; | ||
import {MatchBuilder} from "../builders/MatchBuilder"; | ||
import * as _ from 'lodash'; | ||
import {MatchableElement, MatchableQueryPart} from "./MatchableQueryPart"; | ||
import {PathQueryPart} from "./PathQueryPart"; | ||
|
||
export type MatchableElement = MatchNodeQueryPart<any> | ||
| MatchedNodeQueryPart | ||
| INodeMatchQueryPart<any> | ||
| IRelationMatchQueryPart<any>; | ||
export type MatchQueryPartChild = | ||
| PathQueryPart | ||
| MatchableQueryPart; | ||
|
||
export class MatchQueryPart implements IQueryPart { | ||
static build(isOptional:boolean, ...builderOrElements:(MatchBuilderCallback | MatchableElement)[]):MatchQueryPart { | ||
let matchableElements:MatchableElement[] = []; | ||
const matchableQueryPart = MatchableQueryPart.build(...builderOrElements); | ||
|
||
builderOrElements.forEach((el) => { | ||
if (_.isFunction(el)) { | ||
matchableElements = matchableElements.concat(el(new MatchBuilder())); | ||
} else { | ||
matchableElements.push(el as any); | ||
} | ||
}); | ||
|
||
return new MatchQueryPart(matchableElements, isOptional); | ||
return new MatchQueryPart(matchableQueryPart, isOptional); | ||
} | ||
|
||
constructor(private elements:MatchableElement[], private isOptionalMatch:boolean) {} | ||
constructor(private matchableQueryParts:MatchQueryPartChild, | ||
private isOptionalMatch:boolean) { | ||
} | ||
|
||
toCypher(ctx:QueryContext):IBoundQueryPart { | ||
let cypherPart:IBoundQueryPart = {cypherString: '', params: {}}; | ||
let concatenator:NodeRelationConcatenator = new NodeRelationConcatenator(); | ||
|
||
this.elements.forEach((el:MatchableElement) => { | ||
if (el instanceof MatchNodeQueryPart | ||
|| el instanceof MatchUntypedNodeQueryPart | ||
|| el instanceof MatchedNodeQueryPart) { | ||
|
||
let nodeQueryCypherPart = el.toCypher(ctx); | ||
concatenator.push({cypherString: nodeQueryCypherPart.cypherString, isRelation: false}); | ||
|
||
//TODO: check if there is no collisions! Ideally params should be registered in context!!! We could implement this behaviour there | ||
cypherPart.params = { | ||
...cypherPart.params, | ||
...nodeQueryCypherPart.params | ||
} | ||
} | ||
|
||
if (el instanceof MatchRelationQueryPart || el instanceof MatchUntypedRelationQueryPart) { | ||
let relationQueryCypherPart = el.toCypher(ctx); | ||
concatenator.push({cypherString: relationQueryCypherPart.cypherString, isRelation: true}); | ||
|
||
//TODO: check if there is no collisions! Ideally params should be registered in context!!! We could implement this behaviour there | ||
cypherPart.params = { | ||
...cypherPart.params, | ||
...relationQueryCypherPart.params | ||
} | ||
} | ||
}); | ||
|
||
const cypherPart = this.matchableQueryParts.toCypher(ctx); | ||
let matchKeyword = this.isOptionalMatch ? 'OPTIONAL MATCH' : 'MATCH'; | ||
cypherPart.cypherString = `${matchKeyword} ${concatenator.toString()}`; | ||
cypherPart.cypherString = `${matchKeyword} ${cypherPart.cypherString}`; | ||
return cypherPart; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.