@budibase/server 0.9.186 → 0.9.190-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Dockerfile +7 -1
- package/LICENSE +1 -1
- package/__mocks__/mssql.ts +1 -1
- package/__mocks__/oracledb.ts +31 -0
- package/__mocks__/pg.ts +3 -0
- package/builder/assets/bb-space-man.5be51a45.svg +290 -0
- package/builder/assets/index.43f4c913.js +1316 -0
- package/builder/assets/index.7d405e74.css +1 -0
- package/builder/assets/oracle.66592424.png +0 -0
- package/builder/assets/vendor.470042a4.js +152 -0
- package/builder/assets/vendor.5e1fe644.css +1 -0
- package/builder/index.html +4 -4
- package/coverage/clover.xml +1520 -1087
- package/coverage/coverage-final.json +93 -89
- package/coverage/lcov-report/api/controllers/analytics.js.html +2 -2
- package/coverage/lcov-report/api/controllers/apikeys.js.html +2 -2
- package/coverage/lcov-report/api/controllers/application.js.html +64 -13
- package/coverage/lcov-report/api/controllers/auth.js.html +19 -10
- package/coverage/lcov-report/api/controllers/automation.js.html +3 -3
- package/coverage/lcov-report/api/controllers/backup.js.html +1 -1
- package/coverage/lcov-report/api/controllers/cloud.js.html +1 -1
- package/coverage/lcov-report/api/controllers/component.js.html +4 -4
- package/coverage/lcov-report/api/controllers/datasource.js.html +232 -28
- package/coverage/lcov-report/api/controllers/dev.js.html +16 -7
- package/coverage/lcov-report/api/controllers/hosting.js.html +10 -10
- package/coverage/lcov-report/api/controllers/index.html +91 -91
- package/coverage/lcov-report/api/controllers/integration.js.html +1 -1
- package/coverage/lcov-report/api/controllers/layout.js.html +3 -3
- package/coverage/lcov-report/api/controllers/metadata.js.html +3 -3
- package/coverage/lcov-report/api/controllers/permission.js.html +3 -3
- package/coverage/lcov-report/api/controllers/query.js.html +53 -209
- package/coverage/lcov-report/api/controllers/role.js.html +9 -9
- package/coverage/lcov-report/api/controllers/routing.js.html +3 -3
- package/coverage/lcov-report/api/controllers/row/external.js.html +17 -8
- package/coverage/lcov-report/api/controllers/row/index.html +26 -26
- package/coverage/lcov-report/api/controllers/row/index.js.html +2 -2
- package/coverage/lcov-report/api/controllers/row/internal.js.html +9 -9
- package/coverage/lcov-report/api/controllers/row/internalSearch.js.html +2 -2
- package/coverage/lcov-report/api/controllers/row/utils.js.html +21 -30
- package/coverage/lcov-report/api/controllers/screen.js.html +2 -2
- package/coverage/lcov-report/api/controllers/script.js.html +3 -3
- package/coverage/lcov-report/api/controllers/table/external.js.html +1001 -0
- package/coverage/lcov-report/api/controllers/table/index.html +56 -26
- package/coverage/lcov-report/api/controllers/table/index.js.html +80 -350
- package/coverage/lcov-report/api/controllers/table/internal.js.html +545 -0
- package/coverage/lcov-report/api/controllers/table/utils.js.html +175 -52
- package/coverage/lcov-report/api/controllers/templates.js.html +4 -4
- package/coverage/lcov-report/api/controllers/user.js.html +390 -33
- package/coverage/lcov-report/api/controllers/view/exporters.js.html +19 -4
- package/coverage/lcov-report/api/controllers/view/index.html +22 -22
- package/coverage/lcov-report/api/controllers/view/index.js.html +52 -13
- package/coverage/lcov-report/api/controllers/view/utils.js.html +11 -11
- package/coverage/lcov-report/api/controllers/view/viewBuilder.js.html +3 -3
- package/coverage/lcov-report/api/controllers/webhook.js.html +4 -4
- package/coverage/lcov-report/api/index.html +1 -1
- package/coverage/lcov-report/api/index.js.html +1 -1
- package/coverage/lcov-report/api/routes/analytics.js.html +1 -1
- package/coverage/lcov-report/api/routes/apikeys.js.html +1 -1
- package/coverage/lcov-report/api/routes/application.js.html +1 -1
- package/coverage/lcov-report/api/routes/auth.js.html +1 -1
- package/coverage/lcov-report/api/routes/automation.js.html +1 -1
- package/coverage/lcov-report/api/routes/backup.js.html +1 -1
- package/coverage/lcov-report/api/routes/cloud.js.html +1 -1
- package/coverage/lcov-report/api/routes/component.js.html +1 -1
- package/coverage/lcov-report/api/routes/datasource.js.html +1 -1
- package/coverage/lcov-report/api/routes/deploy.js.html +1 -1
- package/coverage/lcov-report/api/routes/dev.js.html +2 -2
- package/coverage/lcov-report/api/routes/hosting.js.html +1 -1
- package/coverage/lcov-report/api/routes/index.html +4 -4
- package/coverage/lcov-report/api/routes/index.js.html +1 -1
- package/coverage/lcov-report/api/routes/integration.js.html +1 -1
- package/coverage/lcov-report/api/routes/layout.js.html +1 -1
- package/coverage/lcov-report/api/routes/metadata.js.html +1 -1
- package/coverage/lcov-report/api/routes/permission.js.html +1 -1
- package/coverage/lcov-report/api/routes/query.js.html +5 -2
- package/coverage/lcov-report/api/routes/role.js.html +1 -1
- package/coverage/lcov-report/api/routes/routing.js.html +1 -1
- package/coverage/lcov-report/api/routes/row.js.html +1 -1
- package/coverage/lcov-report/api/routes/screen.js.html +1 -1
- package/coverage/lcov-report/api/routes/script.js.html +1 -1
- package/coverage/lcov-report/api/routes/static.js.html +2 -2
- package/coverage/lcov-report/api/routes/table.js.html +35 -2
- package/coverage/lcov-report/api/routes/templates.js.html +1 -1
- package/coverage/lcov-report/api/routes/user.js.html +17 -2
- package/coverage/lcov-report/api/routes/view.js.html +1 -1
- package/coverage/lcov-report/api/routes/webhook.js.html +1 -1
- package/coverage/lcov-report/automations/actions.js.html +2 -2
- package/coverage/lcov-report/automations/automationUtils.js.html +4 -4
- package/coverage/lcov-report/automations/bullboard.js.html +71 -20
- package/coverage/lcov-report/automations/index.html +35 -50
- package/coverage/lcov-report/automations/index.js.html +2 -2
- package/coverage/lcov-report/automations/steps/bash.js.html +1 -1
- package/coverage/lcov-report/automations/steps/createRow.js.html +1 -1
- package/coverage/lcov-report/automations/steps/delay.js.html +1 -1
- package/coverage/lcov-report/automations/steps/deleteRow.js.html +1 -1
- package/coverage/lcov-report/automations/steps/discord.js.html +3 -3
- package/coverage/lcov-report/automations/steps/executeQuery.js.html +1 -1
- package/coverage/lcov-report/automations/steps/executeScript.js.html +3 -3
- package/coverage/lcov-report/automations/steps/filter.js.html +1 -1
- package/coverage/lcov-report/automations/steps/index.html +14 -14
- package/coverage/lcov-report/automations/steps/integromat.js.html +1 -1
- package/coverage/lcov-report/automations/steps/outgoingWebhook.js.html +3 -3
- package/coverage/lcov-report/automations/steps/queryRows.js.html +3 -3
- package/coverage/lcov-report/automations/steps/sendSmtpEmail.js.html +1 -1
- package/coverage/lcov-report/automations/steps/serverLog.js.html +1 -1
- package/coverage/lcov-report/automations/steps/slack.js.html +1 -1
- package/coverage/lcov-report/automations/steps/updateRow.js.html +1 -1
- package/coverage/lcov-report/automations/steps/utils.js.html +7 -7
- package/coverage/lcov-report/automations/steps/zapier.js.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/app.js.html +2 -2
- package/coverage/lcov-report/automations/triggerInfo/cron.js.html +2 -2
- package/coverage/lcov-report/automations/triggerInfo/index.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/index.js.html +8 -8
- package/coverage/lcov-report/automations/triggerInfo/rowDeleted.js.html +2 -2
- package/coverage/lcov-report/automations/triggerInfo/rowSaved.js.html +2 -2
- package/coverage/lcov-report/automations/triggerInfo/rowUpdated.js.html +2 -2
- package/coverage/lcov-report/automations/triggerInfo/webhook.js.html +2 -2
- package/coverage/lcov-report/automations/triggers.js.html +22 -10
- package/coverage/lcov-report/automations/utils.js.html +42 -12
- package/coverage/lcov-report/constants/index.html +5 -5
- package/coverage/lcov-report/constants/index.js.html +87 -21
- package/coverage/lcov-report/constants/layouts.js.html +1 -1
- package/coverage/lcov-report/constants/screens.js.html +1 -1
- package/coverage/lcov-report/db/client.js.html +2 -2
- package/coverage/lcov-report/db/inMemoryView.js.html +2 -2
- package/coverage/lcov-report/db/index.html +2 -2
- package/coverage/lcov-report/db/index.js.html +1 -1
- package/coverage/lcov-report/db/linkedRows/LinkController.js.html +6 -6
- package/coverage/lcov-report/db/linkedRows/index.html +10 -10
- package/coverage/lcov-report/db/linkedRows/index.js.html +5 -5
- package/coverage/lcov-report/db/linkedRows/linkUtils.js.html +6 -6
- package/coverage/lcov-report/db/newid.js.html +3 -3
- package/coverage/lcov-report/db/utils.js.html +57 -57
- package/coverage/lcov-report/events/AutomationEmitter.js.html +6 -6
- package/coverage/lcov-report/events/index.html +6 -6
- package/coverage/lcov-report/events/index.js.html +1 -1
- package/coverage/lcov-report/events/utils.js.html +5 -5
- package/coverage/lcov-report/index.html +108 -93
- package/coverage/lcov-report/integrations/tests/TestConfiguration.js.html +1 -1
- package/coverage/lcov-report/integrations/tests/index.html +1 -1
- package/coverage/lcov-report/middleware/appInfo.js.html +2 -2
- package/coverage/lcov-report/middleware/authorized.js.html +58 -34
- package/coverage/lcov-report/middleware/builder.js.html +16 -7
- package/coverage/lcov-report/middleware/currentapp.js.html +6 -6
- package/coverage/lcov-report/middleware/index.html +27 -27
- package/coverage/lcov-report/middleware/joi-validator.js.html +2 -2
- package/coverage/lcov-report/middleware/resourceId.js.html +18 -18
- package/coverage/lcov-report/middleware/selfhost.js.html +2 -2
- package/coverage/lcov-report/middleware/usageQuota.js.html +4 -4
- package/coverage/lcov-report/middleware/utils.js.html +1 -1
- package/coverage/lcov-report/{automations/thread.js.html → threads/automation.js.html} +90 -33
- package/coverage/lcov-report/threads/index.html +141 -0
- package/coverage/lcov-report/threads/index.js.html +278 -0
- package/coverage/lcov-report/threads/query.js.html +278 -0
- package/coverage/lcov-report/utilities/bcrypt.js.html +1 -1
- package/coverage/lcov-report/utilities/budibaseDir.js.html +1 -1
- package/coverage/lcov-report/utilities/centralPath.js.html +1 -1
- package/coverage/lcov-report/utilities/csvParser.js.html +144 -15
- package/coverage/lcov-report/utilities/global.js.html +26 -11
- package/coverage/lcov-report/utilities/index.html +48 -48
- package/coverage/lcov-report/utilities/index.js.html +47 -14
- package/coverage/lcov-report/utilities/queue/inMemoryQueue.js.html +30 -9
- package/coverage/lcov-report/utilities/queue/index.html +14 -14
- package/coverage/lcov-report/utilities/routing/index.html +1 -1
- package/coverage/lcov-report/utilities/routing/index.js.html +1 -1
- package/coverage/lcov-report/utilities/rowProcessor/index.html +4 -4
- package/coverage/lcov-report/utilities/rowProcessor/index.js.html +2 -2
- package/coverage/lcov-report/utilities/rowProcessor/utils.js.html +3 -3
- package/coverage/lcov-report/utilities/scriptRunner.js.html +16 -7
- package/coverage/lcov-report/utilities/security.js.html +3 -3
- package/coverage/lcov-report/utilities/statusCodes.js.html +1 -1
- package/coverage/lcov-report/utilities/users.js.html +1 -1
- package/coverage/lcov-report/utilities/workerRequests.js.html +5 -5
- package/coverage/lcov.info +2558 -1787
- package/dist/api/controllers/application.js +15 -1
- package/dist/api/controllers/auth.js +3 -3
- package/dist/api/controllers/datasource.js +67 -16
- package/dist/api/controllers/deploy/index.js +2 -0
- package/dist/api/controllers/dev.js +4 -1
- package/dist/api/controllers/query.js +30 -58
- package/dist/api/controllers/row/ExternalRequest.js +37 -14
- package/dist/api/controllers/row/external.js +3 -1
- package/dist/api/controllers/row/utils.js +6 -12
- package/dist/api/controllers/table/external.js +249 -0
- package/dist/api/controllers/table/index.js +49 -123
- package/dist/api/controllers/table/internal.js +150 -0
- package/dist/api/controllers/table/utils.js +62 -28
- package/dist/api/controllers/user.js +123 -11
- package/dist/api/controllers/view/exporters.js +4 -0
- package/dist/api/controllers/view/index.js +14 -2
- package/dist/api/routes/query.js +1 -1
- package/dist/api/routes/table.js +7 -1
- package/dist/api/routes/user.js +2 -1
- package/dist/app.js +2 -11
- package/dist/automations/bullboard.js +37 -10
- package/dist/automations/triggers.js +7 -3
- package/dist/automations/utils.js +11 -2
- package/dist/constants/index.js +19 -0
- package/dist/definitions/datasource.js +5 -0
- package/dist/environment.js +13 -0
- package/dist/integrations/base/IntegrationBase.js +2 -0
- package/dist/integrations/base/datasourcePlus.js +2 -0
- package/dist/integrations/base/sql.js +338 -180
- package/dist/integrations/base/sqlTable.js +143 -0
- package/dist/integrations/base/utils.js +30 -0
- package/dist/integrations/index.js +6 -0
- package/dist/integrations/microsoftSqlServer.js +117 -9
- package/dist/integrations/mysql.js +14 -84
- package/dist/integrations/oracle.js +345 -0
- package/dist/integrations/postgres.js +35 -28
- package/dist/integrations/utils.js +71 -9
- package/dist/middleware/authorized.js +22 -11
- package/dist/middleware/builder.js +4 -1
- package/dist/package.json +13 -8
- package/dist/tests/utilities/TestConfiguration.js +2 -1
- package/dist/{automations/thread.js → threads/automation.js} +26 -8
- package/dist/threads/index.js +64 -0
- package/dist/threads/query.js +64 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/utilities/csvParser.js +46 -5
- package/dist/utilities/global.js +6 -2
- package/dist/utilities/index.js +11 -0
- package/dist/utilities/queue/inMemoryQueue.js +8 -0
- package/dist/utilities/scriptRunner.js +4 -1
- package/package.json +14 -9
- package/scripts/dev/manage.js +1 -0
- package/scripts/integrations/mssql/data/Dockerfile +9 -0
- package/scripts/integrations/mssql/data/entrypoint.sh +24 -0
- package/scripts/integrations/mssql/data/setup.sql +54 -0
- package/scripts/integrations/mssql/docker-compose.yaml +12 -0
- package/scripts/integrations/mssql/reset.sh +3 -0
- package/scripts/integrations/oracle/docker-compose.yml +19 -0
- package/scripts/integrations/oracle/instantclient/linux/x86-64/basiclite-21.4.zip +0 -0
- package/scripts/integrations/oracle/instantclient/linux/x86-64/install.sh +23 -0
- package/scripts/integrations/oracle/oracle.md +90 -0
- package/scripts/integrations/postgres/docker-compose.yml +3 -3
- package/scripts/likeCypress.ts +33 -0
- package/src/api/controllers/application.js +18 -1
- package/src/api/controllers/auth.js +3 -0
- package/src/api/controllers/datasource.js +84 -16
- package/src/api/controllers/deploy/index.js +2 -0
- package/src/api/controllers/dev.js +4 -1
- package/src/api/controllers/query.js +29 -81
- package/src/api/controllers/row/ExternalRequest.ts +47 -16
- package/src/api/controllers/row/external.js +4 -1
- package/src/api/controllers/row/utils.js +8 -11
- package/src/api/controllers/table/external.js +307 -0
- package/src/api/controllers/table/index.js +47 -137
- package/src/api/controllers/table/internal.js +155 -0
- package/src/api/controllers/table/utils.js +74 -33
- package/src/api/controllers/user.js +132 -13
- package/src/api/controllers/view/exporters.js +5 -0
- package/src/api/controllers/view/index.js +15 -2
- package/src/api/routes/query.js +1 -0
- package/src/api/routes/table.js +11 -0
- package/src/api/routes/tests/datasource.spec.js +2 -2
- package/src/api/routes/tests/misc.spec.js +5 -1
- package/src/api/routes/tests/query.spec.js +0 -1
- package/src/api/routes/user.js +5 -0
- package/src/app.ts +2 -10
- package/src/automations/bullboard.js +28 -11
- package/src/automations/tests/automation.spec.js +3 -4
- package/src/automations/triggers.js +7 -3
- package/src/automations/utils.js +12 -2
- package/src/constants/index.js +22 -0
- package/src/definitions/common.ts +7 -1
- package/src/definitions/datasource.ts +10 -3
- package/src/environment.js +15 -0
- package/src/integrations/airtable.ts +2 -1
- package/src/integrations/arangodb.ts +2 -1
- package/src/integrations/base/IntegrationBase.ts +6 -0
- package/src/integrations/base/datasourcePlus.ts +9 -0
- package/src/integrations/base/sql.ts +362 -222
- package/src/integrations/base/sqlTable.ts +180 -0
- package/src/integrations/base/utils.ts +22 -0
- package/src/integrations/couchdb.ts +2 -1
- package/src/integrations/dynamodb.ts +2 -1
- package/src/integrations/elasticsearch.ts +2 -1
- package/src/integrations/index.ts +7 -0
- package/src/integrations/microsoftSqlServer.ts +145 -13
- package/src/integrations/mongodb.ts +2 -1
- package/src/integrations/mysql.ts +20 -94
- package/src/integrations/oracle.ts +445 -0
- package/src/integrations/postgres.ts +45 -35
- package/src/integrations/rest.ts +2 -1
- package/src/integrations/s3.ts +2 -1
- package/src/integrations/tests/microsoftSqlServer.spec.js +22 -15
- package/src/integrations/tests/oracle.spec.js +94 -0
- package/src/integrations/tests/postgres.spec.js +4 -0
- package/src/integrations/utils.ts +74 -8
- package/src/middleware/authorized.js +26 -18
- package/src/middleware/builder.js +4 -1
- package/src/middleware/tests/authorized.spec.js +2 -0
- package/src/tests/utilities/TestConfiguration.js +2 -1
- package/src/{automations/thread.js → threads/automation.js} +27 -8
- package/src/threads/index.js +66 -0
- package/src/threads/query.js +66 -0
- package/src/utilities/csvParser.js +48 -5
- package/src/utilities/global.js +7 -2
- package/src/utilities/index.js +11 -0
- package/src/utilities/queue/inMemoryQueue.js +7 -0
- package/src/utilities/scriptRunner.js +4 -1
- package/src/utilities/tests/__snapshots__/csvParser.spec.js.snap +0 -6
- package/src/utilities/tests/csvParser.spec.js +3 -0
- package/tsconfig.json +1 -1
- package/builder/assets/index.10556cc1.js +0 -201
- package/builder/assets/index.7469e1e4.css +0 -29
- package/builder/assets/vendor.278a305c.js +0 -9
- package/builder/assets/vendor.d75d5eb7.css +0 -1
|
@@ -1,265 +1,314 @@
|
|
|
1
1
|
import { Knex, knex } from "knex"
|
|
2
|
-
const BASE_LIMIT = 5000
|
|
3
2
|
import {
|
|
3
|
+
Operation,
|
|
4
4
|
QueryJson,
|
|
5
|
-
SearchFilters,
|
|
6
5
|
QueryOptions,
|
|
7
|
-
SortDirection,
|
|
8
|
-
Operation,
|
|
9
6
|
RelationshipsJson,
|
|
7
|
+
SearchFilters,
|
|
8
|
+
SortDirection,
|
|
10
9
|
} from "../../definitions/datasource"
|
|
11
|
-
import { isIsoDateString } from "../utils"
|
|
10
|
+
import { isIsoDateString, SqlClients } from "../utils"
|
|
11
|
+
import SqlTableQueryBuilder from "./sqlTable"
|
|
12
|
+
|
|
13
|
+
const BASE_LIMIT = 5000
|
|
12
14
|
|
|
13
15
|
type KnexQuery = Knex.QueryBuilder | Knex
|
|
16
|
+
// these are invalid dates sent by the client, need to convert them to a real max date
|
|
17
|
+
const MIN_ISO_DATE = "0000-00-00T00:00:00.000Z"
|
|
18
|
+
const MAX_ISO_DATE = "9999-00-00T00:00:00.000Z"
|
|
19
|
+
|
|
20
|
+
function parse(input: any) {
|
|
21
|
+
if (Array.isArray(input)) {
|
|
22
|
+
return JSON.stringify(input)
|
|
23
|
+
}
|
|
24
|
+
if (typeof input !== "string") {
|
|
25
|
+
return input
|
|
26
|
+
}
|
|
27
|
+
if (input === MAX_ISO_DATE) {
|
|
28
|
+
return new Date(8640000000000000)
|
|
29
|
+
}
|
|
30
|
+
if (input === MIN_ISO_DATE) {
|
|
31
|
+
return new Date(-8640000000000000)
|
|
32
|
+
}
|
|
33
|
+
if (isIsoDateString(input)) {
|
|
34
|
+
return new Date(input)
|
|
35
|
+
}
|
|
36
|
+
return input
|
|
37
|
+
}
|
|
14
38
|
|
|
15
39
|
function parseBody(body: any) {
|
|
16
40
|
for (let [key, value] of Object.entries(body)) {
|
|
17
|
-
|
|
18
|
-
continue
|
|
19
|
-
}
|
|
20
|
-
if (isIsoDateString(value)) {
|
|
21
|
-
body[key] = new Date(value)
|
|
22
|
-
}
|
|
41
|
+
body[key] = parse(value)
|
|
23
42
|
}
|
|
24
43
|
return body
|
|
25
44
|
}
|
|
26
45
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
structure: { [key: string]: any },
|
|
35
|
-
fn: (key: string, value: any) => void
|
|
36
|
-
) {
|
|
37
|
-
for (let [key, value] of Object.entries(structure)) {
|
|
38
|
-
fn(`${tableName}.${key}`, value)
|
|
46
|
+
function parseFilters(filters: SearchFilters): SearchFilters {
|
|
47
|
+
for (let [key, value] of Object.entries(filters)) {
|
|
48
|
+
let parsed
|
|
49
|
+
if (typeof value === "object") {
|
|
50
|
+
parsed = parseFilters(value)
|
|
51
|
+
} else {
|
|
52
|
+
parsed = parse(value)
|
|
39
53
|
}
|
|
54
|
+
// @ts-ignore
|
|
55
|
+
filters[key] = parsed
|
|
40
56
|
}
|
|
41
|
-
|
|
42
|
-
return query
|
|
43
|
-
}
|
|
44
|
-
// if all or specified in filters, then everything is an or
|
|
45
|
-
const allOr = filters.allOr
|
|
46
|
-
if (filters.oneOf) {
|
|
47
|
-
iterate(filters.oneOf, (key, array) => {
|
|
48
|
-
const fnc = allOr ? "orWhereIn" : "whereIn"
|
|
49
|
-
query = query[fnc](key, array)
|
|
50
|
-
})
|
|
51
|
-
}
|
|
52
|
-
if (filters.string) {
|
|
53
|
-
iterate(filters.string, (key, value) => {
|
|
54
|
-
const fnc = allOr ? "orWhere" : "where"
|
|
55
|
-
query = query[fnc](key, "ilike", `${value}%`)
|
|
56
|
-
})
|
|
57
|
-
}
|
|
58
|
-
if (filters.fuzzy) {
|
|
59
|
-
iterate(filters.fuzzy, (key, value) => {
|
|
60
|
-
const fnc = allOr ? "orWhere" : "where"
|
|
61
|
-
query = query[fnc](key, "ilike", `%${value}%`)
|
|
62
|
-
})
|
|
63
|
-
}
|
|
64
|
-
if (filters.range) {
|
|
65
|
-
iterate(filters.range, (key, value) => {
|
|
66
|
-
if (!value.high || !value.low) {
|
|
67
|
-
return
|
|
68
|
-
}
|
|
69
|
-
const fnc = allOr ? "orWhereBetween" : "whereBetween"
|
|
70
|
-
query = query[fnc](key, [value.low, value.high])
|
|
71
|
-
})
|
|
72
|
-
}
|
|
73
|
-
if (filters.equal) {
|
|
74
|
-
iterate(filters.equal, (key, value) => {
|
|
75
|
-
const fnc = allOr ? "orWhere" : "where"
|
|
76
|
-
query = query[fnc]({ [key]: value })
|
|
77
|
-
})
|
|
78
|
-
}
|
|
79
|
-
if (filters.notEqual) {
|
|
80
|
-
iterate(filters.notEqual, (key, value) => {
|
|
81
|
-
const fnc = allOr ? "orWhereNot" : "whereNot"
|
|
82
|
-
query = query[fnc]({ [key]: value })
|
|
83
|
-
})
|
|
84
|
-
}
|
|
85
|
-
if (filters.empty) {
|
|
86
|
-
iterate(filters.empty, key => {
|
|
87
|
-
const fnc = allOr ? "orWhereNull" : "whereNull"
|
|
88
|
-
query = query[fnc](key)
|
|
89
|
-
})
|
|
90
|
-
}
|
|
91
|
-
if (filters.notEmpty) {
|
|
92
|
-
iterate(filters.notEmpty, key => {
|
|
93
|
-
const fnc = allOr ? "orWhereNotNull" : "whereNotNull"
|
|
94
|
-
query = query[fnc](key)
|
|
95
|
-
})
|
|
96
|
-
}
|
|
97
|
-
return query
|
|
57
|
+
return filters
|
|
98
58
|
}
|
|
99
59
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
60
|
+
class InternalBuilder {
|
|
61
|
+
private readonly client: string
|
|
62
|
+
|
|
63
|
+
constructor(client: string) {
|
|
64
|
+
this.client = client
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// right now we only do filters on the specific table being queried
|
|
68
|
+
addFilters(
|
|
69
|
+
tableName: string,
|
|
70
|
+
query: KnexQuery,
|
|
71
|
+
filters: SearchFilters | undefined
|
|
72
|
+
): KnexQuery {
|
|
73
|
+
function iterate(
|
|
74
|
+
structure: { [key: string]: any },
|
|
75
|
+
fn: (key: string, value: any) => void
|
|
76
|
+
) {
|
|
77
|
+
for (let [key, value] of Object.entries(structure)) {
|
|
78
|
+
fn(`${tableName}.${key}`, value)
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
if (!filters) {
|
|
82
|
+
return query
|
|
83
|
+
}
|
|
84
|
+
filters = parseFilters(filters)
|
|
85
|
+
// if all or specified in filters, then everything is an or
|
|
86
|
+
const allOr = filters.allOr
|
|
87
|
+
if (filters.oneOf) {
|
|
88
|
+
iterate(filters.oneOf, (key, array) => {
|
|
89
|
+
const fnc = allOr ? "orWhereIn" : "whereIn"
|
|
90
|
+
query = query[fnc](key, array)
|
|
91
|
+
})
|
|
92
|
+
}
|
|
93
|
+
if (filters.string) {
|
|
94
|
+
iterate(filters.string, (key, value) => {
|
|
95
|
+
const fnc = allOr ? "orWhere" : "where"
|
|
96
|
+
// postgres supports ilike, nothing else does
|
|
97
|
+
if (this.client === SqlClients.POSTGRES) {
|
|
98
|
+
query = query[fnc](key, "ilike", `${value}%`)
|
|
99
|
+
} else {
|
|
100
|
+
const rawFnc = `${fnc}Raw`
|
|
101
|
+
// @ts-ignore
|
|
102
|
+
query = query[rawFnc](`LOWER(${key}) LIKE ?`, [`${value}%`])
|
|
103
|
+
}
|
|
104
|
+
})
|
|
105
|
+
}
|
|
106
|
+
if (filters.fuzzy) {
|
|
107
|
+
iterate(filters.fuzzy, (key, value) => {
|
|
108
|
+
const fnc = allOr ? "orWhere" : "where"
|
|
109
|
+
// postgres supports ilike, nothing else does
|
|
110
|
+
if (this.client === SqlClients.POSTGRES) {
|
|
111
|
+
query = query[fnc](key, "ilike", `%${value}%`)
|
|
112
|
+
} else {
|
|
113
|
+
const rawFnc = `${fnc}Raw`
|
|
114
|
+
// @ts-ignore
|
|
115
|
+
query = query[rawFnc](`LOWER(${key}) LIKE ?`, [`%${value}%`])
|
|
116
|
+
}
|
|
117
|
+
})
|
|
118
|
+
}
|
|
119
|
+
if (filters.range) {
|
|
120
|
+
iterate(filters.range, (key, value) => {
|
|
121
|
+
if (!value.high || !value.low) {
|
|
122
|
+
return
|
|
123
|
+
}
|
|
124
|
+
const fnc = allOr ? "orWhereBetween" : "whereBetween"
|
|
125
|
+
query = query[fnc](key, [value.low, value.high])
|
|
126
|
+
})
|
|
127
|
+
}
|
|
128
|
+
if (filters.equal) {
|
|
129
|
+
iterate(filters.equal, (key, value) => {
|
|
130
|
+
const fnc = allOr ? "orWhere" : "where"
|
|
131
|
+
query = query[fnc]({ [key]: value })
|
|
132
|
+
})
|
|
133
|
+
}
|
|
134
|
+
if (filters.notEqual) {
|
|
135
|
+
iterate(filters.notEqual, (key, value) => {
|
|
136
|
+
const fnc = allOr ? "orWhereNot" : "whereNot"
|
|
137
|
+
query = query[fnc]({ [key]: value })
|
|
138
|
+
})
|
|
139
|
+
}
|
|
140
|
+
if (filters.empty) {
|
|
141
|
+
iterate(filters.empty, key => {
|
|
142
|
+
const fnc = allOr ? "orWhereNull" : "whereNull"
|
|
143
|
+
query = query[fnc](key)
|
|
144
|
+
})
|
|
145
|
+
}
|
|
146
|
+
if (filters.notEmpty) {
|
|
147
|
+
iterate(filters.notEmpty, key => {
|
|
148
|
+
const fnc = allOr ? "orWhereNotNull" : "whereNotNull"
|
|
149
|
+
query = query[fnc](key)
|
|
150
|
+
})
|
|
151
|
+
}
|
|
108
152
|
return query
|
|
109
153
|
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
const
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
154
|
+
|
|
155
|
+
addRelationships(
|
|
156
|
+
knex: Knex,
|
|
157
|
+
query: KnexQuery,
|
|
158
|
+
fields: string | string[],
|
|
159
|
+
fromTable: string,
|
|
160
|
+
relationships: RelationshipsJson[] | undefined
|
|
161
|
+
): KnexQuery {
|
|
162
|
+
if (!relationships) {
|
|
163
|
+
return query
|
|
164
|
+
}
|
|
165
|
+
for (let relationship of relationships) {
|
|
166
|
+
const from = relationship.from,
|
|
167
|
+
to = relationship.to,
|
|
168
|
+
toTable = relationship.tableName
|
|
169
|
+
if (!relationship.through) {
|
|
126
170
|
// @ts-ignore
|
|
127
|
-
.leftJoin(
|
|
128
|
-
|
|
129
|
-
`${fromTable}.${
|
|
130
|
-
`${
|
|
171
|
+
query = query.leftJoin(
|
|
172
|
+
toTable,
|
|
173
|
+
`${fromTable}.${from}`,
|
|
174
|
+
`${toTable}.${to}`
|
|
131
175
|
)
|
|
132
|
-
|
|
176
|
+
} else {
|
|
177
|
+
const throughTable = relationship.through
|
|
178
|
+
const fromPrimary = relationship.fromPrimary
|
|
179
|
+
const toPrimary = relationship.toPrimary
|
|
180
|
+
query = query
|
|
181
|
+
// @ts-ignore
|
|
182
|
+
.leftJoin(
|
|
183
|
+
throughTable,
|
|
184
|
+
`${fromTable}.${fromPrimary}`,
|
|
185
|
+
`${throughTable}.${from}`
|
|
186
|
+
)
|
|
187
|
+
.leftJoin(toTable, `${toTable}.${toPrimary}`, `${throughTable}.${to}`)
|
|
188
|
+
}
|
|
133
189
|
}
|
|
190
|
+
return query.limit(BASE_LIMIT)
|
|
134
191
|
}
|
|
135
|
-
return query.limit(BASE_LIMIT)
|
|
136
|
-
}
|
|
137
192
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
193
|
+
create(knex: Knex, json: QueryJson, opts: QueryOptions): KnexQuery {
|
|
194
|
+
const { endpoint, body } = json
|
|
195
|
+
let query: KnexQuery = knex(endpoint.entityId)
|
|
196
|
+
const parsedBody = parseBody(body)
|
|
197
|
+
// make sure no null values in body for creation
|
|
198
|
+
for (let [key, value] of Object.entries(parsedBody)) {
|
|
199
|
+
if (value == null) {
|
|
200
|
+
delete parsedBody[key]
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
// mysql can't use returning
|
|
204
|
+
if (opts.disableReturning) {
|
|
205
|
+
return query.insert(parsedBody)
|
|
206
|
+
} else {
|
|
207
|
+
return query.insert(parsedBody).returning("*")
|
|
150
208
|
}
|
|
151
209
|
}
|
|
152
|
-
|
|
153
|
-
|
|
210
|
+
|
|
211
|
+
bulkCreate(knex: Knex, json: QueryJson): KnexQuery {
|
|
212
|
+
const { endpoint, body } = json
|
|
213
|
+
let query: KnexQuery = knex(endpoint.entityId)
|
|
214
|
+
if (!Array.isArray(body)) {
|
|
215
|
+
return query
|
|
216
|
+
}
|
|
217
|
+
const parsedBody = body.map(row => parseBody(row))
|
|
154
218
|
return query.insert(parsedBody)
|
|
155
|
-
} else {
|
|
156
|
-
return query.insert(parsedBody).returning("*")
|
|
157
219
|
}
|
|
158
|
-
}
|
|
159
220
|
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
}
|
|
167
|
-
let selectStatement: string | string[] = "*"
|
|
168
|
-
// handle select
|
|
169
|
-
if (resource.fields && resource.fields.length > 0) {
|
|
170
|
-
// select the resources as the format "table.columnName" - this is what is provided
|
|
171
|
-
// by the resource builder further up
|
|
172
|
-
selectStatement = resource.fields.map(field => `${field} as ${field}`)
|
|
173
|
-
}
|
|
174
|
-
let foundLimit = limit || BASE_LIMIT
|
|
175
|
-
// handle pagination
|
|
176
|
-
let foundOffset: number | null = null
|
|
177
|
-
if (paginate && paginate.page && paginate.limit) {
|
|
178
|
-
// @ts-ignore
|
|
179
|
-
const page = paginate.page <= 1 ? 0 : paginate.page - 1
|
|
180
|
-
const offset = page * paginate.limit
|
|
181
|
-
foundLimit = paginate.limit
|
|
182
|
-
foundOffset = offset
|
|
183
|
-
} else if (paginate && paginate.limit) {
|
|
184
|
-
foundLimit = paginate.limit
|
|
185
|
-
}
|
|
186
|
-
// start building the query
|
|
187
|
-
let query: KnexQuery = knex(tableName).limit(foundLimit)
|
|
188
|
-
if (foundOffset) {
|
|
189
|
-
query = query.offset(foundOffset)
|
|
190
|
-
}
|
|
191
|
-
if (sort) {
|
|
192
|
-
for (let [key, value] of Object.entries(sort)) {
|
|
193
|
-
const direction = value === SortDirection.ASCENDING ? "asc" : "desc"
|
|
194
|
-
query = query.orderBy(key, direction)
|
|
221
|
+
read(knex: Knex, json: QueryJson, limit: number): KnexQuery {
|
|
222
|
+
let { endpoint, resource, filters, sort, paginate, relationships } = json
|
|
223
|
+
const tableName = endpoint.entityId
|
|
224
|
+
// select all if not specified
|
|
225
|
+
if (!resource) {
|
|
226
|
+
resource = { fields: [] }
|
|
195
227
|
}
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
228
|
+
let selectStatement: string | string[] = "*"
|
|
229
|
+
// handle select
|
|
230
|
+
if (resource.fields && resource.fields.length > 0) {
|
|
231
|
+
// select the resources as the format "table.columnName" - this is what is provided
|
|
232
|
+
// by the resource builder further up
|
|
233
|
+
selectStatement = resource.fields.map(field => `${field} as ${field}`)
|
|
234
|
+
}
|
|
235
|
+
let foundLimit = limit || BASE_LIMIT
|
|
236
|
+
// handle pagination
|
|
237
|
+
let foundOffset: number | null = null
|
|
238
|
+
if (paginate && paginate.page && paginate.limit) {
|
|
239
|
+
// @ts-ignore
|
|
240
|
+
const page = paginate.page <= 1 ? 0 : paginate.page - 1
|
|
241
|
+
const offset = page * paginate.limit
|
|
242
|
+
foundLimit = paginate.limit
|
|
243
|
+
foundOffset = offset
|
|
244
|
+
} else if (paginate && paginate.limit) {
|
|
245
|
+
foundLimit = paginate.limit
|
|
246
|
+
}
|
|
247
|
+
// start building the query
|
|
248
|
+
let query: KnexQuery = knex(tableName).limit(foundLimit)
|
|
249
|
+
if (foundOffset) {
|
|
250
|
+
query = query.offset(foundOffset)
|
|
251
|
+
}
|
|
252
|
+
if (sort) {
|
|
253
|
+
for (let [key, value] of Object.entries(sort)) {
|
|
254
|
+
const direction = value === SortDirection.ASCENDING ? "asc" : "desc"
|
|
255
|
+
query = query.orderBy(key, direction)
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
if (this.client === SqlClients.MS_SQL && !sort && paginate?.limit) {
|
|
259
|
+
// @ts-ignore
|
|
260
|
+
query = query.orderBy(json.meta?.table?.primary[0])
|
|
261
|
+
}
|
|
262
|
+
query = this.addFilters(tableName, query, filters)
|
|
200
263
|
// @ts-ignore
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
264
|
+
let preQuery: KnexQuery = knex({
|
|
265
|
+
// @ts-ignore
|
|
266
|
+
[tableName]: query,
|
|
267
|
+
}).select(selectStatement)
|
|
268
|
+
// handle joins
|
|
269
|
+
return this.addRelationships(
|
|
270
|
+
knex,
|
|
271
|
+
preQuery,
|
|
272
|
+
selectStatement,
|
|
273
|
+
tableName,
|
|
274
|
+
relationships
|
|
275
|
+
)
|
|
276
|
+
}
|
|
212
277
|
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
return query.update(parsedBody)
|
|
225
|
-
} else {
|
|
226
|
-
return query.update(parsedBody).returning("*")
|
|
278
|
+
update(knex: Knex, json: QueryJson, opts: QueryOptions): KnexQuery {
|
|
279
|
+
const { endpoint, body, filters } = json
|
|
280
|
+
let query: KnexQuery = knex(endpoint.entityId)
|
|
281
|
+
const parsedBody = parseBody(body)
|
|
282
|
+
query = this.addFilters(endpoint.entityId, query, filters)
|
|
283
|
+
// mysql can't use returning
|
|
284
|
+
if (opts.disableReturning) {
|
|
285
|
+
return query.update(parsedBody)
|
|
286
|
+
} else {
|
|
287
|
+
return query.update(parsedBody).returning("*")
|
|
288
|
+
}
|
|
227
289
|
}
|
|
228
|
-
}
|
|
229
290
|
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
return query.delete()
|
|
241
|
-
} else {
|
|
242
|
-
return query.delete().returning("*")
|
|
291
|
+
delete(knex: Knex, json: QueryJson, opts: QueryOptions): KnexQuery {
|
|
292
|
+
const { endpoint, filters } = json
|
|
293
|
+
let query: KnexQuery = knex(endpoint.entityId)
|
|
294
|
+
query = this.addFilters(endpoint.entityId, query, filters)
|
|
295
|
+
// mysql can't use returning
|
|
296
|
+
if (opts.disableReturning) {
|
|
297
|
+
return query.delete()
|
|
298
|
+
} else {
|
|
299
|
+
return query.delete().returning("*")
|
|
300
|
+
}
|
|
243
301
|
}
|
|
244
302
|
}
|
|
245
303
|
|
|
246
|
-
class SqlQueryBuilder {
|
|
247
|
-
private readonly sqlClient: string
|
|
304
|
+
class SqlQueryBuilder extends SqlTableQueryBuilder {
|
|
248
305
|
private readonly limit: number
|
|
249
306
|
// pass through client to get flavour of SQL
|
|
250
307
|
constructor(client: string, limit: number = BASE_LIMIT) {
|
|
251
|
-
|
|
308
|
+
super(client)
|
|
252
309
|
this.limit = limit
|
|
253
310
|
}
|
|
254
311
|
|
|
255
|
-
/**
|
|
256
|
-
* @param json the input JSON structure from which an SQL query will be built.
|
|
257
|
-
* @return {string} the operation that was found in the JSON.
|
|
258
|
-
*/
|
|
259
|
-
_operation(json: QueryJson): Operation {
|
|
260
|
-
return json.endpoint.operation
|
|
261
|
-
}
|
|
262
|
-
|
|
263
312
|
/**
|
|
264
313
|
* @param json The JSON query DSL which is to be converted to SQL.
|
|
265
314
|
* @param opts extra options which are to be passed into the query builder, e.g. disableReturning
|
|
@@ -267,21 +316,30 @@ class SqlQueryBuilder {
|
|
|
267
316
|
* @return {{ sql: string, bindings: object }} the query ready to be passed to the driver.
|
|
268
317
|
*/
|
|
269
318
|
_query(json: QueryJson, opts: QueryOptions = {}) {
|
|
270
|
-
const
|
|
319
|
+
const sqlClient = this.getSqlClient()
|
|
320
|
+
const client = knex({ client: sqlClient })
|
|
271
321
|
let query
|
|
322
|
+
const builder = new InternalBuilder(sqlClient)
|
|
272
323
|
switch (this._operation(json)) {
|
|
273
324
|
case Operation.CREATE:
|
|
274
|
-
query =
|
|
325
|
+
query = builder.create(client, json, opts)
|
|
275
326
|
break
|
|
276
327
|
case Operation.READ:
|
|
277
|
-
query =
|
|
328
|
+
query = builder.read(client, json, this.limit)
|
|
278
329
|
break
|
|
279
330
|
case Operation.UPDATE:
|
|
280
|
-
query =
|
|
331
|
+
query = builder.update(client, json, opts)
|
|
281
332
|
break
|
|
282
333
|
case Operation.DELETE:
|
|
283
|
-
query =
|
|
334
|
+
query = builder.delete(client, json, opts)
|
|
284
335
|
break
|
|
336
|
+
case Operation.BULK_CREATE:
|
|
337
|
+
query = builder.bulkCreate(client, json)
|
|
338
|
+
break
|
|
339
|
+
case Operation.CREATE_TABLE:
|
|
340
|
+
case Operation.UPDATE_TABLE:
|
|
341
|
+
case Operation.DELETE_TABLE:
|
|
342
|
+
return this._tableQuery(json)
|
|
285
343
|
default:
|
|
286
344
|
throw `Operation type is not supported by SQL query builder`
|
|
287
345
|
}
|
|
@@ -289,6 +347,88 @@ class SqlQueryBuilder {
|
|
|
289
347
|
// @ts-ignore
|
|
290
348
|
return query.toSQL().toNative()
|
|
291
349
|
}
|
|
350
|
+
|
|
351
|
+
async getReturningRow(queryFn: Function, json: QueryJson) {
|
|
352
|
+
if (!json.extra || !json.extra.idFilter) {
|
|
353
|
+
return {}
|
|
354
|
+
}
|
|
355
|
+
const input = this._query({
|
|
356
|
+
endpoint: {
|
|
357
|
+
...json.endpoint,
|
|
358
|
+
operation: Operation.READ,
|
|
359
|
+
},
|
|
360
|
+
resource: {
|
|
361
|
+
fields: [],
|
|
362
|
+
},
|
|
363
|
+
filters: json.extra.idFilter,
|
|
364
|
+
paginate: {
|
|
365
|
+
limit: 1,
|
|
366
|
+
},
|
|
367
|
+
meta: json.meta,
|
|
368
|
+
})
|
|
369
|
+
return queryFn(input, Operation.READ)
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
// when creating if an ID has been inserted need to make sure
|
|
373
|
+
// the id filter is enriched with it before trying to retrieve the row
|
|
374
|
+
checkLookupKeys(id: any, json: QueryJson) {
|
|
375
|
+
if (!id || !json.meta?.table || !json.meta.table.primary) {
|
|
376
|
+
return json
|
|
377
|
+
}
|
|
378
|
+
const primaryKey = json.meta.table.primary?.[0]
|
|
379
|
+
json.extra = {
|
|
380
|
+
idFilter: {
|
|
381
|
+
equal: {
|
|
382
|
+
[primaryKey]: id,
|
|
383
|
+
},
|
|
384
|
+
},
|
|
385
|
+
}
|
|
386
|
+
return json
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
// this function recreates the returning functionality of postgres
|
|
390
|
+
async queryWithReturning(
|
|
391
|
+
json: QueryJson,
|
|
392
|
+
queryFn: Function,
|
|
393
|
+
processFn: Function = (result: any) => result
|
|
394
|
+
) {
|
|
395
|
+
const sqlClient = this.getSqlClient()
|
|
396
|
+
const operation = this._operation(json)
|
|
397
|
+
const input = this._query(json, { disableReturning: true })
|
|
398
|
+
if (Array.isArray(input)) {
|
|
399
|
+
const responses = []
|
|
400
|
+
for (let query of input) {
|
|
401
|
+
responses.push(await queryFn(query, operation))
|
|
402
|
+
}
|
|
403
|
+
return responses
|
|
404
|
+
}
|
|
405
|
+
let row
|
|
406
|
+
// need to manage returning, a feature mySQL can't do
|
|
407
|
+
if (operation === Operation.DELETE) {
|
|
408
|
+
row = processFn(await this.getReturningRow(queryFn, json))
|
|
409
|
+
}
|
|
410
|
+
const response = await queryFn(input, operation)
|
|
411
|
+
const results = processFn(response)
|
|
412
|
+
// same as delete, manage returning
|
|
413
|
+
if (operation === Operation.CREATE || operation === Operation.UPDATE) {
|
|
414
|
+
let id
|
|
415
|
+
if (sqlClient === SqlClients.MS_SQL) {
|
|
416
|
+
id = results?.[0].id
|
|
417
|
+
} else if (sqlClient === SqlClients.MY_SQL) {
|
|
418
|
+
id = results?.insertId
|
|
419
|
+
} else if (sqlClient === SqlClients.ORACLE) {
|
|
420
|
+
id = response.outBinds[0][0]
|
|
421
|
+
}
|
|
422
|
+
row = processFn(
|
|
423
|
+
await this.getReturningRow(queryFn, this.checkLookupKeys(id, json))
|
|
424
|
+
)
|
|
425
|
+
}
|
|
426
|
+
if (operation !== Operation.READ) {
|
|
427
|
+
return row
|
|
428
|
+
}
|
|
429
|
+
return results.length ? results : [{ [operation.toLowerCase()]: true }]
|
|
430
|
+
}
|
|
292
431
|
}
|
|
293
432
|
|
|
433
|
+
export default SqlQueryBuilder
|
|
294
434
|
module.exports = SqlQueryBuilder
|