Search.../

getExternalDatabaseConnection( )

Developer Preview

Retrieves an external database connection by name.

Admin Method

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

Syntax

function getExternalDatabaseConnection(name: string): Promise<ExternalDatabaseConnection>

getExternalDatabaseConnection Parameters

NAME
TYPE
DESCRIPTION
name
string

Name of the external database connection to retrieve.

Returns

Details of the external database connection requested.

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?

Get an external database connection (dashboard page code)

Copy Code
1import { externalDatabaseConnections } from "wix-data.v2";
2import { elevate } from "wix-auth";
3
4const elevatedGetExternalDbConnection = elevate(externalDatabaseConnections.getExternalDatabaseConnection);
5
6/*
7 * Sample name value: 'ConnectionOne'
8 */
9
10export async function myGetExternalDbConnection (name) {
11 try {
12 const getExternalDbConnectionResponse = await elevatedGetExternalDbConnection(name);
13
14 const connectionSuccessful = getExternalDbConnectionResponse.connectionStatus.successful;
15 const dbEndpoint = getExternalDbConnectionResponse.endpoint;
16
17 console.log(`Retrieved the ${name} external database connection, which is ${connectionSuccessful ? 'successful' : 'unsuccessful'}`);
18 console.log(`It is mounted at ${dbEndpoint}`);
19
20 return getExternalDbConnectionResponse;
21 } catch (error) {
22 console.error(error);
23 // Handle the error
24 }
25}
26
27/* Promise resolves to:
28 *
29 * {
30 * "capabilities": {
31 * "collectionModificationsSupported": true,
32 * "fieldTypes": []
33 * }
34 * "configuration": {
35 * "secretKey": "74dbd6d6-ec5b-4668-8229-c77379bc6431"
36 * },
37 * "connectionStatus": {
38 * "causeOfFailure": "NONE",
39 * "hasCollections": "YES"
40 * "successful": true,
41 * },
42 * "endpoint": "https://example.com/my-external-database",
43 * "name": "connectionOne",
44 * "protocolVersion": "V2"
45 * }
46 */
Get an 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 elevatedGetExternalDbConnection = elevate(externalDatabaseConnections.getExternalDatabaseConnection);
6
7/*
8 * Sample name value: 'ConnectionOne'
9 */
10
11export const myGetExternalDbConnection = webMethod(
12 Permissions.Admin,
13 async (name) => {
14 try {
15 const getExternalDbConnectionResponse = await elevatedGetExternalDbConnection(name);
16
17 const connectionSuccessful = getExternalDbConnectionResponse.connectionStatus.successful;
18 const dbEndpoint = getExternalDbConnectionResponse.endpoint;
19
20 console.log(`Retrieved the ${name} external database connection, which is ${connectionSuccessful ? 'successful' : 'unsuccessful'}`);
21 console.log(`It is mounted at ${dbEndpoint}`);
22
23 return getExternalDbConnectionResponse;
24 } catch (error) {
25 console.error(error);
26 // Handle the error
27 }
28 }
29)
30
31/* Promise resolves to:
32 *
33 * {
34 * "capabilities": {
35 * "collectionModificationsSupported": true,
36 * "fieldTypes": []
37 * }
38 * "configuration": {
39 * "secretKey": "74dbd6d6-ec5b-4668-8229-c77379bc6431"
40 * },
41 * "connectionStatus": {
42 * "causeOfFailure": "NONE",
43 * "hasCollections": "YES"
44 * "successful": true,
45 * },
46 * "endpoint": "https://example.com/my-external-database",
47 * "name": "connectionOne",
48 * "protocolVersion": "V2"
49 * }
50 */