Additional Information for Node.js

This section covers these topics:

Type Mappings for Node.js Applications

There are mappings between node-oracledb types (as available through the language module) and TimesTen SQL types

Note:

Additional TimesTen SQL types can be mapped to these Oracle Database types and node-oracledb alias types as a result of TimesTen implicit data type conversions. See Data Type Conversion in Oracle TimesTen In-Memory Database SQL Reference.

For the latest information about data type support in the current release, refer to the README.md file at TimesTen Node.js Samples.

Table 4-1 Type Mappings for node-oracledb

Node.js Type Oracle Database Type node-oracledb Alias Type TimesTen Type

Number

oracledb.DB_TYPE_BINARY_DOUBLE

N/A

BINARY_DOUBLE

Number

oracledb.DB_TYPE_BINARY_FLOAT

N/A

BINARY_FLOAT

Lob

oracledb.DB_TYPE_BLOB

oracledb.BLOB

BLOB

String

oracledb.DB_TYPE_CHAR

N/A

CHAR

Lob

oracledb.DB_TYPE_CLOB

oracledb.CLOB

CLOB

ResultSet

oracledb.DB_TYPE_CURSOR

oracledb.CURSOR

REF CURSOR

Date

oracledb.DB_TYPE_DATE

oracledb.DATE

DATE

Number

oracledb.DB_TYPE_INTEGER

N/A

NUMBER, TT_BIGINT, TT_INTEGER, TT_SMALLINT, TT_TINYINT

String

oracledb.DB_TYPE_NCHAR

N/A

NCHAR (In TimesTen, this type is UTF-16 only.)

Lob

oracledb.DB_TYPE_NCLOB

oracledb.NCLOB

NCLOB

Number

oracledb.DB_TYPE_NUMBER

oracledb.NUMBER

NUMBER, TT_BIGINT, TT_INTEGER, TT_SMALLINT, TT_TINYINT

String

oracledb.DB_TYPE_NVARCHAR

N/A

NVARCHAR2 (In TimesTen, this type is UTF-16 only.)

Buffer

oracledb.DB_TYPE_RAW

oracledb.BUFFER

BINARY, VARBINARY

String

oracledb.DB_TYPE_ROWID

N/A

ROWID

Date

oracledb.DB_TYPE_TIMESTAMP

N/A

TIMESTAMP, TT_TIMESTAMP

String

oracledb.DB_TYPE_VARCHAR

oracledb.STRING

VARCHAR

Failure Modes for Node.js

There are several failure modes for Node.js.

Be aware of the following:

  • Error messages may differ slightly from those produced by Oracle under the same conditions.

  • For the Node.js method connection.executeMany(), TimesTen ignores the batcherrors option and therefore supports only the default batcherrors=false setting. An error is always returned if any row in the batch encounters an error. (By contrast, Oracle Database supports batcherrors=true, in which case success is always returned if any row in the batch is successful.) Also, against a TimesTen database, if multiple errors are encountered in a batch, TimesTen makes no attempt to order the errors as they would be ordered if encountered against an Oracle database.

Node.js Sample: Connect to TimesTen and Execute SQL

This sample program does the following:

  • Connects to a TimesTen database.

  • Creates a table named employees.

  • Inserts three rows into the table.

  • Selects and displays the rows.

  • Drops the table.

  • Disconnects from the database.

'use strict';
var oracledb = require('oracledb');

oracledb.initOracleClient();

async function run() {

  let connection;

  try {
    connection = await oracledb.getConnection({
      user: 'appuser', 
      password: 'password', 
      connectString: 'localhost/sampledb:timesten_direct'
    });

    let result;

    await connection.execute('CREATE TABLE employees(first_name VARCHAR2(20), last_name VARCHAR2(20))');
    console.log('Table created');
    const values = [['ROBERT', 'ROBERTSON'], ['ANDY', 'ANDREWS'], ['MICHAEL', 'MICHAELSON']];
    await connection.executeMany('INSERT INTO employees VALUES(:1, :2)', values);
    console.log('Inserted', values.length, 'employees into the table');
    result = await connection.execute('SELECT first_name, last_name FROM employees');
    result.rows.forEach(function(row){
      console.log('Selected employee:', row[0], row[1]);
    });
    await connection.execute('DROP TABLE employees');
    console.log('Table dropped');
  }
  catch (err) {
    console.log(err);
  }
  finally {
    if (connection) {
      try {
        connection.close();
        console.log('Connection closed');
      }
      catch (err) { 
        console.log(err);
      }
    }
  }
}

run();

Running this sample program to connect to a TimesTen database should result the following output:

Table created
Inserted 3 employees into the table
Selected employee: ROBERT ROBERTSON
Selected employee: ANDY ANDREWS
Selected employee: MICHAEL MICHAELSON
Table dropped
Connection closed

See Task 4: Configure Connections for TimesTen for information on the Easy Connect method used to connect to the database in the sample program.

Node.js Sample Programs for Download

TimesTen provides sample programs for Node.js through the node-oracledb driver. These sample programs are available at TimesTen Node.js Samples.