From cd81a83b949589f3413e589032247f8f99755335 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Wed, 28 Feb 2024 13:37:11 +0000 Subject: [PATCH] Reverting changes to handle full stops. --- .../server/src/api/controllers/row/alias.ts | 15 ++++++++----- .../src/integrations/tests/sqlAlias.spec.ts | 21 +++++++------------ 2 files changed, 17 insertions(+), 19 deletions(-) diff --git a/packages/server/src/api/controllers/row/alias.ts b/packages/server/src/api/controllers/row/alias.ts index ec96bb4603..d2d41e085f 100644 --- a/packages/server/src/api/controllers/row/alias.ts +++ b/packages/server/src/api/controllers/row/alias.ts @@ -55,11 +55,16 @@ export default class AliasTables { aliasField(field: string) { const tableNames = this.tableNames - const possibleTableName = field.substring(0, field.lastIndexOf(".")) - const foundTable = tableNames.find(name => possibleTableName.includes(name)) - if (foundTable) { - const aliasedTable = this.getAlias(foundTable) - field = field.replace(foundTable, aliasedTable) + if (field.includes(".")) { + const [tableName, column] = field.split(".") + const foundTableName = tableNames.find(name => tableName.includes(name)) + if (foundTableName) { + const aliasedTableName = tableName.replace( + foundTableName, + this.getAlias(foundTableName) + ) + return `${aliasedTableName}.${column}` + } } return field } diff --git a/packages/server/src/integrations/tests/sqlAlias.spec.ts b/packages/server/src/integrations/tests/sqlAlias.spec.ts index 6812d358b7..3fb90a3b4d 100644 --- a/packages/server/src/integrations/tests/sqlAlias.spec.ts +++ b/packages/server/src/integrations/tests/sqlAlias.spec.ts @@ -176,25 +176,18 @@ describe("Captures of real examples", () => { }) describe("check some edge cases", () => { - const dotTableNames = ["hello.world", "foo.bar.baz"] + const tableNames = ["hello", "world"] - it("should handle table names/columns with dots in them", () => { - const aliasing = new AliasTables(dotTableNames) - const aliased = aliasing.aliasField(`"hello.world"."field"`) + it("should quoted table names", () => { + const aliasing = new AliasTables(tableNames) + const aliased = aliasing.aliasField(`"hello"."field"`) expect(aliased).toEqual(`"a"."field"`) }) - it("should confirm table with dots in them works with grave accents", () => { - const aliasing = new AliasTables(dotTableNames) - const aliased = aliasing.aliasField("`hello.world`.`field`") - expect(aliased).toEqual("`a`.`field`") - }) - - it("should handle if a table name is used in a column", () => { - const tableNames = ["hello", "world"] + it("should handle quoted table names with graves", () => { const aliasing = new AliasTables(tableNames) - const aliased = aliasing.aliasField(`"hello"."world_relation"`) - expect(aliased).toEqual(`"a"."world_relation"`) + const aliased = aliasing.aliasField("`hello`.`world`") + expect(aliased).toEqual("`a`.`world`") }) }) })