Fix _some_ sqs problems.

This commit is contained in:
Sam Rose 2024-11-27 12:21:27 +00:00
parent f211990117
commit bd17770e4e
No known key found for this signature in database
4 changed files with 21 additions and 21 deletions

View File

@ -3268,7 +3268,7 @@ if (descriptions.length) {
formula: {
name: "formula",
type: FieldType.FORMULA,
formula: formula,
formula,
responseType: opts?.responseType,
formulaType: opts?.formulaType || FormulaType.DYNAMIC,
},
@ -3276,7 +3276,7 @@ if (descriptions.length) {
})
}
it("should be able to search for rows containing formulas", async () => {
it.only("should be able to search for rows containing formulas", async () => {
const { rows } = await config.api.row.search(table._id!)
expect(rows.length).toBe(1)
expect(rows[0].links.length).toBe(1)
@ -3333,7 +3333,7 @@ if (descriptions.length) {
})
isInternal &&
it.only("should coerce a static handlebars formula", async () => {
it("should coerce a static handlebars formula", async () => {
await updateFormulaColumn(encodeJS("return 1"), {
responseType: FieldType.NUMBER,
formulaType: FormulaType.STATIC,

View File

@ -180,19 +180,6 @@ function cleanupFilters(filters: SearchFilters, allTables: Table[]) {
return filters
}
function buildTableMap(tables: Table[]) {
const tableMap: Record<string, Table> = {}
for (let table of tables) {
// update the table name, should never query by name for SQLite
table.originalName = table.name
table.name = table._id!
// need a primary for sorting, lookups etc
table.primary = ["_id"]
tableMap[table._id!] = table
}
return tableMap
}
// table is only needed to handle relationships
function reverseUserColumnMapping(rows: Row[], table?: Table) {
const prefixLength = USER_COLUMN_PREFIX.length
@ -315,7 +302,11 @@ export async function search(
}
const allTables = await sdk.tables.getAllInternalTables()
const allTablesMap = buildTableMap(allTables)
const allTablesMap = allTables.reduce((acc, table) => {
acc[table._id!] = table
return acc
}, {} as Record<string, Table>)
// make sure we have the mapped/latest table
if (table._id) {
table = allTablesMap[table._id]

View File

@ -73,6 +73,17 @@ export function processRowCountResponse(
}
}
function processInternalTables(tables: Table[]) {
const tableMap: Record<string, Table> = {}
for (let table of tables) {
// update the table name, should never query by name for SQLite
table.originalName = table.name
table.name = table._id!
tableMap[table._id!] = table
}
return tableMap
}
export async function enrichQueryJson(
json: QueryJson
): Promise<EnrichedQueryJson> {
@ -85,10 +96,7 @@ export async function enrichQueryJson(
if (datasource) {
tables = datasource.entities || {}
} else {
tables = {}
for (const table of await sdk.tables.getAllInternalTables()) {
tables[table._id!] = table
}
tables = processInternalTables(await sdk.tables.getAllInternalTables())
}
const table = tables[json.endpoint.entityId]

View File

@ -46,6 +46,7 @@ export async function processTable(table: Table): Promise<Table> {
const processed: Table = {
...table,
type: "table",
primary: ["_id"], // internal tables must always use _id as primary key
sourceId: table.sourceId || INTERNAL_TABLE_SOURCE_ID,
sourceType: TableSourceType.INTERNAL,
sql: true,