Reverting changes to handle full stops.
This commit is contained in:
parent
a2df1deb85
commit
cd81a83b94
|
@ -55,11 +55,16 @@ export default class AliasTables {
|
||||||
|
|
||||||
aliasField(field: string) {
|
aliasField(field: string) {
|
||||||
const tableNames = this.tableNames
|
const tableNames = this.tableNames
|
||||||
const possibleTableName = field.substring(0, field.lastIndexOf("."))
|
if (field.includes(".")) {
|
||||||
const foundTable = tableNames.find(name => possibleTableName.includes(name))
|
const [tableName, column] = field.split(".")
|
||||||
if (foundTable) {
|
const foundTableName = tableNames.find(name => tableName.includes(name))
|
||||||
const aliasedTable = this.getAlias(foundTable)
|
if (foundTableName) {
|
||||||
field = field.replace(foundTable, aliasedTable)
|
const aliasedTableName = tableName.replace(
|
||||||
|
foundTableName,
|
||||||
|
this.getAlias(foundTableName)
|
||||||
|
)
|
||||||
|
return `${aliasedTableName}.${column}`
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return field
|
return field
|
||||||
}
|
}
|
||||||
|
|
|
@ -176,25 +176,18 @@ describe("Captures of real examples", () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
describe("check some edge cases", () => {
|
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", () => {
|
it("should quoted table names", () => {
|
||||||
const aliasing = new AliasTables(dotTableNames)
|
const aliasing = new AliasTables(tableNames)
|
||||||
const aliased = aliasing.aliasField(`"hello.world"."field"`)
|
const aliased = aliasing.aliasField(`"hello"."field"`)
|
||||||
expect(aliased).toEqual(`"a"."field"`)
|
expect(aliased).toEqual(`"a"."field"`)
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should confirm table with dots in them works with grave accents", () => {
|
it("should handle quoted table names with graves", () => {
|
||||||
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"]
|
|
||||||
const aliasing = new AliasTables(tableNames)
|
const aliasing = new AliasTables(tableNames)
|
||||||
const aliased = aliasing.aliasField(`"hello"."world_relation"`)
|
const aliased = aliasing.aliasField("`hello`.`world`")
|
||||||
expect(aliased).toEqual(`"a"."world_relation"`)
|
expect(aliased).toEqual("`a`.`world`")
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue