Oracle Cloud Infrastructure (OCI) Globally Distributed Database Client

2.124.0 · active · verified Wed Apr 22

This module, `oci-globallydistributeddatabase`, provides the NodeJS client for interacting with the Oracle Cloud Infrastructure (OCI) Globally Distributed Database Service. It is part of the larger `oci-typescript-sdk` and allows programmatic management of sharded databases, enabling operations like creating, updating, and listing globally distributed database resources within OCI. The current package version is 2.124.0, though the overall OCI SDK has seen rapid development with releases up to 2.130.0, indicating a highly active release cadence (often weekly or bi-weekly patches/minor versions). Key differentiators include deep integration with the OCI ecosystem, comprehensive TypeScript type definitions for robust development, and consistent API patterns across all OCI services supported by the SDK.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to instantiate the `GloballyDistributedDatabaseClient`, configure authentication using the OCI config file, and list sharded databases within a specified OCI compartment.

import { GloballyDistributedDatabaseClient } from 'oci-globallydistributeddatabase';
import * as common from 'oci-common';
import { GloballyDistributedDatabaseRequests } from 'oci-globallydistributeddatabase';

async function listGloballyDistributedDatabases() {
  try {
    // Configure authentication using a config file (typically ~/.oci/config)
    // Ensure your OCI config file is set up with a profile.
    const provider = new common.Auth.ConfigFileAuthenticationDetailsProvider();

    // Initialize the client
    const client = new GloballyDistributedDatabaseClient({ authenticationDetailsProvider: provider });

    // Construct a list request. A compartmentId is typically required for listing resources.
    // Replace 'ocid1.compartment.oc1..aaaa...' with your actual compartment OCID.
    const compartmentId = process.env.OCI_COMPARTMENT_ID ?? 'ocid1.compartment.oc1..examplecompartmentid'; 
    
    const listRequest: GloballyDistributedDatabaseRequests.ListShardedDatabasesRequest = {
      compartmentId: compartmentId,
      limit: 10 // Optional: limit the number of results
    };

    // Make the API call to list sharded databases
    console.log(`Listing sharded databases in compartment: ${compartmentId}...`);
    const response = await client.listShardedDatabases(listRequest);

    // Process the response
    if (response.shardedDatabaseCollection?.items && response.shardedDatabaseCollection.items.length > 0) {
      console.log('Found Sharded Databases:');
      response.shardedDatabaseCollection.items.forEach(db => {
        console.log(`- Name: ${db.displayName}, ID: ${db.id}, Lifecycle State: ${db.lifecycleState}`);
      });
    } else {
      console.log('No sharded databases found in the specified compartment.');
    }
  } catch (error) {
    console.error('Error listing sharded databases:', error);
    // Log specific OCI errors for better debugging
    if (error instanceof common.Error.ServiceError) {
      console.error(`OCI Service Error: ${error.statusCode} - ${error.serviceCode} (${error.errorCode}): ${error.message}`);
    }
    process.exit(1);
  }
}

listGloballyDistributedDatabases();

view raw JSON →