@budibase/server 1.3.21 → 1.3.22-alpha.1
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.96c69636.js +1008 -0
- package/builder/assets/index.c167b5c3.css +6 -0
- package/builder/index.html +2 -4
- package/coverage/clover.xml +308 -338
- package/coverage/coverage-final.json +19 -21
- package/coverage/lcov-report/api/controllers/apikeys.js.html +1 -1
- package/coverage/lcov-report/api/controllers/auth.js.html +41 -8
- 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/datasource.js.html +73 -34
- package/coverage/lcov-report/api/controllers/dev.js.html +1 -1
- package/coverage/lcov-report/api/controllers/index.html +27 -57
- 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/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 +9 -9
- package/coverage/lcov-report/api/routes/utils/validators.js.html +75 -12
- 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 +14 -14
- 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 +30 -18
- 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 +44 -44
- 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 +46 -40
- 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 +15 -15
- 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 +32 -8
- package/coverage/lcov.info +521 -558
- package/dist/api/controllers/application.js +5 -5
- package/dist/api/controllers/auth.js +9 -0
- package/dist/api/controllers/component.js +19 -6
- package/dist/api/controllers/datasource.js +21 -8
- package/dist/api/controllers/deploy/index.js +1 -8
- package/dist/api/controllers/integration.js +4 -4
- package/dist/{migrations/functions/usageQuotas/syncDevelopers.js → api/controllers/plugin/file.js} +13 -13
- package/dist/api/controllers/plugin/github.js +69 -0
- package/dist/api/controllers/plugin/index.js +144 -0
- package/dist/api/controllers/plugin/npm.js +58 -0
- package/dist/api/controllers/plugin/uploaders.js +11 -0
- package/dist/{migrations/functions/usageQuotas/syncPublishedApps.js → api/controllers/plugin/url.js} +13 -15
- package/dist/api/controllers/plugin/utils.js +26 -0
- package/dist/api/controllers/row/external.js +1 -1
- package/dist/api/controllers/screen.js +62 -14
- package/dist/api/controllers/static/index.js +1 -0
- package/dist/api/controllers/static/templates/BudibaseApp.svelte +10 -0
- package/dist/api/controllers/static/templates/preview.hbs +5 -1
- package/dist/api/index.js +1 -1
- package/dist/api/routes/application.js +3 -2
- package/dist/api/routes/index.js +2 -0
- package/dist/{migrations/functions/publishedAppsQuota.js → api/routes/plugin.js} +13 -21
- package/dist/api/routes/public/rows.js +1 -82
- package/dist/api/routes/public/tables.js +1 -1
- package/dist/api/routes/table.js +1 -1
- package/dist/api/routes/utils/validators.js +20 -2
- package/dist/app.js +16 -1
- package/dist/db/utils.js +3 -0
- package/dist/environment.js +1 -0
- package/dist/integrations/airtable.js +126 -129
- package/dist/integrations/arangodb.js +86 -89
- package/dist/integrations/base/query.js +2 -2
- package/dist/integrations/base/sqlTable.js +3 -1
- package/dist/integrations/couchdb.js +80 -83
- package/dist/integrations/dynamodb.js +161 -164
- package/dist/integrations/elasticsearch.js +135 -138
- package/dist/integrations/firebase.js +154 -157
- package/dist/integrations/googlesheets.js +323 -327
- package/dist/integrations/index.js +99 -51
- package/dist/integrations/microsoftSqlServer.js +240 -243
- package/dist/integrations/mongodb.js +239 -242
- package/dist/integrations/mysql.js +215 -219
- package/dist/integrations/oracle.js +318 -322
- package/dist/integrations/postgres.js +262 -265
- package/dist/integrations/redis.js +134 -139
- package/dist/integrations/rest.js +289 -292
- package/dist/integrations/s3.js +61 -64
- package/dist/integrations/snowflake.js +83 -86
- package/dist/middleware/currentapp.js +2 -0
- package/dist/migrations/functions/backfill/global.js +0 -3
- package/dist/migrations/index.js +0 -10
- package/dist/package.json +9 -6
- 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 +105 -1
- package/dist/utilities/workerRequests.js +4 -0
- package/dist/watch.js +77 -0
- package/dist/websocket.js +22 -0
- package/package.json +10 -7
- package/scripts/dev/manage.js +4 -0
- package/scripts/localdomain.js +3 -1
- package/specs/openapi.json +115 -112
- package/specs/openapi.yaml +96 -94
- package/specs/resources/misc.js +116 -0
- package/specs/resources/query.js +1 -1
- package/src/api/controllers/application.ts +1 -2
- package/src/api/controllers/auth.js +11 -0
- package/src/api/controllers/component.ts +57 -0
- package/src/api/controllers/datasource.js +21 -8
- package/src/api/controllers/deploy/index.ts +1 -6
- package/src/api/controllers/integration.js +4 -4
- package/src/api/controllers/plugin/file.ts +15 -0
- package/src/api/controllers/plugin/github.ts +75 -0
- package/src/api/controllers/plugin/index.ts +134 -0
- package/src/api/controllers/plugin/npm.ts +56 -0
- package/src/api/controllers/plugin/uploaders.ts +4 -0
- package/src/api/controllers/plugin/url.ts +12 -0
- package/src/api/controllers/plugin/utils.ts +19 -0
- package/src/api/controllers/public/mapping/types.ts +8 -0
- package/src/api/controllers/row/external.js +1 -1
- package/src/api/controllers/screen.ts +122 -0
- package/src/api/controllers/static/index.ts +1 -1
- package/src/api/controllers/static/templates/BudibaseApp.svelte +10 -0
- package/src/api/controllers/static/templates/preview.hbs +5 -1
- package/src/api/index.js +1 -1
- package/src/api/routes/application.ts +13 -2
- package/src/api/routes/index.ts +2 -0
- package/src/api/routes/plugin.ts +14 -0
- package/src/api/routes/public/rows.ts +1 -82
- 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 +8 -25
- package/src/api/routes/tests/user.spec.js +0 -2
- package/src/api/routes/utils/validators.js +26 -5
- package/src/app.ts +25 -2
- package/src/db/utils.js +4 -0
- package/src/definitions/openapi.ts +56 -55
- package/src/environment.js +1 -0
- package/src/integrations/airtable.ts +116 -118
- package/src/integrations/arangodb.ts +87 -89
- package/src/integrations/base/query.ts +2 -2
- package/src/integrations/base/sqlTable.ts +3 -1
- package/src/integrations/couchdb.ts +83 -89
- package/src/integrations/dynamodb.ts +173 -175
- package/src/integrations/elasticsearch.ts +120 -122
- package/src/integrations/firebase.ts +157 -159
- package/src/integrations/googlesheets.ts +328 -338
- package/src/integrations/index.ts +64 -21
- package/src/integrations/microsoftSqlServer.ts +249 -251
- package/src/integrations/mongodb.ts +261 -258
- package/src/integrations/mysql.ts +229 -234
- package/src/integrations/oracle.ts +373 -380
- package/src/integrations/postgres.ts +264 -268
- package/src/integrations/redis.ts +128 -132
- package/src/integrations/rest.ts +324 -329
- package/src/integrations/s3.ts +68 -71
- package/src/integrations/snowflake.ts +80 -82
- package/src/integrations/tests/{airtable.spec.js → airtable.spec.ts} +21 -18
- package/src/integrations/tests/{arangodb.spec.js → arangodb.spec.ts} +12 -9
- package/src/integrations/tests/{couchdb.spec.js → couchdb.spec.ts} +33 -27
- package/src/integrations/tests/{dynamodb.spec.js → dynamodb.spec.ts} +45 -41
- package/src/integrations/tests/{elasticsearch.spec.js → elasticsearch.spec.ts} +22 -21
- package/src/integrations/tests/{firebase.spec.js → firebase.spec.ts} +33 -28
- package/src/integrations/tests/{microsoftSqlServer.spec.js → microsoftSqlServer.spec.ts} +12 -11
- package/src/integrations/tests/{mongo.spec.js → mongo.spec.ts} +46 -35
- package/src/integrations/tests/{mysql.spec.js → mysql.spec.ts} +17 -15
- package/src/integrations/tests/{oracle.spec.js → oracle.spec.ts} +19 -17
- package/src/integrations/tests/{postgres.spec.js → postgres.spec.ts} +19 -17
- package/src/integrations/tests/{redis.spec.js → redis.spec.ts} +27 -18
- package/src/integrations/tests/{rest.spec.js → rest.spec.ts} +22 -14
- package/src/integrations/tests/{s3.spec.js → s3.spec.ts} +10 -8
- package/src/integrations/tests/{sql.spec.js → sql.spec.ts} +228 -177
- package/src/middleware/currentapp.js +2 -0
- package/src/migrations/functions/backfill/global.ts +0 -3
- package/src/migrations/index.ts +0 -16
- package/src/module.d.ts +2 -0
- package/src/tests/utilities/TestConfiguration.js +1 -1
- package/src/threads/query.ts +2 -2
- package/src/utilities/fileSystem/index.js +123 -0
- package/src/utilities/workerRequests.js +8 -0
- package/src/watch.ts +38 -0
- package/src/websocket.ts +26 -0
- package/builder/assets/index.8d12d461.css +0 -6
- package/builder/assets/index.d354271c.js +0 -879
- package/builder/assets/vendor.5e1fe644.css +0 -1
- package/builder/assets/vendor.67dbd8fa.js +0 -248
- package/coverage/lcov-report/api/controllers/component.js.html +0 -199
- package/coverage/lcov-report/api/controllers/screen.js.html +0 -259
- package/dist/migrations/functions/developerQuota.js +0 -49
- package/src/api/controllers/component.js +0 -38
- package/src/api/controllers/screen.js +0 -58
- package/src/migrations/functions/developerQuota.ts +0 -15
- package/src/migrations/functions/publishedAppsQuota.ts +0 -13
- package/src/migrations/functions/usageQuotas/syncDevelopers.ts +0 -19
- package/src/migrations/functions/usageQuotas/syncPublishedApps.ts +0 -21
|
@@ -19,274 +19,269 @@ import dayjs from "dayjs"
|
|
|
19
19
|
const { NUMBER_REGEX } = require("../utilities")
|
|
20
20
|
import Sql from "./base/sql"
|
|
21
21
|
|
|
22
|
-
|
|
23
|
-
const mysql = require("mysql2/promise")
|
|
22
|
+
const mysql = require("mysql2/promise")
|
|
24
23
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
24
|
+
interface MySQLConfig {
|
|
25
|
+
host: string
|
|
26
|
+
port: number
|
|
27
|
+
user: string
|
|
28
|
+
password: string
|
|
29
|
+
database: string
|
|
30
|
+
ssl?: { [key: string]: any }
|
|
31
|
+
rejectUnauthorized: boolean
|
|
32
|
+
typeCast: Function
|
|
33
|
+
}
|
|
35
34
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
},
|
|
49
|
-
port: {
|
|
50
|
-
type: DatasourceFieldType.NUMBER,
|
|
51
|
-
default: 3306,
|
|
52
|
-
required: false,
|
|
53
|
-
},
|
|
54
|
-
user: {
|
|
55
|
-
type: DatasourceFieldType.STRING,
|
|
56
|
-
default: "root",
|
|
57
|
-
required: true,
|
|
58
|
-
},
|
|
59
|
-
password: {
|
|
60
|
-
type: DatasourceFieldType.PASSWORD,
|
|
61
|
-
default: "root",
|
|
62
|
-
required: true,
|
|
63
|
-
},
|
|
64
|
-
database: {
|
|
65
|
-
type: DatasourceFieldType.STRING,
|
|
66
|
-
required: true,
|
|
67
|
-
},
|
|
68
|
-
ssl: {
|
|
69
|
-
type: DatasourceFieldType.OBJECT,
|
|
70
|
-
required: false,
|
|
71
|
-
},
|
|
72
|
-
rejectUnauthorized: {
|
|
73
|
-
type: DatasourceFieldType.BOOLEAN,
|
|
74
|
-
default: true,
|
|
75
|
-
required: false,
|
|
76
|
-
},
|
|
35
|
+
const SCHEMA: Integration = {
|
|
36
|
+
docs: "https://github.com/sidorares/node-mysql2",
|
|
37
|
+
plus: true,
|
|
38
|
+
friendlyName: "MySQL",
|
|
39
|
+
type: "Relational",
|
|
40
|
+
description:
|
|
41
|
+
"MySQL Database Service is a fully managed database service to deploy cloud-native applications. ",
|
|
42
|
+
datasource: {
|
|
43
|
+
host: {
|
|
44
|
+
type: DatasourceFieldType.STRING,
|
|
45
|
+
default: "localhost",
|
|
46
|
+
required: true,
|
|
77
47
|
},
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
read: {
|
|
83
|
-
type: QueryType.SQL,
|
|
84
|
-
},
|
|
85
|
-
update: {
|
|
86
|
-
type: QueryType.SQL,
|
|
87
|
-
},
|
|
88
|
-
delete: {
|
|
89
|
-
type: QueryType.SQL,
|
|
90
|
-
},
|
|
48
|
+
port: {
|
|
49
|
+
type: DatasourceFieldType.NUMBER,
|
|
50
|
+
default: 3306,
|
|
51
|
+
required: false,
|
|
91
52
|
},
|
|
92
|
-
|
|
53
|
+
user: {
|
|
54
|
+
type: DatasourceFieldType.STRING,
|
|
55
|
+
default: "root",
|
|
56
|
+
required: true,
|
|
57
|
+
},
|
|
58
|
+
password: {
|
|
59
|
+
type: DatasourceFieldType.PASSWORD,
|
|
60
|
+
default: "root",
|
|
61
|
+
required: true,
|
|
62
|
+
},
|
|
63
|
+
database: {
|
|
64
|
+
type: DatasourceFieldType.STRING,
|
|
65
|
+
required: true,
|
|
66
|
+
},
|
|
67
|
+
ssl: {
|
|
68
|
+
type: DatasourceFieldType.OBJECT,
|
|
69
|
+
required: false,
|
|
70
|
+
},
|
|
71
|
+
rejectUnauthorized: {
|
|
72
|
+
type: DatasourceFieldType.BOOLEAN,
|
|
73
|
+
default: true,
|
|
74
|
+
required: false,
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
query: {
|
|
78
|
+
create: {
|
|
79
|
+
type: QueryType.SQL,
|
|
80
|
+
},
|
|
81
|
+
read: {
|
|
82
|
+
type: QueryType.SQL,
|
|
83
|
+
},
|
|
84
|
+
update: {
|
|
85
|
+
type: QueryType.SQL,
|
|
86
|
+
},
|
|
87
|
+
delete: {
|
|
88
|
+
type: QueryType.SQL,
|
|
89
|
+
},
|
|
90
|
+
},
|
|
91
|
+
}
|
|
93
92
|
|
|
94
|
-
|
|
93
|
+
const TimezoneAwareDateTypes = ["timestamp"]
|
|
95
94
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
}
|
|
95
|
+
function bindingTypeCoerce(bindings: any[]) {
|
|
96
|
+
for (let i = 0; i < bindings.length; i++) {
|
|
97
|
+
const binding = bindings[i]
|
|
98
|
+
if (typeof binding !== "string") {
|
|
99
|
+
continue
|
|
100
|
+
}
|
|
101
|
+
const matches = binding.match(NUMBER_REGEX)
|
|
102
|
+
// check if number first
|
|
103
|
+
if (matches && matches[0] !== "" && !isNaN(Number(matches[0]))) {
|
|
104
|
+
bindings[i] = parseFloat(binding)
|
|
105
|
+
}
|
|
106
|
+
// if not a number, see if it is a date - important to do in this order as any
|
|
107
|
+
// integer will be considered a valid date
|
|
108
|
+
else if (/^\d/.test(binding) && dayjs(binding).isValid()) {
|
|
109
|
+
bindings[i] = dayjs(binding).toDate()
|
|
112
110
|
}
|
|
113
|
-
return bindings
|
|
114
111
|
}
|
|
112
|
+
return bindings
|
|
113
|
+
}
|
|
115
114
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
115
|
+
class MySQLIntegration extends Sql implements DatasourcePlus {
|
|
116
|
+
private config: MySQLConfig
|
|
117
|
+
private client: any
|
|
118
|
+
public tables: Record<string, Table> = {}
|
|
119
|
+
public schemaErrors: Record<string, string> = {}
|
|
121
120
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
}
|
|
128
|
-
// make sure this defaults to true
|
|
129
|
-
if (
|
|
130
|
-
config.rejectUnauthorized != null &&
|
|
131
|
-
!config.rejectUnauthorized &&
|
|
132
|
-
config.ssl
|
|
133
|
-
) {
|
|
134
|
-
config.ssl.rejectUnauthorized = config.rejectUnauthorized
|
|
135
|
-
}
|
|
136
|
-
// @ts-ignore
|
|
137
|
-
delete config.rejectUnauthorized
|
|
138
|
-
this.config = {
|
|
139
|
-
...config,
|
|
140
|
-
typeCast: function (field: any, next: any) {
|
|
141
|
-
if (
|
|
142
|
-
field.type == "DATETIME" ||
|
|
143
|
-
field.type === "DATE" ||
|
|
144
|
-
field.type === "TIMESTAMP"
|
|
145
|
-
) {
|
|
146
|
-
return field.string()
|
|
147
|
-
}
|
|
148
|
-
return next()
|
|
149
|
-
},
|
|
150
|
-
}
|
|
121
|
+
constructor(config: MySQLConfig) {
|
|
122
|
+
super(SqlClient.MY_SQL)
|
|
123
|
+
this.config = config
|
|
124
|
+
if (config.ssl && Object.keys(config.ssl).length === 0) {
|
|
125
|
+
delete config.ssl
|
|
151
126
|
}
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
127
|
+
// make sure this defaults to true
|
|
128
|
+
if (
|
|
129
|
+
config.rejectUnauthorized != null &&
|
|
130
|
+
!config.rejectUnauthorized &&
|
|
131
|
+
config.ssl
|
|
132
|
+
) {
|
|
133
|
+
config.ssl.rejectUnauthorized = config.rejectUnauthorized
|
|
155
134
|
}
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
135
|
+
// @ts-ignore
|
|
136
|
+
delete config.rejectUnauthorized
|
|
137
|
+
this.config = {
|
|
138
|
+
...config,
|
|
139
|
+
typeCast: function (field: any, next: any) {
|
|
140
|
+
if (
|
|
141
|
+
field.type == "DATETIME" ||
|
|
142
|
+
field.type === "DATE" ||
|
|
143
|
+
field.type === "TIMESTAMP"
|
|
144
|
+
) {
|
|
145
|
+
return field.string()
|
|
146
|
+
}
|
|
147
|
+
return next()
|
|
148
|
+
},
|
|
159
149
|
}
|
|
150
|
+
}
|
|
160
151
|
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
152
|
+
getBindingIdentifier(): string {
|
|
153
|
+
return "?"
|
|
154
|
+
}
|
|
164
155
|
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
156
|
+
getStringConcat(parts: string[]): string {
|
|
157
|
+
return `concat(${parts.join(", ")})`
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
async connect() {
|
|
161
|
+
this.client = await mysql.createConnection(this.config)
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
async disconnect() {
|
|
165
|
+
await this.client.end()
|
|
166
|
+
}
|
|
168
167
|
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
168
|
+
async internalQuery(
|
|
169
|
+
query: SqlQuery,
|
|
170
|
+
opts: { connect?: boolean; disableCoercion?: boolean } = {
|
|
171
|
+
connect: true,
|
|
172
|
+
disableCoercion: false,
|
|
173
|
+
}
|
|
174
|
+
): Promise<any[] | any> {
|
|
175
|
+
try {
|
|
176
|
+
if (opts?.connect) {
|
|
177
|
+
await this.connect()
|
|
174
178
|
}
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
const response = await this.client.query(query.sql, bindings)
|
|
186
|
-
return response[0]
|
|
187
|
-
} finally {
|
|
188
|
-
if (opts?.connect) {
|
|
189
|
-
await this.disconnect()
|
|
190
|
-
}
|
|
179
|
+
const baseBindings = query.bindings || []
|
|
180
|
+
const bindings = opts?.disableCoercion
|
|
181
|
+
? baseBindings
|
|
182
|
+
: bindingTypeCoerce(baseBindings)
|
|
183
|
+
// Node MySQL is callback based, so we must wrap our call in a promise
|
|
184
|
+
const response = await this.client.query(query.sql, bindings)
|
|
185
|
+
return response[0]
|
|
186
|
+
} finally {
|
|
187
|
+
if (opts?.connect) {
|
|
188
|
+
await this.disconnect()
|
|
191
189
|
}
|
|
192
190
|
}
|
|
191
|
+
}
|
|
193
192
|
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
193
|
+
async buildSchema(datasourceId: string, entities: Record<string, Table>) {
|
|
194
|
+
const tables: { [key: string]: Table } = {}
|
|
195
|
+
const database = this.config.database
|
|
196
|
+
await this.connect()
|
|
198
197
|
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
198
|
+
try {
|
|
199
|
+
// get the tables first
|
|
200
|
+
const tablesResp = await this.internalQuery(
|
|
201
|
+
{ sql: "SHOW TABLES;" },
|
|
202
|
+
{ connect: false }
|
|
203
|
+
)
|
|
204
|
+
const tableNames = tablesResp.map(
|
|
205
|
+
(obj: any) =>
|
|
206
|
+
obj[`Tables_in_${database}`] ||
|
|
207
|
+
obj[`Tables_in_${database.toLowerCase()}`]
|
|
208
|
+
)
|
|
209
|
+
for (let tableName of tableNames) {
|
|
210
|
+
const primaryKeys = []
|
|
211
|
+
const schema: TableSchema = {}
|
|
212
|
+
const descResp = await this.internalQuery(
|
|
213
|
+
{ sql: `DESCRIBE \`${tableName}\`;` },
|
|
203
214
|
{ connect: false }
|
|
204
215
|
)
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
)
|
|
210
|
-
for (let tableName of tableNames) {
|
|
211
|
-
const primaryKeys = []
|
|
212
|
-
const schema: TableSchema = {}
|
|
213
|
-
const descResp = await this.internalQuery(
|
|
214
|
-
{ sql: `DESCRIBE \`${tableName}\`;` },
|
|
215
|
-
{ connect: false }
|
|
216
|
-
)
|
|
217
|
-
for (let column of descResp) {
|
|
218
|
-
const columnName = column.Field
|
|
219
|
-
if (
|
|
220
|
-
column.Key === "PRI" &&
|
|
221
|
-
primaryKeys.indexOf(column.Key) === -1
|
|
222
|
-
) {
|
|
223
|
-
primaryKeys.push(columnName)
|
|
224
|
-
}
|
|
225
|
-
const constraints = {
|
|
226
|
-
presence: column.Null !== "YES",
|
|
227
|
-
}
|
|
228
|
-
const isAuto: boolean =
|
|
229
|
-
typeof column.Extra === "string" &&
|
|
230
|
-
(column.Extra === "auto_increment" ||
|
|
231
|
-
column.Extra.toLowerCase().includes("generated"))
|
|
232
|
-
schema[columnName] = {
|
|
233
|
-
name: columnName,
|
|
234
|
-
autocolumn: isAuto,
|
|
235
|
-
constraints,
|
|
236
|
-
...convertSqlType(column.Type),
|
|
237
|
-
externalType: column.Type,
|
|
238
|
-
}
|
|
216
|
+
for (let column of descResp) {
|
|
217
|
+
const columnName = column.Field
|
|
218
|
+
if (column.Key === "PRI" && primaryKeys.indexOf(column.Key) === -1) {
|
|
219
|
+
primaryKeys.push(columnName)
|
|
239
220
|
}
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
221
|
+
const constraints = {
|
|
222
|
+
presence: column.Null !== "YES",
|
|
223
|
+
}
|
|
224
|
+
const isAuto: boolean =
|
|
225
|
+
typeof column.Extra === "string" &&
|
|
226
|
+
(column.Extra === "auto_increment" ||
|
|
227
|
+
column.Extra.toLowerCase().includes("generated"))
|
|
228
|
+
schema[columnName] = {
|
|
229
|
+
name: columnName,
|
|
230
|
+
autocolumn: isAuto,
|
|
231
|
+
constraints,
|
|
232
|
+
...convertSqlType(column.Type),
|
|
233
|
+
externalType: column.Type,
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
if (!tables[tableName]) {
|
|
237
|
+
tables[tableName] = {
|
|
238
|
+
_id: buildExternalTableId(datasourceId, tableName),
|
|
239
|
+
primary: primaryKeys,
|
|
240
|
+
name: tableName,
|
|
241
|
+
schema,
|
|
247
242
|
}
|
|
248
243
|
}
|
|
249
|
-
} finally {
|
|
250
|
-
await this.disconnect()
|
|
251
244
|
}
|
|
252
|
-
|
|
253
|
-
this.
|
|
254
|
-
this.schemaErrors = final.errors
|
|
245
|
+
} finally {
|
|
246
|
+
await this.disconnect()
|
|
255
247
|
}
|
|
248
|
+
const final = finaliseExternalTables(tables, entities)
|
|
249
|
+
this.tables = final.tables
|
|
250
|
+
this.schemaErrors = final.errors
|
|
251
|
+
}
|
|
256
252
|
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
253
|
+
async create(query: SqlQuery | string) {
|
|
254
|
+
const results = await this.internalQuery(getSqlQuery(query))
|
|
255
|
+
return results.length ? results : [{ created: true }]
|
|
256
|
+
}
|
|
261
257
|
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
258
|
+
async read(query: SqlQuery | string) {
|
|
259
|
+
return this.internalQuery(getSqlQuery(query))
|
|
260
|
+
}
|
|
265
261
|
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
262
|
+
async update(query: SqlQuery | string) {
|
|
263
|
+
const results = await this.internalQuery(getSqlQuery(query))
|
|
264
|
+
return results.length ? results : [{ updated: true }]
|
|
265
|
+
}
|
|
270
266
|
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
267
|
+
async delete(query: SqlQuery | string) {
|
|
268
|
+
const results = await this.internalQuery(getSqlQuery(query))
|
|
269
|
+
return results.length ? results : [{ deleted: true }]
|
|
270
|
+
}
|
|
275
271
|
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
}
|
|
272
|
+
async query(json: QueryJson) {
|
|
273
|
+
await this.connect()
|
|
274
|
+
try {
|
|
275
|
+
const queryFn = (query: any) =>
|
|
276
|
+
this.internalQuery(query, { connect: false, disableCoercion: true })
|
|
277
|
+
return await this.queryWithReturning(json, queryFn)
|
|
278
|
+
} finally {
|
|
279
|
+
await this.disconnect()
|
|
285
280
|
}
|
|
286
281
|
}
|
|
282
|
+
}
|
|
287
283
|
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
}
|
|
284
|
+
export default {
|
|
285
|
+
schema: SCHEMA,
|
|
286
|
+
integration: MySQLIntegration,
|
|
292
287
|
}
|