@budibase/server 1.0.79 → 1.0.80-alpha.2
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/__mocks__/node-fetch.ts +1 -0
- package/builder/assets/{index.c8d1e8f0.css → index.c57242d4.css} +2 -2
- package/builder/assets/index.f3e82852.js +1288 -0
- package/builder/assets/{vendor.20f80cec.js → vendor.a7c6ad0a.js} +190 -216
- package/builder/index.html +3 -3
- package/coverage/clover.xml +2399 -2336
- package/coverage/coverage-final.json +138 -137
- package/coverage/lcov-report/api/controllers/analytics.js.html +6 -6
- package/coverage/lcov-report/api/controllers/apikeys.js.html +6 -6
- package/coverage/lcov-report/api/controllers/application.js.html +152 -149
- package/coverage/lcov-report/api/controllers/auth.js.html +7 -7
- package/coverage/lcov-report/api/controllers/automation.js.html +21 -21
- package/coverage/lcov-report/api/controllers/backup.js.html +3 -3
- package/coverage/lcov-report/api/controllers/cloud.js.html +11 -11
- package/coverage/lcov-report/api/controllers/component.js.html +5 -5
- package/coverage/lcov-report/api/controllers/datasource.js.html +16 -16
- package/coverage/lcov-report/api/controllers/dev.js.html +19 -19
- package/coverage/lcov-report/api/controllers/index.html +16 -16
- package/coverage/lcov-report/api/controllers/integration.js.html +4 -4
- package/coverage/lcov-report/api/controllers/layout.js.html +6 -6
- package/coverage/lcov-report/api/controllers/metadata.js.html +9 -9
- package/coverage/lcov-report/api/controllers/migrations.js.html +4 -4
- package/coverage/lcov-report/api/controllers/permission.js.html +15 -15
- package/coverage/lcov-report/api/controllers/query/index.html +1 -1
- package/coverage/lcov-report/api/controllers/query/index.js.html +26 -26
- package/coverage/lcov-report/api/controllers/query/validation.js.html +10 -10
- package/coverage/lcov-report/api/controllers/role.js.html +9 -9
- package/coverage/lcov-report/api/controllers/routing.js.html +9 -9
- package/coverage/lcov-report/api/controllers/row/external.js.html +16 -16
- package/coverage/lcov-report/api/controllers/row/index.html +27 -27
- package/coverage/lcov-report/api/controllers/row/index.js.html +46 -46
- package/coverage/lcov-report/api/controllers/row/internal.js.html +94 -82
- package/coverage/lcov-report/api/controllers/row/internalSearch.js.html +204 -204
- package/coverage/lcov-report/api/controllers/row/staticFormula.js.html +24 -24
- package/coverage/lcov-report/api/controllers/row/utils.js.html +29 -29
- package/coverage/lcov-report/api/controllers/screen.js.html +7 -7
- package/coverage/lcov-report/api/controllers/script.js.html +4 -4
- package/coverage/lcov-report/api/controllers/table/bulkFormula.js.html +49 -49
- package/coverage/lcov-report/api/controllers/table/external.js.html +12 -12
- package/coverage/lcov-report/api/controllers/table/index.html +11 -11
- package/coverage/lcov-report/api/controllers/table/index.js.html +47 -44
- package/coverage/lcov-report/api/controllers/table/internal.js.html +50 -50
- package/coverage/lcov-report/api/controllers/table/utils.js.html +80 -80
- package/coverage/lcov-report/api/controllers/templates.js.html +5 -5
- package/coverage/lcov-report/api/controllers/user.js.html +19 -19
- package/coverage/lcov-report/api/controllers/view/exporters.js.html +4 -4
- package/coverage/lcov-report/api/controllers/view/index.html +1 -1
- package/coverage/lcov-report/api/controllers/view/index.js.html +14 -14
- package/coverage/lcov-report/api/controllers/view/utils.js.html +12 -12
- package/coverage/lcov-report/api/controllers/view/viewBuilder.js.html +7 -7
- package/coverage/lcov-report/api/controllers/webhook.js.html +18 -27
- package/coverage/lcov-report/api/index.html +10 -10
- package/coverage/lcov-report/api/index.js.html +37 -28
- package/coverage/lcov-report/api/routes/analytics.js.html +6 -6
- package/coverage/lcov-report/api/routes/apikeys.js.html +8 -8
- package/coverage/lcov-report/api/routes/application.js.html +9 -9
- package/coverage/lcov-report/api/routes/auth.js.html +6 -6
- package/coverage/lcov-report/api/routes/automation.js.html +19 -109
- package/coverage/lcov-report/api/routes/backup.js.html +8 -8
- package/coverage/lcov-report/api/routes/cloud.js.html +8 -8
- package/coverage/lcov-report/api/routes/component.js.html +8 -8
- package/coverage/lcov-report/api/routes/datasource.js.html +18 -156
- package/coverage/lcov-report/api/routes/deploy.js.html +8 -8
- package/coverage/lcov-report/api/routes/dev.js.html +13 -13
- package/coverage/lcov-report/api/routes/index.html +35 -35
- package/coverage/lcov-report/api/routes/index.js.html +38 -32
- package/coverage/lcov-report/api/routes/integration.js.html +8 -8
- package/coverage/lcov-report/api/routes/layout.js.html +8 -8
- package/coverage/lcov-report/api/routes/metadata.js.html +9 -9
- package/coverage/lcov-report/api/routes/migrations.js.html +7 -7
- package/coverage/lcov-report/api/routes/permission.js.html +16 -58
- package/coverage/lcov-report/api/routes/query.js.html +10 -10
- package/coverage/lcov-report/api/routes/role.js.html +15 -78
- package/coverage/lcov-report/api/routes/routing.js.html +8 -8
- package/coverage/lcov-report/api/routes/row.js.html +17 -14
- package/coverage/lcov-report/api/routes/screen.js.html +14 -95
- package/coverage/lcov-report/api/routes/script.js.html +1 -1
- package/coverage/lcov-report/api/routes/static.js.html +13 -13
- package/coverage/lcov-report/api/routes/table.js.html +17 -62
- package/coverage/lcov-report/api/routes/templates.js.html +8 -8
- package/coverage/lcov-report/api/routes/user.js.html +8 -8
- package/coverage/lcov-report/api/routes/utils/index.html +111 -0
- package/coverage/lcov-report/api/routes/utils/validators.js.html +737 -0
- package/coverage/lcov-report/api/routes/view.js.html +10 -10
- package/coverage/lcov-report/api/routes/webhook.js.html +14 -62
- package/coverage/lcov-report/automations/actions.js.html +24 -24
- package/coverage/lcov-report/automations/automationUtils.js.html +5 -5
- package/coverage/lcov-report/automations/bullboard.js.html +16 -16
- package/coverage/lcov-report/automations/index.html +1 -1
- package/coverage/lcov-report/automations/index.js.html +7 -7
- package/coverage/lcov-report/automations/steps/bash.js.html +6 -6
- package/coverage/lcov-report/automations/steps/createRow.js.html +7 -7
- package/coverage/lcov-report/automations/steps/delay.js.html +4 -4
- package/coverage/lcov-report/automations/steps/deleteRow.js.html +7 -7
- package/coverage/lcov-report/automations/steps/discord.js.html +7 -7
- package/coverage/lcov-report/automations/steps/executeQuery.js.html +6 -6
- package/coverage/lcov-report/automations/steps/executeScript.js.html +6 -6
- package/coverage/lcov-report/automations/steps/filter.js.html +12 -9
- package/coverage/lcov-report/automations/steps/index.html +1 -1
- package/coverage/lcov-report/automations/steps/integromat.js.html +5 -5
- package/coverage/lcov-report/automations/steps/outgoingWebhook.js.html +8 -8
- package/coverage/lcov-report/automations/steps/queryRows.js.html +11 -11
- package/coverage/lcov-report/automations/steps/sendSmtpEmail.js.html +5 -5
- package/coverage/lcov-report/automations/steps/serverLog.js.html +3 -3
- package/coverage/lcov-report/automations/steps/slack.js.html +5 -5
- package/coverage/lcov-report/automations/steps/updateRow.js.html +6 -6
- package/coverage/lcov-report/automations/steps/utils.js.html +3 -3
- package/coverage/lcov-report/automations/steps/zapier.js.html +5 -5
- 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 +26 -26
- package/coverage/lcov-report/automations/utils.js.html +35 -35
- package/coverage/lcov-report/constants/index.html +5 -5
- package/coverage/lcov-report/constants/index.js.html +40 -28
- package/coverage/lcov-report/constants/layouts.js.html +5 -5
- package/coverage/lcov-report/constants/screens.js.html +4 -4
- package/coverage/lcov-report/db/client.js.html +18 -18
- package/coverage/lcov-report/db/inMemoryView.js.html +7 -7
- package/coverage/lcov-report/db/index.html +15 -15
- package/coverage/lcov-report/db/index.js.html +3 -3
- package/coverage/lcov-report/db/linkedRows/LinkController.js.html +21 -21
- package/coverage/lcov-report/db/linkedRows/index.html +1 -1
- package/coverage/lcov-report/db/linkedRows/index.js.html +36 -36
- package/coverage/lcov-report/db/linkedRows/linkUtils.js.html +30 -30
- package/coverage/lcov-report/db/newid.js.html +4 -4
- package/coverage/lcov-report/db/utils.js.html +123 -87
- package/coverage/lcov-report/events/AutomationEmitter.js.html +1 -1
- package/coverage/lcov-report/events/index.html +1 -1
- package/coverage/lcov-report/events/index.js.html +8 -8
- package/coverage/lcov-report/events/utils.js.html +18 -18
- package/coverage/lcov-report/index.html +89 -74
- 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 +5 -5
- package/coverage/lcov-report/middleware/authorized.js.html +29 -29
- package/coverage/lcov-report/middleware/builder.js.html +16 -16
- package/coverage/lcov-report/middleware/currentapp.js.html +44 -44
- package/coverage/lcov-report/middleware/index.html +1 -1
- package/coverage/lcov-report/middleware/joi-validator.js.html +14 -14
- package/coverage/lcov-report/middleware/resourceId.js.html +29 -29
- package/coverage/lcov-report/middleware/selfhost.js.html +1 -1
- package/coverage/lcov-report/middleware/usageQuota.js.html +17 -17
- package/coverage/lcov-report/middleware/utils.js.html +4 -4
- package/coverage/lcov-report/threads/automation.js.html +1 -1
- package/coverage/lcov-report/threads/index.html +19 -19
- package/coverage/lcov-report/threads/index.js.html +10 -10
- package/coverage/lcov-report/threads/query.js.html +123 -39
- package/coverage/lcov-report/threads/utils.js.html +14 -14
- package/coverage/lcov-report/utilities/bcrypt.js.html +1 -1
- package/coverage/lcov-report/utilities/budibaseDir.js.html +7 -7
- package/coverage/lcov-report/utilities/centralPath.js.html +4 -4
- package/coverage/lcov-report/utilities/csvParser.js.html +6 -6
- package/coverage/lcov-report/utilities/global.js.html +28 -28
- package/coverage/lcov-report/utilities/index.html +18 -18
- package/coverage/lcov-report/utilities/index.js.html +24 -24
- package/coverage/lcov-report/utilities/queue/inMemoryQueue.js.html +9 -9
- package/coverage/lcov-report/utilities/queue/index.html +1 -1
- package/coverage/lcov-report/utilities/routing/index.html +1 -1
- package/coverage/lcov-report/utilities/routing/index.js.html +6 -6
- package/coverage/lcov-report/utilities/rowProcessor/index.html +1 -1
- package/coverage/lcov-report/utilities/rowProcessor/index.js.html +60 -60
- package/coverage/lcov-report/utilities/rowProcessor/utils.js.html +13 -13
- package/coverage/lcov-report/utilities/scriptRunner.js.html +5 -5
- package/coverage/lcov-report/utilities/security.js.html +8 -8
- package/coverage/lcov-report/utilities/statusCodes.js.html +1 -1
- package/coverage/lcov-report/utilities/usageQuota/index.html +1 -1
- package/coverage/lcov-report/utilities/usageQuota/index.js.html +12 -12
- package/coverage/lcov-report/utilities/usageQuota/rows.js.html +8 -8
- package/coverage/lcov-report/utilities/usageQuota/usageQuoteReset.js.html +1 -1
- package/coverage/lcov-report/utilities/users.js.html +5 -5
- package/coverage/lcov-report/utilities/workerRequests.js.html +200 -53
- package/coverage/lcov.info +3323 -3224
- package/dist/api/controllers/application.js +1 -0
- package/dist/api/controllers/public/applications.js +94 -0
- package/dist/api/controllers/public/mapping/applications.js +29 -0
- package/dist/api/controllers/public/mapping/index.js +11 -0
- package/dist/api/controllers/public/mapping/queries.js +36 -0
- package/dist/api/controllers/public/mapping/rows.js +24 -0
- package/dist/api/controllers/public/mapping/tables.js +23 -0
- package/dist/api/controllers/public/mapping/types.js +2 -0
- package/dist/api/controllers/public/mapping/users.js +29 -0
- package/dist/api/controllers/public/queries.js +38 -0
- package/dist/api/controllers/public/rows.js +97 -0
- package/dist/api/controllers/public/tables.js +75 -0
- package/dist/api/controllers/public/users.js +95 -0
- package/dist/api/controllers/public/utils.js +49 -0
- package/dist/api/controllers/row/internal.js +4 -1
- package/dist/api/controllers/table/index.js +2 -1
- package/dist/api/controllers/webhook.js +3 -5
- package/dist/api/index.js +3 -1
- package/dist/api/routes/automation.js +3 -31
- package/dist/api/routes/datasource.js +3 -50
- package/dist/api/routes/index.js +2 -0
- package/dist/api/routes/permission.js +4 -14
- package/dist/api/routes/public/applications.js +141 -0
- package/dist/api/routes/public/index.js +101 -0
- package/dist/api/routes/public/middleware/mapper.js +94 -0
- package/dist/api/routes/public/queries.js +77 -0
- package/dist/api/routes/public/rows.js +229 -0
- package/dist/api/routes/public/tables.js +154 -0
- package/dist/api/routes/public/users.js +137 -0
- package/dist/api/routes/public/utils/Endpoint.js +36 -0
- package/dist/api/routes/role.js +3 -19
- package/dist/api/routes/row.js +3 -4
- package/dist/api/routes/screen.js +2 -23
- package/dist/api/routes/table.js +3 -17
- package/dist/api/routes/tests/utilities/index.js +23 -0
- package/dist/api/routes/utils/validators.js +200 -0
- package/dist/api/routes/webhook.js +2 -17
- package/dist/automations/steps/filter.js +2 -2
- package/dist/automations/steps/queryRows.js +1 -1
- package/dist/automations/utils.js +2 -2
- package/dist/constants/index.js +3 -0
- package/dist/db/utils.js +11 -0
- package/dist/definitions/openapi.js +6 -0
- package/dist/environment.js +1 -0
- package/dist/integrations/base/sql.js +16 -1
- package/dist/integrations/base/sqlTable.js +8 -4
- package/dist/integrations/googlesheets.js +3 -0
- package/dist/integrations/microsoftSqlServer.js +60 -43
- package/dist/integrations/mysql.js +3 -0
- package/dist/integrations/oracle.js +14 -19
- package/dist/integrations/postgres.js +34 -28
- package/dist/integrations/utils.js +32 -15
- package/dist/package.json +11 -7
- package/dist/tests/utilities/TestConfiguration.js +25 -8
- package/dist/threads/query.js +33 -8
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/utilities/workerRequests.js +50 -15
- package/package.json +12 -8
- package/scripts/integrations/mssql/data/setup.sql +18 -1
- package/scripts/integrations/oracle/oracle.md +2 -2
- package/scripts/integrations/postgres/init.sql +11 -3
- package/scripts/likeCypress.ts +9 -6
- package/specs/generate.js +83 -0
- package/specs/openapi.json +2222 -0
- package/specs/openapi.yaml +1530 -0
- package/specs/parameters.js +59 -0
- package/specs/resources/application.js +101 -0
- package/specs/resources/index.js +24 -0
- package/specs/resources/misc.js +12 -0
- package/specs/resources/query.js +189 -0
- package/specs/resources/row.js +125 -0
- package/specs/resources/table.js +191 -0
- package/specs/resources/user.js +126 -0
- package/specs/resources/utils/Resource.js +26 -0
- package/specs/resources/utils/index.js +11 -0
- package/specs/security.js +7 -0
- package/src/api/controllers/application.js +1 -0
- package/src/api/controllers/public/applications.ts +74 -0
- package/src/api/controllers/public/mapping/applications.ts +32 -0
- package/src/api/controllers/public/mapping/index.ts +13 -0
- package/src/api/controllers/public/mapping/queries.ts +39 -0
- package/src/api/controllers/public/mapping/rows.ts +31 -0
- package/src/api/controllers/public/mapping/tables.ts +26 -0
- package/src/api/controllers/public/mapping/types.ts +13 -0
- package/src/api/controllers/public/mapping/users.ts +32 -0
- package/src/api/controllers/public/queries.ts +20 -0
- package/src/api/controllers/public/rows.ts +77 -0
- package/src/api/controllers/public/tables.ts +56 -0
- package/src/api/controllers/public/users.ts +82 -0
- package/src/api/controllers/public/utils.ts +38 -0
- package/src/api/controllers/row/ExternalRequest.ts +1 -1
- package/src/api/controllers/row/internal.js +4 -0
- package/src/api/controllers/table/index.js +2 -1
- package/src/api/controllers/webhook.js +3 -6
- package/src/api/index.js +4 -1
- package/src/api/routes/automation.js +3 -33
- package/src/api/routes/datasource.js +6 -52
- package/src/api/routes/index.js +2 -0
- package/src/api/routes/permission.js +4 -18
- package/src/api/routes/public/applications.ts +156 -0
- package/src/api/routes/public/index.ts +118 -0
- package/src/api/routes/public/middleware/mapper.ts +81 -0
- package/src/api/routes/public/queries.ts +81 -0
- package/src/api/routes/public/rows.ts +242 -0
- package/src/api/routes/public/tables.ts +169 -0
- package/src/api/routes/public/tests/compare.spec.js +184 -0
- package/src/api/routes/public/users.ts +144 -0
- package/src/api/routes/public/utils/Endpoint.ts +51 -0
- package/src/api/routes/role.js +3 -24
- package/src/api/routes/row.js +3 -2
- package/src/api/routes/screen.js +2 -29
- package/src/api/routes/table.js +4 -19
- package/src/api/routes/tests/utilities/index.js +24 -0
- package/src/api/routes/utils/validators.js +219 -0
- package/src/api/routes/webhook.js +2 -18
- package/src/automations/steps/filter.js +3 -2
- package/src/automations/steps/queryRows.js +1 -1
- package/src/automations/utils.js +2 -2
- package/src/constants/index.js +4 -0
- package/src/db/utils.js +12 -0
- package/src/definitions/common.ts +4 -0
- package/src/definitions/datasource.ts +1 -0
- package/src/definitions/openapi.ts +943 -0
- package/src/environment.js +1 -0
- package/src/integrations/base/datasourcePlus.ts +3 -0
- package/src/integrations/base/sql.ts +16 -1
- package/src/integrations/base/sqlTable.ts +11 -7
- package/src/integrations/googlesheets.ts +5 -2
- package/src/integrations/microsoftSqlServer.ts +86 -61
- package/src/integrations/mysql.ts +4 -0
- package/src/integrations/oracle.ts +27 -35
- package/src/integrations/postgres.ts +33 -26
- package/src/integrations/utils.ts +43 -15
- package/src/tests/utilities/TestConfiguration.js +23 -2
- package/src/threads/query.js +37 -9
- package/src/utilities/workerRequests.js +65 -16
- package/builder/assets/index.f28c5d54.js +0 -1352
- package/scripts/proxy/generateProxyConfig.js +0 -70
package/src/environment.js
CHANGED
|
@@ -45,6 +45,7 @@ module.exports = {
|
|
|
45
45
|
INTERNAL_API_KEY: process.env.INTERNAL_API_KEY,
|
|
46
46
|
MULTI_TENANCY: process.env.MULTI_TENANCY,
|
|
47
47
|
HTTP_MIGRATIONS: process.env.HTTP_MIGRATIONS,
|
|
48
|
+
API_REQ_LIMIT_PER_SEC: process.env.API_REQ_LIMIT_PER_SEC,
|
|
48
49
|
// environment
|
|
49
50
|
NODE_ENV: process.env.NODE_ENV,
|
|
50
51
|
JEST_WORKER_ID: process.env.JEST_WORKER_ID,
|
|
@@ -5,5 +5,8 @@ export interface DatasourcePlus extends IntegrationBase {
|
|
|
5
5
|
tables: Record<string, Table>
|
|
6
6
|
schemaErrors: Record<string, string>
|
|
7
7
|
|
|
8
|
+
// if the datasource supports the use of bindings directly (to protect against SQL injection)
|
|
9
|
+
// this returns the format of the identifier
|
|
10
|
+
getBindingIdentifier(): string
|
|
8
11
|
buildSchema(datasourceId: string, entities: Record<string, Table>): any
|
|
9
12
|
}
|
|
@@ -249,6 +249,9 @@ class InternalBuilder {
|
|
|
249
249
|
create(knex: Knex, json: QueryJson, opts: QueryOptions): KnexQuery {
|
|
250
250
|
const { endpoint, body } = json
|
|
251
251
|
let query: KnexQuery = knex(endpoint.entityId)
|
|
252
|
+
if (endpoint.schema) {
|
|
253
|
+
query = query.withSchema(endpoint.schema)
|
|
254
|
+
}
|
|
252
255
|
const parsedBody = parseBody(body)
|
|
253
256
|
// make sure no null values in body for creation
|
|
254
257
|
for (let [key, value] of Object.entries(parsedBody)) {
|
|
@@ -267,6 +270,9 @@ class InternalBuilder {
|
|
|
267
270
|
bulkCreate(knex: Knex, json: QueryJson): KnexQuery {
|
|
268
271
|
const { endpoint, body } = json
|
|
269
272
|
let query: KnexQuery = knex(endpoint.entityId)
|
|
273
|
+
if (endpoint.schema) {
|
|
274
|
+
query = query.withSchema(endpoint.schema)
|
|
275
|
+
}
|
|
270
276
|
if (!Array.isArray(body)) {
|
|
271
277
|
return query
|
|
272
278
|
}
|
|
@@ -275,7 +281,7 @@ class InternalBuilder {
|
|
|
275
281
|
}
|
|
276
282
|
|
|
277
283
|
read(knex: Knex, json: QueryJson, limit: number): KnexQuery {
|
|
278
|
-
let { endpoint, resource, filters,
|
|
284
|
+
let { endpoint, resource, filters, paginate, relationships } = json
|
|
279
285
|
const tableName = endpoint.entityId
|
|
280
286
|
// select all if not specified
|
|
281
287
|
if (!resource) {
|
|
@@ -302,6 +308,9 @@ class InternalBuilder {
|
|
|
302
308
|
}
|
|
303
309
|
// start building the query
|
|
304
310
|
let query: KnexQuery = knex(tableName).limit(foundLimit)
|
|
311
|
+
if (endpoint.schema) {
|
|
312
|
+
query = query.withSchema(endpoint.schema)
|
|
313
|
+
}
|
|
305
314
|
if (foundOffset) {
|
|
306
315
|
query = query.offset(foundOffset)
|
|
307
316
|
}
|
|
@@ -331,6 +340,9 @@ class InternalBuilder {
|
|
|
331
340
|
update(knex: Knex, json: QueryJson, opts: QueryOptions): KnexQuery {
|
|
332
341
|
const { endpoint, body, filters } = json
|
|
333
342
|
let query: KnexQuery = knex(endpoint.entityId)
|
|
343
|
+
if (endpoint.schema) {
|
|
344
|
+
query = query.withSchema(endpoint.schema)
|
|
345
|
+
}
|
|
334
346
|
const parsedBody = parseBody(body)
|
|
335
347
|
query = this.addFilters(query, filters, { tableName: endpoint.entityId })
|
|
336
348
|
// mysql can't use returning
|
|
@@ -344,6 +356,9 @@ class InternalBuilder {
|
|
|
344
356
|
delete(knex: Knex, json: QueryJson, opts: QueryOptions): KnexQuery {
|
|
345
357
|
const { endpoint, filters } = json
|
|
346
358
|
let query: KnexQuery = knex(endpoint.entityId)
|
|
359
|
+
if (endpoint.schema) {
|
|
360
|
+
query = query.withSchema(endpoint.schema)
|
|
361
|
+
}
|
|
347
362
|
query = this.addFilters(query, filters, { tableName: endpoint.entityId })
|
|
348
363
|
// mysql can't use returning
|
|
349
364
|
if (opts.disableReturning) {
|
|
@@ -101,28 +101,28 @@ function generateSchema(
|
|
|
101
101
|
}
|
|
102
102
|
|
|
103
103
|
function buildCreateTable(
|
|
104
|
-
knex:
|
|
104
|
+
knex: SchemaBuilder,
|
|
105
105
|
table: Table,
|
|
106
106
|
tables: Record<string, Table>
|
|
107
107
|
): SchemaBuilder {
|
|
108
|
-
return knex.
|
|
108
|
+
return knex.createTable(table.name, schema => {
|
|
109
109
|
generateSchema(schema, table, tables)
|
|
110
110
|
})
|
|
111
111
|
}
|
|
112
112
|
|
|
113
113
|
function buildUpdateTable(
|
|
114
|
-
knex:
|
|
114
|
+
knex: SchemaBuilder,
|
|
115
115
|
table: Table,
|
|
116
116
|
tables: Record<string, Table>,
|
|
117
117
|
oldTable: Table
|
|
118
118
|
): SchemaBuilder {
|
|
119
|
-
return knex.
|
|
119
|
+
return knex.alterTable(table.name, schema => {
|
|
120
120
|
generateSchema(schema, table, tables, oldTable)
|
|
121
121
|
})
|
|
122
122
|
}
|
|
123
123
|
|
|
124
|
-
function buildDeleteTable(knex:
|
|
125
|
-
return knex.
|
|
124
|
+
function buildDeleteTable(knex: SchemaBuilder, table: Table): SchemaBuilder {
|
|
125
|
+
return knex.dropTable(table.name)
|
|
126
126
|
}
|
|
127
127
|
|
|
128
128
|
class SqlTableQueryBuilder {
|
|
@@ -146,7 +146,11 @@ class SqlTableQueryBuilder {
|
|
|
146
146
|
}
|
|
147
147
|
|
|
148
148
|
_tableQuery(json: QueryJson): any {
|
|
149
|
-
|
|
149
|
+
let client = knex({ client: this.sqlClient }).schema
|
|
150
|
+
if (json?.endpoint?.schema) {
|
|
151
|
+
client = client.withSchema(json.endpoint.schema)
|
|
152
|
+
}
|
|
153
|
+
|
|
150
154
|
let query
|
|
151
155
|
if (!json.table || !json.meta || !json.meta.tables) {
|
|
152
156
|
throw "Cannot execute without table being specified"
|
|
@@ -6,11 +6,10 @@ import {
|
|
|
6
6
|
} from "../definitions/datasource"
|
|
7
7
|
import { OAuth2Client } from "google-auth-library"
|
|
8
8
|
import { DatasourcePlus } from "./base/datasourcePlus"
|
|
9
|
-
import {
|
|
9
|
+
import { Table, TableSchema } from "../definitions/common"
|
|
10
10
|
import { buildExternalTableId } from "./utils"
|
|
11
11
|
import { DataSourceOperation, FieldTypes } from "../constants"
|
|
12
12
|
import { GoogleSpreadsheet } from "google-spreadsheet"
|
|
13
|
-
import { table } from "console"
|
|
14
13
|
|
|
15
14
|
module GoogleSheetsModule {
|
|
16
15
|
const { getGlobalDB } = require("@budibase/backend-core/tenancy")
|
|
@@ -112,6 +111,10 @@ module GoogleSheetsModule {
|
|
|
112
111
|
this.client = new GoogleSpreadsheet(spreadsheetId)
|
|
113
112
|
}
|
|
114
113
|
|
|
114
|
+
getBindingIdentifier() {
|
|
115
|
+
return ""
|
|
116
|
+
}
|
|
117
|
+
|
|
115
118
|
/**
|
|
116
119
|
* Pull the spreadsheet ID out from a valid google sheets URL
|
|
117
120
|
* @param spreadsheetId - the URL or standard spreadsheetId of the google sheet
|
|
@@ -19,6 +19,7 @@ import { Table, TableSchema } from "../definitions/common"
|
|
|
19
19
|
module MSSQLModule {
|
|
20
20
|
const sqlServer = require("mssql")
|
|
21
21
|
const Sql = require("./base/sql")
|
|
22
|
+
const DEFAULT_SCHEMA = "dbo"
|
|
22
23
|
|
|
23
24
|
interface MSSQLConfig {
|
|
24
25
|
user: string
|
|
@@ -26,9 +27,17 @@ module MSSQLModule {
|
|
|
26
27
|
server: string
|
|
27
28
|
port: number
|
|
28
29
|
database: string
|
|
30
|
+
schema: string
|
|
29
31
|
encrypt?: boolean
|
|
30
32
|
}
|
|
31
33
|
|
|
34
|
+
interface TablesResponse {
|
|
35
|
+
TABLE_CATALOG: string
|
|
36
|
+
TABLE_SCHEMA: string
|
|
37
|
+
TABLE_NAME: string
|
|
38
|
+
TABLE_TYPE: string
|
|
39
|
+
}
|
|
40
|
+
|
|
32
41
|
const SCHEMA: Integration = {
|
|
33
42
|
docs: "https://github.com/tediousjs/node-mssql",
|
|
34
43
|
plus: true,
|
|
@@ -58,6 +67,10 @@ module MSSQLModule {
|
|
|
58
67
|
type: DatasourceFieldTypes.STRING,
|
|
59
68
|
default: "root",
|
|
60
69
|
},
|
|
70
|
+
schema: {
|
|
71
|
+
type: DatasourceFieldTypes.STRING,
|
|
72
|
+
default: DEFAULT_SCHEMA,
|
|
73
|
+
},
|
|
61
74
|
encrypt: {
|
|
62
75
|
type: DatasourceFieldTypes.BOOLEAN,
|
|
63
76
|
default: true,
|
|
@@ -79,34 +92,9 @@ module MSSQLModule {
|
|
|
79
92
|
},
|
|
80
93
|
}
|
|
81
94
|
|
|
82
|
-
async function internalQuery(
|
|
83
|
-
client: any,
|
|
84
|
-
query: SqlQuery,
|
|
85
|
-
operation: string | undefined = undefined
|
|
86
|
-
) {
|
|
87
|
-
const request = client.request()
|
|
88
|
-
try {
|
|
89
|
-
if (Array.isArray(query.bindings)) {
|
|
90
|
-
let count = 0
|
|
91
|
-
for (let binding of query.bindings) {
|
|
92
|
-
request.input(`p${count++}`, binding)
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
// this is a hack to get the inserted ID back,
|
|
96
|
-
// no way to do this with Knex nicely
|
|
97
|
-
const sql =
|
|
98
|
-
operation === Operation.CREATE
|
|
99
|
-
? `${query.sql}; SELECT SCOPE_IDENTITY() AS id;`
|
|
100
|
-
: query.sql
|
|
101
|
-
return await request.query(sql)
|
|
102
|
-
} catch (err) {
|
|
103
|
-
// @ts-ignore
|
|
104
|
-
throw new Error(err)
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
|
|
108
95
|
class SqlServerIntegration extends Sql implements DatasourcePlus {
|
|
109
96
|
private readonly config: MSSQLConfig
|
|
97
|
+
private index: number = 0
|
|
110
98
|
static pool: any
|
|
111
99
|
public tables: Record<string, Table> = {}
|
|
112
100
|
public schemaErrors: Record<string, string> = {}
|
|
@@ -121,6 +109,62 @@ module MSSQLModule {
|
|
|
121
109
|
TABLES_SQL =
|
|
122
110
|
"SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE='BASE TABLE'"
|
|
123
111
|
|
|
112
|
+
constructor(config: MSSQLConfig) {
|
|
113
|
+
super(SqlClients.MS_SQL)
|
|
114
|
+
this.config = config
|
|
115
|
+
const clientCfg = {
|
|
116
|
+
...this.config,
|
|
117
|
+
options: {
|
|
118
|
+
encrypt: this.config.encrypt,
|
|
119
|
+
enableArithAbort: true,
|
|
120
|
+
},
|
|
121
|
+
}
|
|
122
|
+
delete clientCfg.encrypt
|
|
123
|
+
if (!this.pool) {
|
|
124
|
+
this.pool = new sqlServer.ConnectionPool(clientCfg)
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
getBindingIdentifier(): string {
|
|
129
|
+
return `(@p${this.index++})`
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
async connect() {
|
|
133
|
+
try {
|
|
134
|
+
this.client = await this.pool.connect()
|
|
135
|
+
} catch (err) {
|
|
136
|
+
// @ts-ignore
|
|
137
|
+
throw new Error(err)
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
async internalQuery(
|
|
142
|
+
query: SqlQuery,
|
|
143
|
+
operation: string | undefined = undefined
|
|
144
|
+
) {
|
|
145
|
+
const client = this.client
|
|
146
|
+
const request = client.request()
|
|
147
|
+
this.index = 0
|
|
148
|
+
try {
|
|
149
|
+
if (Array.isArray(query.bindings)) {
|
|
150
|
+
let count = 0
|
|
151
|
+
for (let binding of query.bindings) {
|
|
152
|
+
request.input(`p${count++}`, binding)
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
// this is a hack to get the inserted ID back,
|
|
156
|
+
// no way to do this with Knex nicely
|
|
157
|
+
const sql =
|
|
158
|
+
operation === Operation.CREATE
|
|
159
|
+
? `${query.sql}; SELECT SCOPE_IDENTITY() AS id;`
|
|
160
|
+
: query.sql
|
|
161
|
+
return await request.query(sql)
|
|
162
|
+
} catch (err) {
|
|
163
|
+
// @ts-ignore
|
|
164
|
+
throw new Error(err)
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
124
168
|
getDefinitionSQL(tableName: string) {
|
|
125
169
|
return `select *
|
|
126
170
|
from INFORMATION_SCHEMA.COLUMNS
|
|
@@ -149,33 +193,8 @@ module MSSQLModule {
|
|
|
149
193
|
WHERE TABLE_NAME='${tableName}'`
|
|
150
194
|
}
|
|
151
195
|
|
|
152
|
-
constructor(config: MSSQLConfig) {
|
|
153
|
-
super(SqlClients.MS_SQL)
|
|
154
|
-
this.config = config
|
|
155
|
-
const clientCfg = {
|
|
156
|
-
...this.config,
|
|
157
|
-
options: {
|
|
158
|
-
encrypt: this.config.encrypt,
|
|
159
|
-
enableArithAbort: true,
|
|
160
|
-
},
|
|
161
|
-
}
|
|
162
|
-
delete clientCfg.encrypt
|
|
163
|
-
if (!this.pool) {
|
|
164
|
-
this.pool = new sqlServer.ConnectionPool(clientCfg)
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
async connect() {
|
|
169
|
-
try {
|
|
170
|
-
this.client = await this.pool.connect()
|
|
171
|
-
} catch (err) {
|
|
172
|
-
// @ts-ignore
|
|
173
|
-
throw new Error(err)
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
|
|
177
196
|
async runSQL(sql: string) {
|
|
178
|
-
return (await internalQuery(
|
|
197
|
+
return (await this.internalQuery(getSqlQuery(sql))).recordset
|
|
179
198
|
}
|
|
180
199
|
|
|
181
200
|
/**
|
|
@@ -185,11 +204,14 @@ module MSSQLModule {
|
|
|
185
204
|
*/
|
|
186
205
|
async buildSchema(datasourceId: string, entities: Record<string, Table>) {
|
|
187
206
|
await this.connect()
|
|
188
|
-
let
|
|
189
|
-
if (
|
|
207
|
+
let tableInfo: TablesResponse[] = await this.runSQL(this.TABLES_SQL)
|
|
208
|
+
if (tableInfo == null || !Array.isArray(tableInfo)) {
|
|
190
209
|
throw "Unable to get list of tables in database"
|
|
191
210
|
}
|
|
192
|
-
|
|
211
|
+
|
|
212
|
+
const schema = this.config.schema || DEFAULT_SCHEMA
|
|
213
|
+
const tableNames = tableInfo
|
|
214
|
+
.filter((record: any) => record.TABLE_SCHEMA === schema)
|
|
193
215
|
.map((record: any) => record.TABLE_NAME)
|
|
194
216
|
.filter((name: string) => this.MASTER_TABLES.indexOf(name) === -1)
|
|
195
217
|
|
|
@@ -238,33 +260,36 @@ module MSSQLModule {
|
|
|
238
260
|
|
|
239
261
|
async read(query: SqlQuery | string) {
|
|
240
262
|
await this.connect()
|
|
241
|
-
const response = await internalQuery(
|
|
263
|
+
const response = await this.internalQuery(getSqlQuery(query))
|
|
242
264
|
return response.recordset
|
|
243
265
|
}
|
|
244
266
|
|
|
245
267
|
async create(query: SqlQuery | string) {
|
|
246
268
|
await this.connect()
|
|
247
|
-
const response = await internalQuery(
|
|
269
|
+
const response = await this.internalQuery(getSqlQuery(query))
|
|
248
270
|
return response.recordset || [{ created: true }]
|
|
249
271
|
}
|
|
250
272
|
|
|
251
273
|
async update(query: SqlQuery | string) {
|
|
252
274
|
await this.connect()
|
|
253
|
-
const response = await internalQuery(
|
|
275
|
+
const response = await this.internalQuery(getSqlQuery(query))
|
|
254
276
|
return response.recordset || [{ updated: true }]
|
|
255
277
|
}
|
|
256
278
|
|
|
257
279
|
async delete(query: SqlQuery | string) {
|
|
258
280
|
await this.connect()
|
|
259
|
-
const response = await internalQuery(
|
|
281
|
+
const response = await this.internalQuery(getSqlQuery(query))
|
|
260
282
|
return response.recordset || [{ deleted: true }]
|
|
261
283
|
}
|
|
262
284
|
|
|
263
285
|
async query(json: QueryJson) {
|
|
286
|
+
const schema = this.config.schema
|
|
264
287
|
await this.connect()
|
|
288
|
+
if (schema && schema !== DEFAULT_SCHEMA && json?.endpoint) {
|
|
289
|
+
json.endpoint.schema = schema
|
|
290
|
+
}
|
|
265
291
|
const operation = this._operation(json)
|
|
266
|
-
const queryFn = (query: any, op: string) =>
|
|
267
|
-
internalQuery(this.client, query, op)
|
|
292
|
+
const queryFn = (query: any, op: string) => this.internalQuery(query, op)
|
|
268
293
|
const processFn = (result: any) =>
|
|
269
294
|
result.recordset ? result.recordset : [{ [operation]: true }]
|
|
270
295
|
return this.queryWithReturning(json, queryFn, processFn)
|
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
import {
|
|
2
|
-
Integration,
|
|
3
2
|
DatasourceFieldTypes,
|
|
3
|
+
Integration,
|
|
4
|
+
Operation,
|
|
5
|
+
QueryJson,
|
|
4
6
|
QueryTypes,
|
|
5
7
|
SqlQuery,
|
|
6
|
-
QueryJson,
|
|
7
|
-
Operation,
|
|
8
8
|
} from "../definitions/datasource"
|
|
9
9
|
import {
|
|
10
|
-
finaliseExternalTables,
|
|
11
|
-
getSqlQuery,
|
|
12
10
|
buildExternalTableId,
|
|
13
11
|
convertSqlType,
|
|
12
|
+
finaliseExternalTables,
|
|
13
|
+
getSqlQuery,
|
|
14
14
|
SqlClients,
|
|
15
15
|
} from "./utils"
|
|
16
16
|
import oracledb, {
|
|
17
|
-
|
|
18
|
-
Result,
|
|
17
|
+
BindParameters,
|
|
19
18
|
Connection,
|
|
20
19
|
ConnectionAttributes,
|
|
21
|
-
|
|
20
|
+
ExecuteOptions,
|
|
21
|
+
Result,
|
|
22
22
|
} from "oracledb"
|
|
23
23
|
import Sql from "./base/sql"
|
|
24
24
|
import { Table } from "../definitions/common"
|
|
@@ -137,6 +137,7 @@ module OracleModule {
|
|
|
137
137
|
|
|
138
138
|
class OracleIntegration extends Sql implements DatasourcePlus {
|
|
139
139
|
private readonly config: OracleConfig
|
|
140
|
+
private index: number = 1
|
|
140
141
|
|
|
141
142
|
public tables: Record<string, Table> = {}
|
|
142
143
|
public schemaErrors: Record<string, string> = {}
|
|
@@ -174,6 +175,10 @@ module OracleModule {
|
|
|
174
175
|
this.config = config
|
|
175
176
|
}
|
|
176
177
|
|
|
178
|
+
getBindingIdentifier(): string {
|
|
179
|
+
return `:${this.index++}`
|
|
180
|
+
}
|
|
181
|
+
|
|
177
182
|
/**
|
|
178
183
|
* Map the flat tabular columns and constraints data into a nested object
|
|
179
184
|
*/
|
|
@@ -233,20 +238,14 @@ module OracleModule {
|
|
|
233
238
|
return oracleTables
|
|
234
239
|
}
|
|
235
240
|
|
|
236
|
-
private isSupportedColumn(column: OracleColumn) {
|
|
237
|
-
|
|
238
|
-
return false
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
return true
|
|
241
|
+
private static isSupportedColumn(column: OracleColumn) {
|
|
242
|
+
return !UNSUPPORTED_TYPES.includes(column.type)
|
|
242
243
|
}
|
|
243
244
|
|
|
244
|
-
private isAutoColumn(column: OracleColumn) {
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
return false
|
|
245
|
+
private static isAutoColumn(column: OracleColumn) {
|
|
246
|
+
return !!(
|
|
247
|
+
column.default && column.default.toLowerCase().includes("nextval")
|
|
248
|
+
)
|
|
250
249
|
}
|
|
251
250
|
|
|
252
251
|
/**
|
|
@@ -254,7 +253,7 @@ module OracleModule {
|
|
|
254
253
|
* This matches the default behaviour for generating DDL used in knex.
|
|
255
254
|
*/
|
|
256
255
|
private isBooleanType(column: OracleColumn): boolean {
|
|
257
|
-
|
|
256
|
+
return (
|
|
258
257
|
column.type.toLowerCase() === "number" &&
|
|
259
258
|
Object.values(column.constraints).filter(c => {
|
|
260
259
|
if (
|
|
@@ -273,11 +272,7 @@ module OracleModule {
|
|
|
273
272
|
}
|
|
274
273
|
return false
|
|
275
274
|
}).length > 0
|
|
276
|
-
)
|
|
277
|
-
return true
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
return false
|
|
275
|
+
)
|
|
281
276
|
}
|
|
282
277
|
|
|
283
278
|
private internalConvertType(column: OracleColumn): string {
|
|
@@ -317,7 +312,9 @@ module OracleModule {
|
|
|
317
312
|
// iterate each column on the table
|
|
318
313
|
Object.values(oracleTable.columns)
|
|
319
314
|
// remove columns that we can't read / save
|
|
320
|
-
.filter(oracleColumn =>
|
|
315
|
+
.filter(oracleColumn =>
|
|
316
|
+
OracleIntegration.isSupportedColumn(oracleColumn)
|
|
317
|
+
)
|
|
321
318
|
// match the order of the columns in the db
|
|
322
319
|
.sort((c1, c2) => c1.id - c2.id)
|
|
323
320
|
.forEach(oracleColumn => {
|
|
@@ -325,7 +322,7 @@ module OracleModule {
|
|
|
325
322
|
let fieldSchema = table.schema[columnName]
|
|
326
323
|
if (!fieldSchema) {
|
|
327
324
|
fieldSchema = {
|
|
328
|
-
autocolumn:
|
|
325
|
+
autocolumn: OracleIntegration.isAutoColumn(oracleColumn),
|
|
329
326
|
name: columnName,
|
|
330
327
|
type: this.internalConvertType(oracleColumn),
|
|
331
328
|
}
|
|
@@ -351,18 +348,13 @@ module OracleModule {
|
|
|
351
348
|
private async internalQuery<T>(query: SqlQuery): Promise<Result<T>> {
|
|
352
349
|
let connection
|
|
353
350
|
try {
|
|
351
|
+
this.index = 1
|
|
354
352
|
connection = await this.getConnection()
|
|
355
353
|
|
|
356
354
|
const options: ExecuteOptions = { autoCommit: true }
|
|
357
355
|
const bindings: BindParameters = query.bindings || []
|
|
358
356
|
|
|
359
|
-
|
|
360
|
-
query.sql,
|
|
361
|
-
bindings,
|
|
362
|
-
options
|
|
363
|
-
)
|
|
364
|
-
|
|
365
|
-
return result
|
|
357
|
+
return await connection.execute<T>(query.sql, bindings, options)
|
|
366
358
|
} finally {
|
|
367
359
|
if (connection) {
|
|
368
360
|
try {
|
|
@@ -103,30 +103,11 @@ module PostgresModule {
|
|
|
103
103
|
},
|
|
104
104
|
}
|
|
105
105
|
|
|
106
|
-
async function internalQuery(client: any, query: SqlQuery) {
|
|
107
|
-
// need to handle a specific issue with json data types in postgres,
|
|
108
|
-
// new lines inside the JSON data will break it
|
|
109
|
-
if (query && query.sql) {
|
|
110
|
-
const matches = query.sql.match(JSON_REGEX)
|
|
111
|
-
if (matches && matches.length > 0) {
|
|
112
|
-
for (let match of matches) {
|
|
113
|
-
const escaped = escapeDangerousCharacters(match)
|
|
114
|
-
query.sql = query.sql.replace(match, escaped)
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
try {
|
|
119
|
-
return await client.query(query.sql, query.bindings || [])
|
|
120
|
-
} catch (err) {
|
|
121
|
-
// @ts-ignore
|
|
122
|
-
throw new Error(err)
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
|
|
126
106
|
class PostgresIntegration extends Sql implements DatasourcePlus {
|
|
127
107
|
static pool: any
|
|
128
108
|
private readonly client: any
|
|
129
109
|
private readonly config: PostgresConfig
|
|
110
|
+
private index: number = 1
|
|
130
111
|
public tables: Record<string, Table> = {}
|
|
131
112
|
public schemaErrors: Record<string, string> = {}
|
|
132
113
|
|
|
@@ -163,6 +144,32 @@ module PostgresModule {
|
|
|
163
144
|
this.setSchema()
|
|
164
145
|
}
|
|
165
146
|
|
|
147
|
+
getBindingIdentifier(): string {
|
|
148
|
+
return `$${this.index++}`
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
async internalQuery(query: SqlQuery) {
|
|
152
|
+
const client = this.client
|
|
153
|
+
this.index = 1
|
|
154
|
+
// need to handle a specific issue with json data types in postgres,
|
|
155
|
+
// new lines inside the JSON data will break it
|
|
156
|
+
if (query && query.sql) {
|
|
157
|
+
const matches = query.sql.match(JSON_REGEX)
|
|
158
|
+
if (matches && matches.length > 0) {
|
|
159
|
+
for (let match of matches) {
|
|
160
|
+
const escaped = escapeDangerousCharacters(match)
|
|
161
|
+
query.sql = query.sql.replace(match, escaped)
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
try {
|
|
166
|
+
return await client.query(query.sql, query.bindings || [])
|
|
167
|
+
} catch (err) {
|
|
168
|
+
// @ts-ignore
|
|
169
|
+
throw new Error(err)
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
166
173
|
setSchema() {
|
|
167
174
|
if (!this.config.schema) {
|
|
168
175
|
this.config.schema = "public"
|
|
@@ -241,22 +248,22 @@ module PostgresModule {
|
|
|
241
248
|
}
|
|
242
249
|
|
|
243
250
|
async create(query: SqlQuery | string) {
|
|
244
|
-
const response = await internalQuery(
|
|
251
|
+
const response = await this.internalQuery(getSqlQuery(query))
|
|
245
252
|
return response.rows.length ? response.rows : [{ created: true }]
|
|
246
253
|
}
|
|
247
254
|
|
|
248
255
|
async read(query: SqlQuery | string) {
|
|
249
|
-
const response = await internalQuery(
|
|
256
|
+
const response = await this.internalQuery(getSqlQuery(query))
|
|
250
257
|
return response.rows
|
|
251
258
|
}
|
|
252
259
|
|
|
253
260
|
async update(query: SqlQuery | string) {
|
|
254
|
-
const response = await internalQuery(
|
|
261
|
+
const response = await this.internalQuery(getSqlQuery(query))
|
|
255
262
|
return response.rows.length ? response.rows : [{ updated: true }]
|
|
256
263
|
}
|
|
257
264
|
|
|
258
265
|
async delete(query: SqlQuery | string) {
|
|
259
|
-
const response = await internalQuery(
|
|
266
|
+
const response = await this.internalQuery(getSqlQuery(query))
|
|
260
267
|
return response.rows.length ? response.rows : [{ deleted: true }]
|
|
261
268
|
}
|
|
262
269
|
|
|
@@ -266,11 +273,11 @@ module PostgresModule {
|
|
|
266
273
|
if (Array.isArray(input)) {
|
|
267
274
|
const responses = []
|
|
268
275
|
for (let query of input) {
|
|
269
|
-
responses.push(await internalQuery(
|
|
276
|
+
responses.push(await this.internalQuery(query))
|
|
270
277
|
}
|
|
271
278
|
return responses
|
|
272
279
|
} else {
|
|
273
|
-
const response = await internalQuery(
|
|
280
|
+
const response = await this.internalQuery(input)
|
|
274
281
|
return response.rows.length ? response.rows : [{ [operation]: true }]
|
|
275
282
|
}
|
|
276
283
|
}
|