Oracle NoSQL Database Node.js Driver

5.5.3 · active · verified Wed Apr 22

The `oracle-nosqldb` package provides the Node.js SDK for interacting with Oracle NoSQL Database, supporting both the Oracle NoSQL Database Cloud Service and on-premise deployments. Currently at version 5.5.3, the library offers comprehensive interfaces for developing JavaScript and TypeScript applications, enabling operations like table creation, data insertion, retrieval, and schema management. While a strict release cadence isn't specified, it appears to follow major Node.js ecosystem updates and NoSQL database feature releases. A key differentiator is its dual support for cloud and and on-premise environments, offering a consistent API across deployment models. Developers need Node.js 12 or higher, and for TypeScript projects, TypeScript 5.0.x or higher is recommended.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates creating a table, inserting a record using `put()`, retrieving it with `get()`, and finally dropping the table. It provides configuration placeholders for both Oracle NoSQL Database Cloud Service and on-premise/simulator environments.

/*
 * A simple example that
 *   - creates a table
 *   - inserts a row using the put() operation
 *   - reads a row using the get() operation
 *   - drops the table
 *
 * To run:
 *  1. Edit for your target environment and credentials
 *  2. Run it:
 *       node quickstart.js cloud|cloudsim|kvstore
 *
 *  Use 'cloud' for the Oracle NoSQL Database Cloud Service
 *  Use 'cloudsim' for the Oracle NoSQL Cloud Simulator
 *  Use 'kvstore' for the Oracle NoSQL Database on-premise
 */
'use strict';

const NoSQLClient = require('oracle-nosqldb').NoSQLClient;
const Region = require('oracle-nosqldb').Region;
const ServiceType = require('oracle-nosqldb').ServiceType;

// --- Configuration (replace with your actual credentials and endpoint) ---
// For Oracle NoSQL Database Cloud Service:
// const config = {
//   serviceType: ServiceType.CLOUD,
//   region: Region.US_PHOENIX_1, // e.g., Region.US_PHOENIX_1
//   auth: {
//     userName: process.env.OCI_USER_OCID ?? '',
//     tenantId: process.env.OCI_TENANT_OCID ?? '',
//     privateKey: process.env.OCI_PRIVATE_KEY_PATH ?? '',
//     fingerprint: process.env.OCI_FINGERPRINT ?? '',
//     passPhrase: process.env.OCI_PRIVATE_KEY_PASSPHRASE ?? '' // Optional
//   }
// };

// For Oracle NoSQL Cloud Simulator or On-Premise:
const config = {
  serviceType: ServiceType.KVSTORE,
  endpoint: process.env.NOSQL_ENDPOINT ?? 'localhost:8080' // Default for simulator/on-prem
};

async function runQuickstart() {
  let client;
  try {
    client = new NoSQLClient(config);
    const tableName = 'quickstartTable';

    console.log(`Creating table: ${tableName}`);
    await client.tableDDL(`CREATE TABLE ${tableName} (id LONG, name STRING, PRIMARY KEY (id))`);
    console.log('Table created.');

    const row = { id: 1, name: 'Hello, Oracle NoSQL!' };
    console.log(`Putting row: ${JSON.stringify(row)}`);
    await client.put(tableName, row);
    console.log('Row put.');

    console.log(`Getting row with id: ${row.id}`);
    const result = await client.get(tableName, { id: row.id });
    console.log(`Got row: ${JSON.stringify(result.value)}`);

    console.log(`Dropping table: ${tableName}`);
    await client.tableDDL(`DROP TABLE ${tableName}`);
    console.log('Table dropped.');

  } catch (error) {
    console.error('Error:', error.message);
  } finally {
    if (client) {
      client.close();
    }
  }
}

runQuickstart();

view raw JSON →