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

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 */