getExternalDatabaseConnection( )
Retrieves an external database connection by name.
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 of the external database connection to retrieve.
Returns
Details of the external database connection requested.
Return Type:
NAME
TYPE
DESCRIPTION
The external database's capabilities.
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.
Status of the external database connection. Includes whether the connection was established successfully, and if not, the reason for the failure.
Base URL for provisioning and managing data in the external database. For example: https://example.com/my-external-database
.
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?
1import { externalDatabaseConnections } from "wix-data.v2";2import { elevate } from "wix-auth";34const elevatedGetExternalDbConnection = elevate(externalDatabaseConnections.getExternalDatabaseConnection);56/*7 * Sample name value: 'ConnectionOne'8 */910export async function myGetExternalDbConnection (name) {11 try {12 const getExternalDbConnectionResponse = await elevatedGetExternalDbConnection(name);1314 const connectionSuccessful = getExternalDbConnectionResponse.connectionStatus.successful;15 const dbEndpoint = getExternalDbConnectionResponse.endpoint;1617 console.log(`Retrieved the ${name} external database connection, which is ${connectionSuccessful ? 'successful' : 'unsuccessful'}`);18 console.log(`It is mounted at ${dbEndpoint}`);1920 return getExternalDbConnectionResponse;21 } catch (error) {22 console.error(error);23 // Handle the error24 }25}2627/* 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 */
1import { Permissions, webMethod } from "wix-web-module";2import { externalDatabaseConnections } from "wix-data.v2";3import { elevate } from "wix-auth";45const elevatedGetExternalDbConnection = elevate(externalDatabaseConnections.getExternalDatabaseConnection);67/*8 * Sample name value: 'ConnectionOne'9 */1011export const myGetExternalDbConnection = webMethod(12 Permissions.Admin,13 async (name) => {14 try {15 const getExternalDbConnectionResponse = await elevatedGetExternalDbConnection(name);1617 const connectionSuccessful = getExternalDbConnectionResponse.connectionStatus.successful;18 const dbEndpoint = getExternalDbConnectionResponse.endpoint;1920 console.log(`Retrieved the ${name} external database connection, which is ${connectionSuccessful ? 'successful' : 'unsuccessful'}`);21 console.log(`It is mounted at ${dbEndpoint}`);2223 return getExternalDbConnectionResponse;24 } catch (error) {25 console.error(error);26 // Handle the error27 }28 }29)3031/* 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 */