1
0
Fork 0
mirror of synced 2024-09-08 13:41:09 +12:00

Quick fix based on testing.

This commit is contained in:
mike12345567 2024-02-05 12:45:19 +00:00
parent f73f78c67c
commit c4f4a46d70
4 changed files with 31 additions and 19 deletions

View file

@ -113,7 +113,12 @@ export default class AliasTables {
}
json.meta.tables = aliasedTables
}
json.tableAliases = this.tableAliases
// invert and return
const invertedTableAliases: Record<string, string> = {}
for (let [key, value] of Object.entries(this.tableAliases)) {
invertedTableAliases[value] = key
}
json.tableAliases = invertedTableAliases
const response = await getDatasourceAndQuery(json)
return this.reverse(response)
}

View file

@ -499,7 +499,6 @@ class InternalBuilder {
foundLimit = paginate.limit
}
// start building the query
let query = this.knexWithAlias(knex, endpoint, tableAliases)
query = query.limit(foundLimit)
if (foundOffset) {

View file

@ -685,20 +685,3 @@ describe("SQL query builder", () => {
})
})
})
describe("Captures of real examples", () => {
const limit = 5000
function getJson(name: string): QueryJson {
return require(join(__dirname, "sqlQueryJson", name)) as QueryJson
}
it("should handle filtering by relationship", () => {
const queryJson = getJson(`filterByRelationship.json`)
let query = new Sql(SqlClient.POSTGRES, limit)._query(queryJson)
expect(query).toEqual({
bindings: [100, "assembling", limit],
sql: `select "a"."productname" as "a.productname", "a"."productid" as "a.productid", "b"."executorid" as "b.executorid", "b"."taskname" as "b.taskname", "b"."taskid" as "b.taskid", "b"."completed" as "b.completed", "b"."qaid" as "b.qaid" from (select * from "products" as "a" order by "a"."productname" asc limit $1) as "a" left join "products_tasks" as "c" on "a"."productid" = "c"."productid" left join "tasks" as "b" on "b"."taskid" = "c"."taskid" where "b"."taskname" = $2 order by "a"."productname" asc limit $3`,
})
})
})

View file

@ -0,0 +1,25 @@
import { QueryJson } from "@budibase/types"
import { join } from "path"
import Sql from "../base/sql"
import { SqlClient } from "../utils"
describe("Captures of real examples", () => {
const limit = 5000
function getJson(name: string): QueryJson {
return require(join(__dirname, "sqlQueryJson", name)) as QueryJson
}
it("should handle basic retrieval", () => {
const queryJson = getJson("")
})
it("should handle filtering by relationship", () => {
const queryJson = getJson("filterByRelationship.json")
let query = new Sql(SqlClient.POSTGRES, limit)._query(queryJson)
expect(query).toEqual({
bindings: [100, "assembling", limit],
sql: `select "a"."productname" as "a.productname", "a"."productid" as "a.productid", "b"."executorid" as "b.executorid", "b"."taskname" as "b.taskname", "b"."taskid" as "b.taskid", "b"."completed" as "b.completed", "b"."qaid" as "b.qaid" from (select * from "products" as "a" order by "a"."productname" asc limit $1) as "a" left join "products_tasks" as "c" on "a"."productid" = "c"."productid" left join "tasks" as "b" on "b"."taskid" = "c"."taskid" where "b"."taskname" = $2 order by "a"."productname" asc limit $3`,
})
})
})