1
0
Fork 0
mirror of synced 2024-07-06 15:00:49 +12:00

Loop aliasing.

This commit is contained in:
mike12345567 2024-02-26 18:36:34 +00:00
parent 59ab557a93
commit d68fcbf8f7
2 changed files with 18 additions and 1 deletions

View file

@ -32,7 +32,7 @@ export default class AliasTables {
char.substring(0, char.length - 1) +
String.fromCharCode(char.charCodeAt(char.length - 1) + 1)
// 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("")
}
return char

View file

@ -2,6 +2,8 @@ import { QueryJson } from "@budibase/types"
import { join } from "path"
import Sql from "../base/sql"
import { SqlClient } from "../utils"
import AliasTables from "../../api/controllers/row/alias"
import { generator } from "@budibase/backend-core/tests"
function multiline(sql: string) {
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")
})
})
})