OCI Database Tools Service Client for NodeJS

2.130.0 · active · verified Wed Apr 22

The `oci-databasetools` package is the official Oracle Cloud Infrastructure (OCI) NodeJS client for the Database Tools Service. It enables developers to programmatically manage resources within this service, such as database connections, private endpoints, and related configurations. As part of the broader OCI TypeScript SDK, it ships with comprehensive TypeScript type definitions, enhancing developer experience. Currently at version 2.130.0, the package follows a rapid release cadence, often receiving updates weekly or bi-weekly to incorporate new OCI service features and API enhancements. Its key differentiators include direct integration with OCI's authentication mechanisms, adherence to OCI API specifications, and guaranteed compatibility with the latest service functionalities, providing a robust and reliable interface for OCI automation compared to generic HTTP clients.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart initializes the OCI Database Tools client using default authentication, then lists active database tools connections within a specified compartment. It demonstrates basic client instantiation, request creation, and error handling.

import * as common from 'oci-common';
import * as databasetools from 'oci-databasetools';
import * as models from 'oci-databasetools/lib/model';

async function main() {
  try {
    // Configure authentication provider. This will attempt to load configuration
    // from ~/.oci/config (recommended) or environment variables.
    const provider = new common.DefaultAuthenticationDetailsProvider();

    // Create a client for the Database Tools Service
    const client = new databasetools.DatabaseToolsClient({
      authenticationDetailsProvider: provider
    });

    // Replace with your compartment ID (e.g., from environment variable or direct string)
    const compartmentId = process.env.OCI_COMPARTMENT_ID ?? 'ocid1.compartment.oc1..exampleuniqueid';

    console.log(`Listing Database Tools Connections in compartment: ${compartmentId}`);

    const listConnectionsRequest: models.ListDatabaseToolsConnectionsRequest = {
      compartmentId: compartmentId,
      limit: 10, // Limit results for demonstration
      lifecycleState: models.DatabaseToolsConnection.LifecycleState.Active // Filter for active connections
    };

    const response = await client.listDatabaseToolsConnections(listConnectionsRequest);

    if (response.databaseToolsConnectionCollection.items.length > 0) {
      console.log('Found Database Tools Connections:');
      response.databaseToolsConnectionCollection.items.forEach(connection => {
        console.log(`- ${connection.displayName} (ID: ${connection.id}, State: ${connection.lifecycleState})`);
      });
    } else {
      console.log('No active Database Tools Connections found in this compartment.');
    }

  } catch (error) {
    console.error('Error interacting with OCI Database Tools Service:', error);
    if (error instanceof common.errors.ServiceError) {
      console.error(`OCI Service Error: ${error.statusCode} - ${error.serviceCode}`);
      console.error(`Message: ${error.message}`);
    } else if (error instanceof Error) {
      console.error(`General Error: ${error.message}`);
    }
  }
}

main();

view raw JSON →