Quick fix based on testing.
This commit is contained in:
parent
f73f78c67c
commit
c4f4a46d70
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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`,
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
@ -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`,
|
||||
})
|
||||
})
|
||||
})
|
Loading…
Reference in New Issue