Loop aliasing.
This commit is contained in:
parent
59ab557a93
commit
d68fcbf8f7
|
@ -32,7 +32,7 @@ export default class AliasTables {
|
||||||
char.substring(0, char.length - 1) +
|
char.substring(0, char.length - 1) +
|
||||||
String.fromCharCode(char.charCodeAt(char.length - 1) + 1)
|
String.fromCharCode(char.charCodeAt(char.length - 1) + 1)
|
||||||
// reached end of characters, extend number of characters used
|
// reached end of characters, extend number of characters used
|
||||||
if (this.character === "z") {
|
if (this.character.charAt(this.character.length - 1) === "z") {
|
||||||
this.character = new Array(this.character.length + 1).fill("a").join("")
|
this.character = new Array(this.character.length + 1).fill("a").join("")
|
||||||
}
|
}
|
||||||
return char
|
return char
|
||||||
|
|
|
@ -2,6 +2,8 @@ import { QueryJson } from "@budibase/types"
|
||||||
import { join } from "path"
|
import { join } from "path"
|
||||||
import Sql from "../base/sql"
|
import Sql from "../base/sql"
|
||||||
import { SqlClient } from "../utils"
|
import { SqlClient } from "../utils"
|
||||||
|
import AliasTables from "../../api/controllers/row/alias"
|
||||||
|
import { generator } from "@budibase/backend-core/tests"
|
||||||
|
|
||||||
function multiline(sql: string) {
|
function multiline(sql: string) {
|
||||||
return sql.replace(/\n/g, "").replace(/ +/g, " ")
|
return sql.replace(/\n/g, "").replace(/ +/g, " ")
|
||||||
|
@ -157,4 +159,19 @@ describe("Captures of real examples", () => {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe("check max character aliasing", () => {
|
||||||
|
it("should handle over 'z' max character alias", () => {
|
||||||
|
const tableNames = []
|
||||||
|
for (let i = 0; i < 100; i++) {
|
||||||
|
tableNames.push(generator.word())
|
||||||
|
}
|
||||||
|
const aliasing = new AliasTables(tableNames)
|
||||||
|
let alias: string = ""
|
||||||
|
for (let table of tableNames) {
|
||||||
|
alias = aliasing.getAlias(table)
|
||||||
|
}
|
||||||
|
expect(alias).toEqual("aaay")
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue