Search.../

updateExternalDatabaseConnection( )

Developer Preview

Updates an external database connection.

Description

An external database collection name must be provided in name. If an existing external database connection is found with the same name, that connection's details are updated. If no external database connection has that name, the request fails.

Note: After an external database connection is updated, it only contains the values provided in the request. All previous values are lost.

Admin Method

This function requires elevated permissions to run. This function is not universal and runs only on the backend.

Syntax

function updateExternalDatabaseConnection(name: string, externalDatabaseConnection: UpdateExternalDatabaseConnection): Promise<ExternalDatabaseConnection>

updateExternalDatabaseConnection Parameters

NAME
TYPE
DESCRIPTION
name
string

Name of the external database connection. An external database connection may connect to one or more external data collections or tables. These are represented as connectionName/dataCollectionId.

externalDatabaseConnection
UpdateExternalDatabaseConnection

Updated external database connection details. The existing connection is replaced with this version.

Returns

Updated external database connection details.

Return Type:

Promise<
ExternalDatabaseConnection
>
NAME
TYPE
DESCRIPTION
capabilities
Capabilities

The external database's capabilities.

configuration
Object

Settings passed to the external database connection as part of each request. These settings can relate to authentication, tenancy, or provide any other information needed for processing a request. Their content and structure depend on the specific requirements of the external database's API.

connectionStatus
ConnectionStatus

Status of the external database connection. Includes whether the connection was established successfully, and if not, the reason for the failure.

endpoint
string

Base URL for provisioning and managing data in the external database. For example: https://example.com/my-external-database.

name
string

Name of the external database connection. An external database connection may connect to one or more external data collections or tables. These are represented as connectionName/dataCollectionId.

Was this helpful?

Update an existing external database connection (dashboard page code)

Copy Code
1import { externalDatabaseConnections } from "wix-data.v2";
2import { elevate } from "wix-auth";
3
4const elevatedUpdateExternalDatabaseConnection = elevate(externalDatabaseConnections.updateExternalDatabaseConnection);
5
6/*
7 * Sample name value: 'connectionOne'
8 *
9 * Sample externalDatabaseConnection object:
10 *
11 * {
12 * capabilities: {
13 * collectionModificationsSupported: false,
14 * fieldTypes: []
15 * },
16 * configuration: {
17 * secretKey: '74dbd6d6-ec5b-4668-8229-c77379bc6431',
18 * username: 'Jane Doe'
19 * },
20 * endpoint: 'https://example.com/my-external-database'
21 * }
22 */
23
24export async function myUpdateExternalDatabaseConnectionFunction(name, externalDatabaseConnection) {
25 try {
26 const updateExternalDatabaseConnectionResponse = await elevatedUpdateExternalDatabaseConnection(name, externalDatabaseConnection);
27
28 console.log(`The ${name} connection was updated with the new values. It is currently mounted at ${updateExternalDatabaseConnectionResponse.endpoint}`);
29
30 return updateExternalDatabaseConnectionResponse;
31 } catch (error) {
32 console.error(error);
33 // Handle the error
34 }
35}
36
37/* Promise resolves to:
38 * {
39 * "capabilities": {
40 * "collectionModificationsSupported": false,
41 * "fieldTypes": []
42 * }
43 * "configuration": {
44 * "secretKey": "74dbd6d6-ec5b-4668-8229-c77379bc6431",
45 * "username": "Jane Doe"
46 * },
47 * "connectionStatus": {
48 * "successful": true,
49 * "causeOfFailure": "NONE",
50 * "hasCollections": "YES"
51 * },
52 * "endpoint": "https://example.com/my-external-database",
53 * "name": "connection1",
54 * "protocolVersion": "<connection-protocol-version>"
55 * }
56 */
Update an existing external database connection (export from backend code)

Copy Code
1import { Permissions, webMethod } from "wix-web-module";
2import { externalDatabaseConnections } from "wix-data.v2";
3import { elevate } from "wix-auth";
4
5const elevatedUpdateExternalDatabaseConnection = elevate(externalDatabaseConnections.updateExternalDatabaseConnection);
6
7/*
8 * Sample name value: 'connectionOne'
9 *
10 * Sample externalDatabaseConnection object:
11 *
12 * {
13 * capabilities: {
14 * collectionModificationsSupported: false,
15 * fieldTypes: []
16 * },
17 * configuration: {
18 * secretKey: '74dbd6d6-ec5b-4668-8229-c77379bc6431',
19 * username: 'Jane Doe'
20 * },
21 * endpoint: 'https://example.com/my-external-database'
22 * }
23 */
24
25export const myUpdateExternalDatabaseConnectionFunction = webMethod(
26 Permissions.Admin,
27 async (name, externalDatabaseConnection) => {
28 try {
29 const updateExternalDatabaseConnectionResponse = await elevatedUpdateExternalDatabaseConnection(name, externalDatabaseConnection);
30
31 console.log(`The ${name} connection was updated with the new values. It is currently mounted at ${updateExternalDatabaseConnectionResponse.endpoint}`);
32
33 return updateExternalDatabaseConnectionResponse;
34 } catch (error) {
35 console.error(error);
36 // Handle the error
37 }
38 }
39)
40
41/* Promise resolves to:
42 * {
43 * "capabilities": {
44 * "collectionModificationsSupported": false,
45 * "fieldTypes": []
46 * }
47 * "configuration": {
48 * "secretKey": "74dbd6d6-ec5b-4668-8229-c77379bc6431",
49 * "username": "Jane Doe"
50 * },
51 * "connectionStatus": {
52 * "successful": true,
53 * "causeOfFailure": "NONE",
54 * "hasCollections": "YES"
55 * },
56 * "endpoint": "https://example.com/my-external-database",
57 * "name": "connection1",
58 * "protocolVersion": "<connection-protocol-version>"
59 * }
60 */