Reverting changes to handle full stops.

This commit is contained in:
mike12345567 2024-02-28 13:37:11 +00:00
parent a2df1deb85
commit cd81a83b94
2 changed files with 17 additions and 19 deletions

View File

@ -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
}

View File

@ -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`")
})
})
})