fix(neo4j): preserve cypher labels during query execution
This commit is contained in:
1 parent
62bf47a0e9
commit
77c542248d
9 files changed
+84
-11
No files matched your search
@@ -34,6 +34,16 @@ describe("extractSqlParameters", () => {
|
||||
{ key: "params", name: "params", syntax: "named", token: ":params" },
|
||||
{ key: "context", name: "context", syntax: "sqlserver", token: "@context" },
|
||||
]);
|
||||
expect(extractSqlParameters("select :customer_id", { databaseType: "mysql" })).toEqual(["customer_id"]);
|
||||
});
|
||||
|
||||
it("preserves Neo4j pattern labels and relationship types", () => {
|
||||
const cypher = 'MATCH (p:Person)-[:WORK_IN]->(c:Company{name:"星云科技"})\nRETURN p.name, p.job, c.name';
|
||||
const options = { databaseType: "neo4j" as const };
|
||||
expect(extractSqlParameterDescriptors(cypher, options)).toEqual([]);
|
||||
expect(substituteSqlParameters(cypher, {}, options)).toBe(cypher);
|
||||
expect(extractSqlParameterDescriptors(cypher, { ...options, enabledSyntaxes: ["named"] as const })).toEqual([]);
|
||||
expect(extractSqlParameters("MATCH (p:Person {name:${name}}) RETURN p", options)).toEqual(["name"]);
|
||||
});
|
||||
|
||||
it("extracts unique template parameters in order", () => {
|
||||
|
||||
@@ -12,6 +12,13 @@ describe("resolveSqlVariableSyntaxToggles", () => {
|
||||
expect(resolveSqlVariableSyntaxToggles({ mysql: { shell: false } }, "postgres")).toEqual(DEFAULT_SQL_VARIABLE_SYNTAX_TOGGLES);
|
||||
});
|
||||
|
||||
it("disables SQL-style named parameters for Neo4j patterns", () => {
|
||||
const toggles = resolveSqlVariableSyntaxToggles(undefined, "neo4j");
|
||||
expect(toggles).toEqual({ ...DEFAULT_SQL_VARIABLE_SYNTAX_TOGGLES, named: false });
|
||||
expect(enabledSqlParameterSyntaxes(toggles)).not.toContain("named");
|
||||
expect(resolveSqlVariableSyntaxToggles({ neo4j: { shell: false } }, "neo4j")).toEqual({ ...toggles, shell: false });
|
||||
});
|
||||
|
||||
it("enables every syntax when the database type is unknown", () => {
|
||||
expect(resolveSqlVariableSyntaxToggles({ mysql: { shell: false } }, undefined)).toEqual(DEFAULT_SQL_VARIABLE_SYNTAX_TOGGLES);
|
||||
});
|
||||
|
||||
@@ -378,7 +378,7 @@ function findSqlParameterOccurrences(sql: string, options?: SqlParameterOptions)
|
||||
const occurrences: ParameterOccurrence[] = [];
|
||||
const databaseType = options?.databaseType;
|
||||
const nativeSqlServerParameters = collectNativeSqlServerParameters(sql, databaseType);
|
||||
const supportsNamedParameters = databaseType !== "saphana";
|
||||
const supportsNamedParameters = databaseType !== "saphana" && databaseType !== "neo4j";
|
||||
const enabledSyntaxes = options?.enabledSyntaxes ? new Set(options.enabledSyntaxes) : null;
|
||||
const isSyntaxEnabled = (syntax: SqlParameterSyntax) => !enabledSyntaxes || enabledSyntaxes.has(syntax);
|
||||
const complexTypeFieldSeparators = supportsNamedParameters && isSyntaxEnabled("named") ? collectComplexTypeFieldSeparators(sql, databaseType) : new Set<number>();
|
||||
|
||||
@@ -3,11 +3,11 @@
|
||||
// DBX runs two client-side substitution systems before sending SQL to a backend:
|
||||
// the placeholder parameter dialog (`sqlParameters.ts`, five syntaxes) and the
|
||||
// `@set name = value;` expansion (`sqlVariables.ts`). This module lets users opt
|
||||
// out of individual syntaxes per database type. Every toggle defaults to `true`,
|
||||
// so an empty/absent config reproduces the historical "always substitute" behaviour.
|
||||
// out of individual syntaxes per database type. SQL syntaxes default to `true`,
|
||||
// except Neo4j's `:label` patterns, which are not named parameters.
|
||||
//
|
||||
// Storage is sparse: only syntaxes explicitly turned off (`false`) are persisted,
|
||||
// keyed by database type. Anything not stored resolves to enabled.
|
||||
// keyed by database type. Unset values use the database-specific defaults.
|
||||
|
||||
import type { DatabaseType } from "@/types/database";
|
||||
import type { SqlParameterSyntax } from "@/lib/sql/sqlParameters";
|
||||
@@ -72,7 +72,7 @@ export function resolveSqlVariableSyntaxToggles(overrides: SqlVariableSyntaxOver
|
||||
const partial = dbType ? overrides?.[dbType] : undefined;
|
||||
return {
|
||||
positional: partial?.positional ?? true,
|
||||
named: partial?.named ?? true,
|
||||
named: dbType === "neo4j" ? false : (partial?.named ?? true),
|
||||
shell: partial?.shell ?? true,
|
||||
mybatis: partial?.mybatis ?? true,
|
||||
sqlserver: partial?.sqlserver ?? true,
|
||||
|
||||
Reference in new issue
Block a user