Clean up params and isSqs

This commit is contained in:
Sam Rose 2024-10-02 09:44:20 +01:00
parent ddd229062c
commit 7b9af81fd5
No known key found for this signature in database
1 changed files with 20 additions and 16 deletions

View File

@ -87,6 +87,13 @@ function convertBooleans(query: SqlQuery | SqlQuery[]): SqlQuery | SqlQuery[] {
return query
}
function isSqs(table: Table): boolean {
return (
table.sourceType === TableSourceType.INTERNAL ||
table.sourceId === INTERNAL_TABLE_SOURCE_ID
)
}
class InternalBuilder {
private readonly client: SqlClient
private readonly query: QueryJson
@ -799,37 +806,34 @@ class InternalBuilder {
return query
}
isSqs(t?: Table): boolean {
const table = t || this.table
return (
table.sourceType === TableSourceType.INTERNAL ||
table.sourceId === INTERNAL_TABLE_SOURCE_ID
)
isSqs(): boolean {
return isSqs(this.table)
}
getTableName(t?: Table | string): string {
getTableName(tableOrName?: Table | string): string {
let table: Table
if (typeof t === "string") {
if (this.query.table?.name === t) {
if (typeof tableOrName === "string") {
const name = tableOrName
if (this.query.table?.name === name) {
table = this.query.table
} else if (this.query.meta.table?.name === t) {
} else if (this.query.meta.table?.name === name) {
table = this.query.meta.table
} else if (!this.query.meta.tables?.[t]) {
} else if (!this.query.meta.tables?.[name]) {
// This can legitimately happen in custom queries, where the user is
// querying against a table that may not have been imported into
// Budibase.
return t
return name
} else {
table = this.query.meta.tables[t]
table = this.query.meta.tables[name]
}
} else if (t) {
table = t
} else if (tableOrName) {
table = tableOrName
} else {
table = this.table
}
let name = table.name
if (this.isSqs(table) && table._id) {
if (isSqs(table) && table._id) {
// SQS uses the table ID rather than the table name
name = table._id
}