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