@budibase/server 1.3.19-alpha.1 → 1.3.19
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__/mongodb.ts +1 -1
- package/builder/assets/index.9ce4f8c5.css +6 -0
- package/builder/assets/index.a1f7532b.js +876 -0
- package/builder/assets/vendor.5e1fe644.css +1 -0
- package/builder/assets/vendor.67dbd8fa.js +248 -0
- package/builder/index.html +4 -2
- package/coverage/clover.xml +388 -441
- package/coverage/coverage-final.json +20 -20
- package/coverage/lcov-report/api/controllers/apikeys.js.html +1 -1
- package/coverage/lcov-report/api/controllers/auth.js.html +8 -41
- package/coverage/lcov-report/api/controllers/automation.js.html +1 -1
- 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 +11 -68
- package/coverage/lcov-report/api/controllers/datasource.js.html +34 -73
- package/coverage/lcov-report/api/controllers/dev.js.html +1 -1
- package/coverage/lcov-report/api/controllers/index.html +46 -46
- package/coverage/lcov-report/api/controllers/integration.js.html +6 -6
- package/coverage/lcov-report/api/controllers/layout.js.html +1 -1
- package/coverage/lcov-report/api/controllers/metadata.js.html +1 -1
- package/coverage/lcov-report/api/controllers/migrations.js.html +1 -1
- package/coverage/lcov-report/api/controllers/permission.js.html +1 -1
- package/coverage/lcov-report/api/controllers/query/index.html +1 -1
- package/coverage/lcov-report/api/controllers/query/validation.js.html +1 -1
- package/coverage/lcov-report/api/controllers/role.js.html +1 -1
- package/coverage/lcov-report/api/controllers/routing.js.html +1 -1
- package/coverage/lcov-report/api/controllers/row/external.js.html +2 -2
- package/coverage/lcov-report/api/controllers/row/index.html +1 -1
- package/coverage/lcov-report/api/controllers/row/internal.js.html +1 -1
- package/coverage/lcov-report/api/controllers/row/internalSearch.js.html +1 -1
- package/coverage/lcov-report/api/controllers/row/staticFormula.js.html +1 -1
- package/coverage/lcov-report/api/controllers/row/utils.js.html +1 -1
- package/coverage/lcov-report/api/controllers/screen.js.html +12 -207
- package/coverage/lcov-report/api/controllers/script.js.html +1 -1
- package/coverage/lcov-report/api/controllers/table/bulkFormula.js.html +1 -1
- package/coverage/lcov-report/api/controllers/table/external.js.html +1 -1
- package/coverage/lcov-report/api/controllers/table/index.html +1 -1
- package/coverage/lcov-report/api/controllers/table/index.js.html +1 -1
- package/coverage/lcov-report/api/controllers/templates.js.html +1 -1
- package/coverage/lcov-report/api/controllers/user.js.html +1 -1
- package/coverage/lcov-report/api/controllers/view/exporters.js.html +1 -1
- package/coverage/lcov-report/api/controllers/view/index.html +1 -1
- package/coverage/lcov-report/api/controllers/view/index.js.html +1 -1
- package/coverage/lcov-report/api/controllers/view/utils.js.html +1 -1
- package/coverage/lcov-report/api/controllers/view/viewBuilder.js.html +1 -1
- package/coverage/lcov-report/api/controllers/webhook.js.html +1 -1
- package/coverage/lcov-report/api/index.html +1 -1
- package/coverage/lcov-report/api/index.js.html +13 -13
- 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/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 +1 -1
- package/coverage/lcov-report/api/routes/index.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/migrations.js.html +1 -1
- package/coverage/lcov-report/api/routes/permission.js.html +1 -1
- package/coverage/lcov-report/api/routes/query.js.html +1 -1
- 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/screen.js.html +1 -1
- package/coverage/lcov-report/api/routes/script.js.html +1 -1
- package/coverage/lcov-report/api/routes/table.js.html +2 -2
- package/coverage/lcov-report/api/routes/templates.js.html +1 -1
- package/coverage/lcov-report/api/routes/user.js.html +1 -1
- package/coverage/lcov-report/api/routes/utils/index.html +5 -5
- package/coverage/lcov-report/api/routes/utils/validators.js.html +6 -9
- 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 +1 -1
- package/coverage/lcov-report/automations/automationUtils.js.html +1 -1
- package/coverage/lcov-report/automations/bullboard.js.html +1 -1
- package/coverage/lcov-report/automations/index.html +1 -1
- package/coverage/lcov-report/automations/index.js.html +1 -1
- package/coverage/lcov-report/automations/steps/bash.js.html +1 -1
- package/coverage/lcov-report/automations/steps/delay.js.html +1 -1
- package/coverage/lcov-report/automations/steps/discord.js.html +1 -1
- package/coverage/lcov-report/automations/steps/executeQuery.js.html +1 -1
- package/coverage/lcov-report/automations/steps/executeScript.js.html +1 -1
- package/coverage/lcov-report/automations/steps/filter.js.html +1 -1
- package/coverage/lcov-report/automations/steps/index.html +1 -1
- package/coverage/lcov-report/automations/steps/integromat.js.html +1 -1
- package/coverage/lcov-report/automations/steps/loop.js.html +1 -1
- package/coverage/lcov-report/automations/steps/outgoingWebhook.js.html +1 -1
- package/coverage/lcov-report/automations/steps/queryRows.js.html +1 -1
- 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 +1 -1
- package/coverage/lcov-report/automations/steps/zapier.js.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/app.js.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/cron.js.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/index.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/index.js.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/rowDeleted.js.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/rowSaved.js.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/rowUpdated.js.html +1 -1
- package/coverage/lcov-report/automations/triggerInfo/webhook.js.html +1 -1
- package/coverage/lcov-report/automations/triggers.js.html +1 -1
- package/coverage/lcov-report/constants/index.html +1 -1
- package/coverage/lcov-report/constants/index.js.html +1 -1
- 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/inMemoryView.js.html +1 -1
- package/coverage/lcov-report/db/index.html +18 -18
- package/coverage/lcov-report/db/index.js.html +1 -1
- package/coverage/lcov-report/db/linkedRows/LinkController.js.html +1 -1
- package/coverage/lcov-report/db/linkedRows/index.html +1 -1
- package/coverage/lcov-report/db/linkedRows/index.js.html +1 -1
- package/coverage/lcov-report/db/linkedRows/linkUtils.js.html +1 -1
- package/coverage/lcov-report/db/newid.js.html +2 -2
- package/coverage/lcov-report/db/utils.js.html +20 -56
- package/coverage/lcov-report/events/AutomationEmitter.js.html +3 -3
- package/coverage/lcov-report/events/index.html +1 -1
- package/coverage/lcov-report/events/index.js.html +1 -1
- package/coverage/lcov-report/events/utils.js.html +1 -1
- package/coverage/lcov-report/index.html +37 -37
- 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 +1 -1
- package/coverage/lcov-report/middleware/builder.js.html +12 -12
- package/coverage/lcov-report/middleware/currentapp.js.html +40 -46
- package/coverage/lcov-report/middleware/index.html +15 -15
- package/coverage/lcov-report/middleware/joi-validator.js.html +1 -1
- package/coverage/lcov-report/middleware/publicApi.js.html +1 -1
- package/coverage/lcov-report/middleware/resourceId.js.html +7 -7
- package/coverage/lcov-report/middleware/selfhost.js.html +1 -1
- package/coverage/lcov-report/middleware/utils.js.html +2 -2
- package/coverage/lcov-report/utilities/budibaseDir.js.html +3 -3
- package/coverage/lcov-report/utilities/centralPath.js.html +4 -4
- package/coverage/lcov-report/utilities/csvParser.js.html +1 -1
- package/coverage/lcov-report/utilities/global.js.html +16 -16
- package/coverage/lcov-report/utilities/index.html +1 -1
- package/coverage/lcov-report/utilities/index.js.html +24 -24
- package/coverage/lcov-report/utilities/queue/inMemoryQueue.js.html +2 -2
- 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 +1 -1
- package/coverage/lcov-report/utilities/rowProcessor/index.html +1 -1
- package/coverage/lcov-report/utilities/rowProcessor/index.js.html +1 -1
- package/coverage/lcov-report/utilities/rowProcessor/utils.js.html +1 -1
- package/coverage/lcov-report/utilities/scriptRunner.js.html +1 -1
- package/coverage/lcov-report/utilities/security.js.html +2 -2
- 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/rows.js.html +1 -1
- package/coverage/lcov-report/utilities/usageQuota/usageQuoteReset.js.html +1 -1
- package/coverage/lcov-report/utilities/users.js.html +1 -1
- package/coverage/lcov-report/utilities/workerRequests.js.html +1 -1
- package/coverage/lcov.info +667 -780
- package/dist/api/controllers/application.js +5 -5
- package/dist/api/controllers/auth.js +0 -9
- package/dist/api/controllers/component.js +1 -14
- package/dist/api/controllers/datasource.js +8 -21
- package/dist/api/controllers/deploy/index.js +8 -1
- package/dist/api/controllers/integration.js +4 -4
- package/dist/api/controllers/row/external.js +1 -1
- package/dist/api/controllers/screen.js +2 -52
- package/dist/api/controllers/static/index.js +0 -1
- package/dist/api/controllers/static/templates/BudibaseApp.svelte +0 -10
- package/dist/api/controllers/static/templates/preview.hbs +1 -5
- package/dist/api/index.js +1 -1
- package/dist/api/routes/application.js +2 -3
- package/dist/api/routes/index.js +0 -2
- package/dist/api/routes/public/tables.js +1 -1
- package/dist/api/routes/table.js +1 -1
- package/dist/api/routes/utils/validators.js +1 -2
- package/dist/app.js +0 -11
- package/dist/db/utils.js +1 -10
- package/dist/environment.js +0 -1
- package/dist/integrations/airtable.js +129 -126
- package/dist/integrations/arangodb.js +89 -86
- package/dist/integrations/base/query.js +2 -2
- package/dist/integrations/base/sqlTable.js +1 -3
- package/dist/integrations/couchdb.js +83 -80
- package/dist/integrations/dynamodb.js +164 -161
- package/dist/integrations/elasticsearch.js +138 -135
- package/dist/integrations/firebase.js +157 -154
- package/dist/integrations/googlesheets.js +327 -323
- package/dist/integrations/index.js +51 -99
- package/dist/integrations/microsoftSqlServer.js +243 -240
- package/dist/integrations/mongodb.js +242 -239
- package/dist/integrations/mysql.js +219 -215
- package/dist/integrations/oracle.js +322 -318
- package/dist/integrations/postgres.js +265 -262
- package/dist/integrations/redis.js +139 -134
- package/dist/integrations/rest.js +292 -289
- package/dist/integrations/s3.js +64 -61
- package/dist/integrations/snowflake.js +86 -83
- package/dist/middleware/currentapp.js +0 -2
- package/dist/migrations/functions/backfill/global.js +3 -0
- package/dist/migrations/functions/developerQuota.js +49 -0
- package/dist/{api/routes/plugin.js → migrations/functions/publishedAppsQuota.js} +21 -13
- package/dist/{api/controllers/plugin/url.js → migrations/functions/usageQuotas/syncDevelopers.js} +13 -13
- package/dist/{api/controllers/plugin/file.js → migrations/functions/usageQuotas/syncPublishedApps.js} +15 -13
- package/dist/migrations/index.js +10 -0
- package/dist/package.json +6 -9
- package/dist/tests/utilities/TestConfiguration.js +1 -1
- package/dist/threads/query.js +2 -2
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/utilities/fileSystem/index.js +1 -110
- package/package.json +7 -10
- package/scripts/dev/manage.js +0 -1
- package/scripts/localdomain.js +1 -3
- package/specs/openapi.json +3 -3
- package/specs/openapi.yaml +3 -3
- package/specs/resources/query.js +1 -1
- package/src/api/controllers/application.ts +2 -1
- package/src/api/controllers/auth.js +0 -11
- package/src/api/controllers/component.js +2 -21
- package/src/api/controllers/datasource.js +8 -21
- package/src/api/controllers/deploy/index.ts +6 -1
- package/src/api/controllers/integration.js +4 -4
- package/src/api/controllers/row/external.js +1 -1
- package/src/api/controllers/screen.js +1 -66
- package/src/api/controllers/static/index.ts +1 -1
- package/src/api/controllers/static/templates/BudibaseApp.svelte +0 -10
- package/src/api/controllers/static/templates/preview.hbs +1 -5
- package/src/api/index.js +1 -1
- package/src/api/routes/application.ts +2 -13
- package/src/api/routes/index.ts +0 -2
- package/src/api/routes/public/tables.ts +1 -1
- package/src/api/routes/table.js +1 -1
- package/src/api/routes/tests/query.spec.js +25 -8
- package/src/api/routes/tests/user.spec.js +2 -0
- package/src/api/routes/utils/validators.js +1 -2
- package/src/app.ts +0 -14
- package/src/db/utils.js +0 -12
- package/src/definitions/openapi.ts +3 -3
- package/src/environment.js +0 -1
- package/src/integrations/airtable.ts +118 -116
- package/src/integrations/arangodb.ts +89 -87
- package/src/integrations/base/query.ts +2 -2
- package/src/integrations/base/sqlTable.ts +1 -3
- package/src/integrations/couchdb.ts +89 -83
- package/src/integrations/dynamodb.ts +175 -173
- package/src/integrations/elasticsearch.ts +122 -120
- package/src/integrations/firebase.ts +159 -157
- package/src/integrations/googlesheets.ts +338 -328
- package/src/integrations/index.ts +21 -64
- package/src/integrations/microsoftSqlServer.ts +251 -249
- package/src/integrations/mongodb.ts +258 -261
- package/src/integrations/mysql.ts +234 -229
- package/src/integrations/oracle.ts +380 -373
- package/src/integrations/postgres.ts +268 -264
- package/src/integrations/redis.ts +132 -128
- package/src/integrations/rest.ts +329 -324
- package/src/integrations/s3.ts +71 -68
- package/src/integrations/snowflake.ts +82 -80
- package/src/integrations/tests/{airtable.spec.ts → airtable.spec.js} +18 -21
- package/src/integrations/tests/{arangodb.spec.ts → arangodb.spec.js} +9 -12
- package/src/integrations/tests/{couchdb.spec.ts → couchdb.spec.js} +27 -33
- package/src/integrations/tests/{dynamodb.spec.ts → dynamodb.spec.js} +41 -45
- package/src/integrations/tests/{elasticsearch.spec.ts → elasticsearch.spec.js} +21 -22
- package/src/integrations/tests/{firebase.spec.ts → firebase.spec.js} +28 -33
- package/src/integrations/tests/{microsoftSqlServer.spec.ts → microsoftSqlServer.spec.js} +11 -12
- package/src/integrations/tests/{mongo.spec.ts → mongo.spec.js} +35 -46
- package/src/integrations/tests/{mysql.spec.ts → mysql.spec.js} +15 -17
- package/src/integrations/tests/{oracle.spec.ts → oracle.spec.js} +17 -19
- package/src/integrations/tests/{postgres.spec.ts → postgres.spec.js} +17 -19
- package/src/integrations/tests/{redis.spec.ts → redis.spec.js} +18 -27
- package/src/integrations/tests/{rest.spec.ts → rest.spec.js} +14 -22
- package/src/integrations/tests/{s3.spec.ts → s3.spec.js} +8 -10
- package/src/integrations/tests/{sql.spec.ts → sql.spec.js} +177 -228
- package/src/middleware/currentapp.js +0 -2
- package/src/migrations/functions/backfill/global.ts +3 -0
- package/src/migrations/functions/developerQuota.ts +15 -0
- package/src/migrations/functions/publishedAppsQuota.ts +13 -0
- package/src/migrations/functions/usageQuotas/syncDevelopers.ts +19 -0
- package/src/migrations/functions/usageQuotas/syncPublishedApps.ts +21 -0
- package/src/migrations/index.ts +16 -0
- package/src/module.d.ts +0 -2
- package/src/tests/utilities/TestConfiguration.js +1 -1
- package/src/threads/query.ts +2 -2
- package/src/utilities/fileSystem/index.js +0 -129
- package/builder/assets/index.1709d1b3.js +0 -1005
- package/builder/assets/index.8f621053.css +0 -6
- package/dist/api/controllers/plugin/github.js +0 -69
- package/dist/api/controllers/plugin/index.js +0 -200
- package/dist/api/controllers/plugin/npm.js +0 -58
- package/dist/api/controllers/plugin/uploaders.js +0 -11
- package/dist/api/controllers/plugin/utils.js +0 -26
- package/dist/watch.js +0 -77
- package/dist/websocket.js +0 -22
- package/src/api/controllers/plugin/file.ts +0 -15
- package/src/api/controllers/plugin/github.ts +0 -75
- package/src/api/controllers/plugin/index.ts +0 -215
- package/src/api/controllers/plugin/npm.ts +0 -56
- package/src/api/controllers/plugin/uploaders.ts +0 -4
- package/src/api/controllers/plugin/url.ts +0 -12
- package/src/api/controllers/plugin/utils.ts +0 -19
- package/src/api/routes/plugin.ts +0 -14
- package/src/watch.ts +0 -38
- package/src/websocket.ts +0 -26
|
@@ -25,430 +25,437 @@ import oracledb, {
|
|
|
25
25
|
import Sql from "./base/sql"
|
|
26
26
|
import { FieldTypes } from "../constants"
|
|
27
27
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
28
|
+
module OracleModule {
|
|
29
|
+
oracledb.outFormat = oracledb.OUT_FORMAT_OBJECT
|
|
30
|
+
|
|
31
|
+
interface OracleConfig {
|
|
32
|
+
host: string
|
|
33
|
+
port: number
|
|
34
|
+
database: string
|
|
35
|
+
user: string
|
|
36
|
+
password: string
|
|
37
|
+
}
|
|
37
38
|
|
|
38
|
-
const SCHEMA: Integration = {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
},
|
|
69
|
-
query: {
|
|
70
|
-
create: {
|
|
71
|
-
type: QueryType.SQL,
|
|
39
|
+
const SCHEMA: Integration = {
|
|
40
|
+
docs: "https://github.com/oracle/node-oracledb",
|
|
41
|
+
plus: true,
|
|
42
|
+
friendlyName: "Oracle",
|
|
43
|
+
type: "Relational",
|
|
44
|
+
description:
|
|
45
|
+
"Oracle Database is an object-relational database management system developed by Oracle Corporation",
|
|
46
|
+
datasource: {
|
|
47
|
+
host: {
|
|
48
|
+
type: DatasourceFieldType.STRING,
|
|
49
|
+
default: "localhost",
|
|
50
|
+
required: true,
|
|
51
|
+
},
|
|
52
|
+
port: {
|
|
53
|
+
type: DatasourceFieldType.NUMBER,
|
|
54
|
+
required: true,
|
|
55
|
+
default: 1521,
|
|
56
|
+
},
|
|
57
|
+
database: {
|
|
58
|
+
type: DatasourceFieldType.STRING,
|
|
59
|
+
required: true,
|
|
60
|
+
},
|
|
61
|
+
user: {
|
|
62
|
+
type: DatasourceFieldType.STRING,
|
|
63
|
+
required: true,
|
|
64
|
+
},
|
|
65
|
+
password: {
|
|
66
|
+
type: DatasourceFieldType.PASSWORD,
|
|
67
|
+
required: true,
|
|
68
|
+
},
|
|
72
69
|
},
|
|
73
|
-
|
|
74
|
-
|
|
70
|
+
query: {
|
|
71
|
+
create: {
|
|
72
|
+
type: QueryType.SQL,
|
|
73
|
+
},
|
|
74
|
+
read: {
|
|
75
|
+
type: QueryType.SQL,
|
|
76
|
+
},
|
|
77
|
+
update: {
|
|
78
|
+
type: QueryType.SQL,
|
|
79
|
+
},
|
|
80
|
+
delete: {
|
|
81
|
+
type: QueryType.SQL,
|
|
82
|
+
},
|
|
75
83
|
},
|
|
76
|
-
|
|
77
|
-
type: QueryType.SQL,
|
|
78
|
-
},
|
|
79
|
-
delete: {
|
|
80
|
-
type: QueryType.SQL,
|
|
81
|
-
},
|
|
82
|
-
},
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
const UNSUPPORTED_TYPES = ["BLOB", "CLOB", "NCLOB"]
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* Raw query response
|
|
89
|
-
*/
|
|
90
|
-
interface ColumnsResponse {
|
|
91
|
-
TABLE_NAME: string
|
|
92
|
-
COLUMN_NAME: string
|
|
93
|
-
DATA_TYPE: string
|
|
94
|
-
DATA_DEFAULT: string | null
|
|
95
|
-
COLUMN_ID: number
|
|
96
|
-
CONSTRAINT_NAME: string | null
|
|
97
|
-
CONSTRAINT_TYPE: string | null
|
|
98
|
-
R_CONSTRAINT_NAME: string | null
|
|
99
|
-
SEARCH_CONDITION: string | null
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
/**
|
|
103
|
-
* An oracle constraint
|
|
104
|
-
*/
|
|
105
|
-
interface OracleConstraint {
|
|
106
|
-
name: string
|
|
107
|
-
type: string
|
|
108
|
-
relatedConstraintName: string | null
|
|
109
|
-
searchCondition: string | null
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* An oracle column and it's related constraints
|
|
114
|
-
*/
|
|
115
|
-
interface OracleColumn {
|
|
116
|
-
name: string
|
|
117
|
-
type: string
|
|
118
|
-
default: string | null
|
|
119
|
-
id: number
|
|
120
|
-
constraints: { [key: string]: OracleConstraint }
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
/**
|
|
124
|
-
* An oracle table and it's related columns
|
|
125
|
-
*/
|
|
126
|
-
interface OracleTable {
|
|
127
|
-
name: string
|
|
128
|
-
columns: { [key: string]: OracleColumn }
|
|
129
|
-
}
|
|
84
|
+
}
|
|
130
85
|
|
|
131
|
-
const
|
|
132
|
-
PRIMARY: "P",
|
|
133
|
-
NOT_NULL_OR_CHECK: "C",
|
|
134
|
-
FOREIGN_KEY: "R",
|
|
135
|
-
UNIQUE: "U",
|
|
136
|
-
}
|
|
86
|
+
const UNSUPPORTED_TYPES = ["BLOB", "CLOB", "NCLOB"]
|
|
137
87
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
cols.column_id,
|
|
152
|
-
cons.constraint_name,
|
|
153
|
-
cons.constraint_type,
|
|
154
|
-
cons.r_constraint_name,
|
|
155
|
-
cons.search_condition
|
|
156
|
-
FROM
|
|
157
|
-
user_tables tabs
|
|
158
|
-
JOIN
|
|
159
|
-
user_tab_columns cols
|
|
160
|
-
ON tabs.table_name = cols.table_name
|
|
161
|
-
LEFT JOIN
|
|
162
|
-
user_cons_columns col_cons
|
|
163
|
-
ON cols.column_name = col_cons.column_name
|
|
164
|
-
AND cols.table_name = col_cons.table_name
|
|
165
|
-
LEFT JOIN
|
|
166
|
-
user_constraints cons
|
|
167
|
-
ON col_cons.constraint_name = cons.constraint_name
|
|
168
|
-
AND cons.table_name = cols.table_name
|
|
169
|
-
WHERE
|
|
170
|
-
(cons.status = 'ENABLED'
|
|
171
|
-
OR cons.status IS NULL)
|
|
172
|
-
`
|
|
173
|
-
constructor(config: OracleConfig) {
|
|
174
|
-
super(SqlClient.ORACLE)
|
|
175
|
-
this.config = config
|
|
88
|
+
/**
|
|
89
|
+
* Raw query response
|
|
90
|
+
*/
|
|
91
|
+
interface ColumnsResponse {
|
|
92
|
+
TABLE_NAME: string
|
|
93
|
+
COLUMN_NAME: string
|
|
94
|
+
DATA_TYPE: string
|
|
95
|
+
DATA_DEFAULT: string | null
|
|
96
|
+
COLUMN_ID: number
|
|
97
|
+
CONSTRAINT_NAME: string | null
|
|
98
|
+
CONSTRAINT_TYPE: string | null
|
|
99
|
+
R_CONSTRAINT_NAME: string | null
|
|
100
|
+
SEARCH_CONDITION: string | null
|
|
176
101
|
}
|
|
177
102
|
|
|
178
|
-
|
|
179
|
-
|
|
103
|
+
/**
|
|
104
|
+
* An oracle constraint
|
|
105
|
+
*/
|
|
106
|
+
interface OracleConstraint {
|
|
107
|
+
name: string
|
|
108
|
+
type: string
|
|
109
|
+
relatedConstraintName: string | null
|
|
110
|
+
searchCondition: string | null
|
|
180
111
|
}
|
|
181
112
|
|
|
182
|
-
|
|
183
|
-
|
|
113
|
+
/**
|
|
114
|
+
* An oracle column and it's related constraints
|
|
115
|
+
*/
|
|
116
|
+
interface OracleColumn {
|
|
117
|
+
name: string
|
|
118
|
+
type: string
|
|
119
|
+
default: string | null
|
|
120
|
+
id: number
|
|
121
|
+
constraints: { [key: string]: OracleConstraint }
|
|
184
122
|
}
|
|
185
123
|
|
|
186
124
|
/**
|
|
187
|
-
*
|
|
125
|
+
* An oracle table and it's related columns
|
|
188
126
|
*/
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
127
|
+
interface OracleTable {
|
|
128
|
+
name: string
|
|
129
|
+
columns: { [key: string]: OracleColumn }
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const OracleContraintTypes = {
|
|
133
|
+
PRIMARY: "P",
|
|
134
|
+
NOT_NULL_OR_CHECK: "C",
|
|
135
|
+
FOREIGN_KEY: "R",
|
|
136
|
+
UNIQUE: "U",
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
class OracleIntegration extends Sql implements DatasourcePlus {
|
|
140
|
+
private readonly config: OracleConfig
|
|
141
|
+
private index: number = 1
|
|
142
|
+
|
|
143
|
+
public tables: Record<string, Table> = {}
|
|
144
|
+
public schemaErrors: Record<string, string> = {}
|
|
145
|
+
|
|
146
|
+
private readonly COLUMNS_SQL = `
|
|
147
|
+
SELECT
|
|
148
|
+
tabs.table_name,
|
|
149
|
+
cols.column_name,
|
|
150
|
+
cols.data_type,
|
|
151
|
+
cols.data_default,
|
|
152
|
+
cols.column_id,
|
|
153
|
+
cons.constraint_name,
|
|
154
|
+
cons.constraint_type,
|
|
155
|
+
cons.r_constraint_name,
|
|
156
|
+
cons.search_condition
|
|
157
|
+
FROM
|
|
158
|
+
user_tables tabs
|
|
159
|
+
JOIN
|
|
160
|
+
user_tab_columns cols
|
|
161
|
+
ON tabs.table_name = cols.table_name
|
|
162
|
+
LEFT JOIN
|
|
163
|
+
user_cons_columns col_cons
|
|
164
|
+
ON cols.column_name = col_cons.column_name
|
|
165
|
+
AND cols.table_name = col_cons.table_name
|
|
166
|
+
LEFT JOIN
|
|
167
|
+
user_constraints cons
|
|
168
|
+
ON col_cons.constraint_name = cons.constraint_name
|
|
169
|
+
AND cons.table_name = cols.table_name
|
|
170
|
+
WHERE
|
|
171
|
+
(cons.status = 'ENABLED'
|
|
172
|
+
OR cons.status IS NULL)
|
|
173
|
+
`
|
|
174
|
+
constructor(config: OracleConfig) {
|
|
175
|
+
super(SqlClient.ORACLE)
|
|
176
|
+
this.config = config
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
getBindingIdentifier(): string {
|
|
180
|
+
return `:${this.index++}`
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
getStringConcat(parts: string[]): string {
|
|
184
|
+
return parts.join(" || ")
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* Map the flat tabular columns and constraints data into a nested object
|
|
189
|
+
*/
|
|
190
|
+
private mapColumns(result: Result<ColumnsResponse>): {
|
|
191
|
+
[key: string]: OracleTable
|
|
192
|
+
} {
|
|
193
|
+
const oracleTables: { [key: string]: OracleTable } = {}
|
|
194
|
+
|
|
195
|
+
if (result.rows) {
|
|
196
|
+
result.rows.forEach(row => {
|
|
197
|
+
const tableName = row.TABLE_NAME
|
|
198
|
+
const columnName = row.COLUMN_NAME
|
|
199
|
+
const dataType = row.DATA_TYPE
|
|
200
|
+
const dataDefault = row.DATA_DEFAULT
|
|
201
|
+
const columnId = row.COLUMN_ID
|
|
202
|
+
const constraintName = row.CONSTRAINT_NAME
|
|
203
|
+
const constraintType = row.CONSTRAINT_TYPE
|
|
204
|
+
const relatedConstraintName = row.R_CONSTRAINT_NAME
|
|
205
|
+
const searchCondition = row.SEARCH_CONDITION
|
|
206
|
+
|
|
207
|
+
let table = oracleTables[tableName]
|
|
208
|
+
if (!table) {
|
|
209
|
+
table = {
|
|
210
|
+
name: tableName,
|
|
211
|
+
columns: {},
|
|
212
|
+
}
|
|
213
|
+
oracleTables[tableName] = table
|
|
211
214
|
}
|
|
212
|
-
oracleTables[tableName] = table
|
|
213
|
-
}
|
|
214
215
|
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
216
|
+
let column = table.columns[columnName]
|
|
217
|
+
if (!column) {
|
|
218
|
+
column = {
|
|
219
|
+
name: columnName,
|
|
220
|
+
type: dataType,
|
|
221
|
+
default: dataDefault,
|
|
222
|
+
id: columnId,
|
|
223
|
+
constraints: {},
|
|
224
|
+
}
|
|
225
|
+
table.columns[columnName] = column
|
|
223
226
|
}
|
|
224
|
-
table.columns[columnName] = column
|
|
225
|
-
}
|
|
226
227
|
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
228
|
+
if (constraintName && constraintType) {
|
|
229
|
+
let constraint = column.constraints[constraintName]
|
|
230
|
+
if (!constraint) {
|
|
231
|
+
constraint = {
|
|
232
|
+
name: constraintName,
|
|
233
|
+
type: constraintType,
|
|
234
|
+
relatedConstraintName: relatedConstraintName,
|
|
235
|
+
searchCondition: searchCondition,
|
|
236
|
+
}
|
|
235
237
|
}
|
|
238
|
+
column.constraints[constraintName] = constraint
|
|
236
239
|
}
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
})
|
|
240
|
-
}
|
|
240
|
+
})
|
|
241
|
+
}
|
|
241
242
|
|
|
242
|
-
|
|
243
|
-
|
|
243
|
+
return oracleTables
|
|
244
|
+
}
|
|
244
245
|
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
246
|
+
private static isSupportedColumn(column: OracleColumn) {
|
|
247
|
+
return !UNSUPPORTED_TYPES.includes(column.type)
|
|
248
|
+
}
|
|
248
249
|
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
250
|
+
private static isAutoColumn(column: OracleColumn) {
|
|
251
|
+
return !!(
|
|
252
|
+
column.default && column.default.toLowerCase().includes("nextval")
|
|
253
|
+
)
|
|
254
|
+
}
|
|
254
255
|
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
256
|
+
/**
|
|
257
|
+
* No native boolean in oracle. Best we can do is to check if a manual 1 or 0 number constraint has been set up
|
|
258
|
+
* This matches the default behaviour for generating DDL used in knex.
|
|
259
|
+
*/
|
|
260
|
+
private isBooleanType(column: OracleColumn): boolean {
|
|
261
|
+
return (
|
|
262
|
+
column.type.toLowerCase() === "number" &&
|
|
263
|
+
Object.values(column.constraints).filter(c => {
|
|
264
|
+
if (
|
|
265
|
+
c.type === OracleContraintTypes.NOT_NULL_OR_CHECK &&
|
|
266
|
+
c.searchCondition
|
|
267
|
+
) {
|
|
268
|
+
const condition = c.searchCondition
|
|
269
|
+
.replace(/\s/g, "") // remove spaces
|
|
270
|
+
.replace(/[']+/g, "") // remove quotes
|
|
271
|
+
if (
|
|
272
|
+
condition.includes("in(0,1)") ||
|
|
273
|
+
condition.includes("in(1,0)")
|
|
274
|
+
) {
|
|
275
|
+
return true
|
|
276
|
+
}
|
|
272
277
|
}
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
}
|
|
278
|
+
return false
|
|
279
|
+
}).length > 0
|
|
280
|
+
)
|
|
281
|
+
}
|
|
278
282
|
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
283
|
+
private internalConvertType(column: OracleColumn): { type: string } {
|
|
284
|
+
if (this.isBooleanType(column)) {
|
|
285
|
+
return { type: FieldTypes.BOOLEAN }
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
return convertSqlType(column.type)
|
|
282
289
|
}
|
|
283
290
|
|
|
284
|
-
|
|
285
|
-
|
|
291
|
+
/**
|
|
292
|
+
* Fetches the tables from the oracle table and assigns them to the datasource.
|
|
293
|
+
* @param {*} datasourceId - datasourceId to fetch
|
|
294
|
+
* @param entities - the tables that are to be built
|
|
295
|
+
*/
|
|
296
|
+
async buildSchema(datasourceId: string, entities: Record<string, Table>) {
|
|
297
|
+
const columnsResponse = await this.internalQuery<ColumnsResponse>({
|
|
298
|
+
sql: this.COLUMNS_SQL,
|
|
299
|
+
})
|
|
300
|
+
const oracleTables = this.mapColumns(columnsResponse)
|
|
286
301
|
|
|
287
|
-
|
|
288
|
-
* Fetches the tables from the oracle table and assigns them to the datasource.
|
|
289
|
-
* @param {*} datasourceId - datasourceId to fetch
|
|
290
|
-
* @param entities - the tables that are to be built
|
|
291
|
-
*/
|
|
292
|
-
async buildSchema(datasourceId: string, entities: Record<string, Table>) {
|
|
293
|
-
const columnsResponse = await this.internalQuery<ColumnsResponse>({
|
|
294
|
-
sql: this.COLUMNS_SQL,
|
|
295
|
-
})
|
|
296
|
-
const oracleTables = this.mapColumns(columnsResponse)
|
|
297
|
-
|
|
298
|
-
const tables: { [key: string]: Table } = {}
|
|
299
|
-
|
|
300
|
-
// iterate each table
|
|
301
|
-
Object.values(oracleTables).forEach(oracleTable => {
|
|
302
|
-
let table = tables[oracleTable.name]
|
|
303
|
-
if (!table) {
|
|
304
|
-
table = {
|
|
305
|
-
_id: buildExternalTableId(datasourceId, oracleTable.name),
|
|
306
|
-
primary: [],
|
|
307
|
-
name: oracleTable.name,
|
|
308
|
-
schema: {},
|
|
309
|
-
}
|
|
310
|
-
tables[oracleTable.name] = table
|
|
311
|
-
}
|
|
302
|
+
const tables: { [key: string]: Table } = {}
|
|
312
303
|
|
|
313
|
-
// iterate each
|
|
314
|
-
Object.values(oracleTable
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
const columnName = oracleColumn.name
|
|
323
|
-
let fieldSchema = table.schema[columnName]
|
|
324
|
-
if (!fieldSchema) {
|
|
325
|
-
fieldSchema = {
|
|
326
|
-
autocolumn: OracleIntegration.isAutoColumn(oracleColumn),
|
|
327
|
-
name: columnName,
|
|
328
|
-
...this.internalConvertType(oracleColumn),
|
|
329
|
-
}
|
|
330
|
-
table.schema[columnName] = fieldSchema
|
|
304
|
+
// iterate each table
|
|
305
|
+
Object.values(oracleTables).forEach(oracleTable => {
|
|
306
|
+
let table = tables[oracleTable.name]
|
|
307
|
+
if (!table) {
|
|
308
|
+
table = {
|
|
309
|
+
_id: buildExternalTableId(datasourceId, oracleTable.name),
|
|
310
|
+
primary: [],
|
|
311
|
+
name: oracleTable.name,
|
|
312
|
+
schema: {},
|
|
331
313
|
}
|
|
314
|
+
tables[oracleTable.name] = table
|
|
315
|
+
}
|
|
332
316
|
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
317
|
+
// iterate each column on the table
|
|
318
|
+
Object.values(oracleTable.columns)
|
|
319
|
+
// remove columns that we can't read / save
|
|
320
|
+
.filter(oracleColumn =>
|
|
321
|
+
OracleIntegration.isSupportedColumn(oracleColumn)
|
|
322
|
+
)
|
|
323
|
+
// match the order of the columns in the db
|
|
324
|
+
.sort((c1, c2) => c1.id - c2.id)
|
|
325
|
+
.forEach(oracleColumn => {
|
|
326
|
+
const columnName = oracleColumn.name
|
|
327
|
+
let fieldSchema = table.schema[columnName]
|
|
328
|
+
if (!fieldSchema) {
|
|
329
|
+
fieldSchema = {
|
|
330
|
+
autocolumn: OracleIntegration.isAutoColumn(oracleColumn),
|
|
331
|
+
name: columnName,
|
|
332
|
+
...this.internalConvertType(oracleColumn),
|
|
333
|
+
}
|
|
334
|
+
table.schema[columnName] = fieldSchema
|
|
337
335
|
}
|
|
336
|
+
|
|
337
|
+
// iterate each constraint on the column
|
|
338
|
+
Object.values(oracleColumn.constraints).forEach(
|
|
339
|
+
oracleConstraint => {
|
|
340
|
+
if (oracleConstraint.type === OracleContraintTypes.PRIMARY) {
|
|
341
|
+
table.primary!.push(columnName)
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
)
|
|
338
345
|
})
|
|
339
|
-
|
|
340
|
-
})
|
|
346
|
+
})
|
|
341
347
|
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
348
|
+
const final = finaliseExternalTables(tables, entities)
|
|
349
|
+
this.tables = final.tables
|
|
350
|
+
this.schemaErrors = final.errors
|
|
351
|
+
}
|
|
346
352
|
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
353
|
+
private async internalQuery<T>(query: SqlQuery): Promise<Result<T>> {
|
|
354
|
+
let connection
|
|
355
|
+
try {
|
|
356
|
+
this.index = 1
|
|
357
|
+
connection = await this.getConnection()
|
|
358
|
+
|
|
359
|
+
const options: ExecuteOptions = { autoCommit: true }
|
|
360
|
+
const bindings: BindParameters = query.bindings || []
|
|
361
|
+
|
|
362
|
+
return await connection.execute<T>(query.sql, bindings, options)
|
|
363
|
+
} finally {
|
|
364
|
+
if (connection) {
|
|
365
|
+
try {
|
|
366
|
+
await connection.close()
|
|
367
|
+
} catch (err) {
|
|
368
|
+
console.error(err)
|
|
369
|
+
}
|
|
363
370
|
}
|
|
364
371
|
}
|
|
365
372
|
}
|
|
366
|
-
}
|
|
367
373
|
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
374
|
+
private getConnection = async (): Promise<Connection> => {
|
|
375
|
+
//connectString : "(DESCRIPTION =(ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))(CONNECT_DATA =(SID= ORCL)))"
|
|
376
|
+
const connectString = `${this.config.host}:${this.config.port || 1521}/${
|
|
377
|
+
this.config.database
|
|
378
|
+
}`
|
|
379
|
+
const attributes: ConnectionAttributes = {
|
|
380
|
+
user: this.config.user,
|
|
381
|
+
password: this.config.password,
|
|
382
|
+
connectString,
|
|
383
|
+
}
|
|
384
|
+
return oracledb.getConnection(attributes)
|
|
377
385
|
}
|
|
378
|
-
return oracledb.getConnection(attributes)
|
|
379
|
-
}
|
|
380
386
|
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
+
async create(query: SqlQuery | string): Promise<any[]> {
|
|
388
|
+
const response = await this.internalQuery<any>(getSqlQuery(query))
|
|
389
|
+
return response.rows && response.rows.length
|
|
390
|
+
? response.rows
|
|
391
|
+
: [{ created: true }]
|
|
392
|
+
}
|
|
387
393
|
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
394
|
+
async read(query: SqlQuery | string): Promise<any[]> {
|
|
395
|
+
const response = await this.internalQuery<any>(getSqlQuery(query))
|
|
396
|
+
return response.rows ? response.rows : []
|
|
397
|
+
}
|
|
392
398
|
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
+
async update(query: SqlQuery | string): Promise<any[]> {
|
|
400
|
+
const response = await this.internalQuery(getSqlQuery(query))
|
|
401
|
+
return response.rows && response.rows.length
|
|
402
|
+
? response.rows
|
|
403
|
+
: [{ updated: true }]
|
|
404
|
+
}
|
|
399
405
|
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
+
async delete(query: SqlQuery | string): Promise<any[]> {
|
|
407
|
+
const response = await this.internalQuery(getSqlQuery(query))
|
|
408
|
+
return response.rows && response.rows.length
|
|
409
|
+
? response.rows
|
|
410
|
+
: [{ deleted: true }]
|
|
411
|
+
}
|
|
406
412
|
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
413
|
+
async query(json: QueryJson) {
|
|
414
|
+
const operation = this._operation(json)
|
|
415
|
+
const input = this._query(json, { disableReturning: true })
|
|
416
|
+
if (Array.isArray(input)) {
|
|
417
|
+
const responses = []
|
|
418
|
+
for (let query of input) {
|
|
419
|
+
responses.push(await this.internalQuery(query))
|
|
420
|
+
}
|
|
421
|
+
return responses
|
|
422
|
+
} else {
|
|
423
|
+
// read the row to be deleted up front for the return
|
|
424
|
+
let deletedRows
|
|
425
|
+
if (operation === Operation.DELETE) {
|
|
426
|
+
const queryFn = (query: any) => this.internalQuery(query)
|
|
427
|
+
deletedRows = await this.getReturningRow(queryFn, json)
|
|
428
|
+
}
|
|
423
429
|
|
|
424
|
-
|
|
425
|
-
|
|
430
|
+
// run the query
|
|
431
|
+
const response = await this.internalQuery(input)
|
|
426
432
|
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
} else {
|
|
433
|
-
// get the last row that was updated
|
|
434
|
-
if (
|
|
435
|
-
response.lastRowid &&
|
|
436
|
-
json.endpoint?.entityId &&
|
|
437
|
-
operation !== Operation.DELETE
|
|
438
|
-
) {
|
|
439
|
-
const lastRow = await this.internalQuery({
|
|
440
|
-
sql: `SELECT * FROM \"${json.endpoint.entityId}\" WHERE ROWID = '${response.lastRowid}'`,
|
|
441
|
-
})
|
|
442
|
-
return lastRow.rows
|
|
433
|
+
// get the results or return the created / updated / deleted row
|
|
434
|
+
if (deletedRows?.rows?.length) {
|
|
435
|
+
return deletedRows.rows
|
|
436
|
+
} else if (response.rows?.length) {
|
|
437
|
+
return response.rows
|
|
443
438
|
} else {
|
|
444
|
-
|
|
439
|
+
// get the last row that was updated
|
|
440
|
+
if (
|
|
441
|
+
response.lastRowid &&
|
|
442
|
+
json.endpoint?.entityId &&
|
|
443
|
+
operation !== Operation.DELETE
|
|
444
|
+
) {
|
|
445
|
+
const lastRow = await this.internalQuery({
|
|
446
|
+
sql: `SELECT * FROM \"${json.endpoint.entityId}\" WHERE ROWID = '${response.lastRowid}'`,
|
|
447
|
+
})
|
|
448
|
+
return lastRow.rows
|
|
449
|
+
} else {
|
|
450
|
+
return [{ [operation.toLowerCase()]: true }]
|
|
451
|
+
}
|
|
445
452
|
}
|
|
446
453
|
}
|
|
447
454
|
}
|
|
448
455
|
}
|
|
449
|
-
}
|
|
450
456
|
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
457
|
+
module.exports = {
|
|
458
|
+
schema: SCHEMA,
|
|
459
|
+
integration: OracleIntegration,
|
|
460
|
+
}
|
|
454
461
|
}
|