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

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