Skip to content

Commit

Permalink
Merge pull request #10 from neo4j/compile-cypher
Browse files Browse the repository at this point in the history
Updates compileCypher method so it properly exports its typings
  • Loading branch information
angrykoala committed Jun 8, 2023
2 parents 1029491 + cc144e1 commit 5673e57
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
9 changes: 5 additions & 4 deletions src/utils/compile-cypher-if-exists.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,16 @@
*/

import type { CypherEnvironment } from "../Environment";
import type { CypherCompilable } from "../types";
import { compileCypher } from "./compile-cypher";
import { CypherCompilable } from "../types";

/** Compiles the cypher of an element, if the resulting cypher is not empty adds a prefix */
export function compileCypherIfExists(
element: CypherCompilable | undefined,
env: CypherEnvironment,
options: { prefix?: string; suffix?: string } = {}
{ prefix = "", suffix = "" }: { prefix?: string; suffix?: string } = {}
): string {
if (!element) return "";
return compileCypher(element, env, options);
const cypher = element.getCypher(env);
if (!cypher) return "";
return `${prefix}${cypher}${suffix}`;
}
5 changes: 3 additions & 2 deletions src/utils/compile-cypher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,16 @@
*/

import type { CypherEnvironment } from "../Environment";
import type { CypherCompilable } from "../types";
import { Clause } from "../clauses/Clause";
import type { Expr } from "../types";
import { isCypherCompilable } from "./is-cypher-compilable";

/** Compiles a clause or expression to a Cypher string, adding optional prefix or suffix. To be used in a RawCypher callback
*
* The prefix and suffix will only be added if the resulting Cypher is **not** an empty string
*/
export function compileCypher(
element: CypherCompilable,
element: Expr | Clause,
env: CypherEnvironment,
{ prefix = "", suffix = "" }: { prefix?: string; suffix?: string } = {}
): string {
Expand Down

0 comments on commit 5673e57

Please sign in to comment.