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 |
---|---|---|---|
|
|
N/A |
|
|
|
N/A |
|
|
|
|
|
|
|
N/A |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
N/A |
|
|
|
N/A |
|
|
|
|
|
|
|
|
|
|
|
N/A |
|
|
|
|
|
|
|
N/A |
|
|
|
N/A |
|
|
|
|
|
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 thebatcherrors
option and therefore supports only the defaultbatcherrors=false
setting. An error is always returned if any row in the batch encounters an error. (By contrast, Oracle Database supportsbatcherrors=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.