Node-oracledb 4.0 release, adding Oracle Advanced Queue API

node-oracledb 4.0 has been released, the Node-oracledb  is Oracle's official release of Oracle's Node.js driver. New features in this version are mainly including query and binding type named Oracle, Oracle Advanced Queuing API. Specific updates are as follows:

Reconstruct

Although the module is still calling the JavaScript wrapper binary layer Oracle client libraries, but now Node.js binary layer of N-API interface instead of  NAN . NAN is initiated Node.js C ++ wrappers for providing portability in updating module V8 engines. Use of N-API interface to update brings a number of benefits:

  • API has its own version of the method of N-API, allows the construction of a node-oracledb binary (each operating system architecture), and may be used later in the current version Node.js
  • npm download package is one-fourth the size of 3.1 package node-oracledb, because the package does not contain every Node.js version of the binary file
  • node-oracledb code is now pure C, rather than C ++, so the C compiler you need to build a module is no longer required to support C ++ 11, which is built on some older environments easier

Oracle supports the type of query and bind named

This makes it a good Node.js a good environment using SQL or PL / SQL user-defined type of environment, or the type used in the process of pre-created as Oracle spatial characteristics used.

For example, create a table and some types:

CREATE TYPE dbharvesttype AS VARRAY(10) OF VARCHAR2(20)
/

CREATE TYPE dbfarmtype AS OBJECT (
   farmername     VARCHAR2(20),
   harvest        dbharvesttype)
/

CREATE TABLE farmtab (id NUMBER, farm dbfarmtype);

In the node-oracledb 4.0, JavaScript objects may be mapped to insert a column farm:

// A JavaScript object automatically mapped to the DBFARMTYPE object.
// The case of the properties matters.
const newFarm = {
  FARMERNAME: 'McDonald',
  HARVEST: [ 'corn', 'wheat', 'barley' ]
};
 
await connection.execute(
  `INSERT INTO farmtab (id, farm) VALUES (:id, :f)`,
  { id: 1,
    f: {
      type: 'DBFARMTYPE', // name of the top level DB type, case sensitive
      val: newFarm
    }
  }
);

FARMTAB query returns a DbObject, it is new in the node-oracledb 4.0:

const result = await connection.execute(`SELECT farm FROM farmtab WHERE id = 1 `);
 
// a DbObject for the named Oracle type:
const farm = result.rows[0][0];
 
// The whole object:
// [MYUSER.DBFARMTYPE] { FARMERNAME: 'MacDonald', HARVEST: [ 'corn', 'wheat', 'barley' ] }
console.log(farm);
 
// Objects can be stringified:
// {"FARMERNAME":"MacDonald","HARVEST":["corn","wheat","barley"]}
console.log(JSON.stringify(farm));
 
// Iterate over the collection:
console.log(farm.FARMERNAME);        // "MacDonald"
for (const crop of farm.HARVEST) {
  console.log(crop);                 // "corn", "wheat", "barley"
}

Oracle Advanced Queuing (AQ)

Oracle Advanced Queuing is a highly scalable and configurable message delivery function of an Oracle database. It interfaces with various languages, a plurality of tools may be integrated in the architecture to send and receive messages. a node-oracledb 4.0 Advanced Queuing API  supports RAW and queue objects, can send and receive character string, or object message buffer.

For example, if the queue is arranged in RAW database, you can send a simple string:

const queue = await connection.getQueue('MYQUEUE');
const messageString = 'This is my message';
await queue.enqOne(messageString);
await connection.commit();

If it is received, another application can be executed:

const queue = await connection.getQueue('MYQUEUE');
const msg = await queue.deqOne();
await connection.commit();
console.log(msg.payload.toString());

Implicit results

This makes the query result set returned from PL / SQL to the node-oracledb easier. For implicit result, no bind variables. Results DBMS_SQL.RETURN_SUPER the new interface allows the cursor to return a result of node-oracledb.

result = await connection.execute(
  `DECLARE
    c1 SYS_REFCURSOR;
    c2 SYS_REFCURSOR;
  BEGIN
 
    OPEN c1 FOR SELECT city, postal_code FROM locations;
    DBMS_SQL.RETURN_RESULT(c1);
 
    OPEN C2 FOR SELECT employee_id, last_name FROM employees;
    DBMS_SQL.RETURN_RESULT(c2);
 
  END;`,
 
  [],   // no binds needed
 
  { resultSet: true }
);
 
// Iterate over all the ResultSets
for (const rs of result.implicitResults) {
  while ((row = await rs.getRow()))
    console.log(row);
  await rs.close();
}

Other changes

  • Type constants and renumber the Oracle database type constants, binding for future enhancements. Be sure to use the constant name in your application, rather than their value
  • New connection.currentSchema property, set the framework for the qualifier in SQL statements used in the qualifier is omitted. This is a change of one kind of session set Current_SCHEMA effective alternative
  • The query output lines extracted as a JavaScript object by setting outFormat
  • Introduces new constants oracledb.OUT_Format_Array and oracledb.OUT_Format_Object, to replace oracledb.OBJECT called oracledb.ARRAY and oracledb.OBJECT, slightly ambiguous

Installation: can be installed from npm node-oracledb version 4.0.4.0 requires Node.js version 8 or higher, for Node.js 8, the minimum patch level is 8.16, for Node.js 10, the minimum patch level is 10.16.

For details, see the release notes

Guess you like

Origin www.oschina.net/news/108529/node-oracledb-4-0-released