Skip to content

Commit

Permalink
Upgrade to oracledb 2.x
Browse files Browse the repository at this point in the history
  • Loading branch information
raymondfeng committed May 23, 2018
1 parent 1ff5aee commit 226f0fd
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 50 deletions.
46 changes: 12 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,17 @@ For more information, see the <a href="http://loopback.io/doc/en/lb3/Oracle-conn

## Prerequisites

**Node.js**: The Oracle connector requires Node.js version 4.x or 6.x.
**Node.js**: The Oracle connector requires Node.js version 6.x and up.

**Windows**: On 32-bit Windows systems, you must use the 32-bit version of Node.js. On 64-bit Windows systems, you must use the 64-bit version of Node.js. For more information, see [Node-oracledb Installation on Windows](https://github.com/oracle/node-oracledb/blob/master/INSTALL.md#-7-node-oracledb-installation-on-windows).

**Oracle**: The Oracle connector requires Oracle client libraries 11.2+ and can connect to Oracle Database Server 9.2+.

## Installation

Before installing this module, please follow instructions at https://oracle.github.io/node-oracledb/INSTALL.html
to make sure all the prerequisites are satisfied.

In your application root directory, enter this command to install the connector:

```shell
Expand All @@ -24,31 +27,6 @@ $ npm install loopback-connector-oracle --save

If you create a Oracle data source using the data source generator as described below, you don’t have to do this, since the generator will run npm install for you.

See [Installing the Oracle connector](http://loopback.io/doc/en/lb3/Installing-the-Oracle-connector.html) for further installation instructions.

To simplify the installation of [node-oracledb](https://github.com/oracle/node-oracledb) module and Oracle instant clients, use [loopback-oracle-installer](https://github.com/strongloop/loopback-oracle-installer) as a dependency to install and configure `node-oracledb` (oracledb) upon `npm install`.

Use the `config.oracleUrl` property to define the base URL to download the corresponding node-oracle (oracledb) bundle for the local environment.

The bundle file name is `loopback-oracle-<platform>-<arch>-<version>.tar.gz`. The `version` is the same as the `version` in package.json.

```javascript
"dependencies": {
"loopback-oracle-installer": "git+ssh://git@github.com:strongloop/loopback-oracle-installer.git",
...
},
"config": {
"oracleUrl": "http://7e9918db41dd01dbf98e-ec15952f71452bc0809d79c86f5751b6.r22.cf1.rackcdn.com"
},
...
```

You can override the `oracleUrl` setting with the LOOPBACK_ORACLE_URL environment variable.

For example, the full URL for v1.5.0 for MacOSX is:

http://7e9918db41dd01dbf98e-ec15952f71452bc0809d79c86f5751b6.r22.cf1.rackcdn.com/loopback-oracle-MacOSX-x64-1.5.0.tar.gz

The `libaio` library is required on Linux systems:

On Ubuntu/Debian, get it with this command:
Expand All @@ -65,7 +43,7 @@ sudo yum install libaio

## Creating an Oracle data source

Use the [Data source generator](http://loopback.io/doc/en/lb3/Data-source-generator.html) to add a Oracle data source to your application.
Use the [Data source generator](http://loopback.io/doc/en/lb3/Data-source-generator.html) to add a Oracle data source to your application.
The generator will prompt for the database server hostname, port, and other settings
required to connect to a Oracle database. It will also run the `npm install` command above for you.

Expand All @@ -76,7 +54,7 @@ The entry in the application's `/server/datasources.json` will look like this:
"mydb": {
"name": "mydb",
"connector": "oracle",
"tns": "demo",
"tns": "demo",
"host": "myserver",
"port": 3306,
"database": "mydb",
Expand Down Expand Up @@ -110,7 +88,7 @@ The data source then has the following settings.
<th>Description</th>
</tr>
</thead>
<tbody>
<tbody>
<tr>
<td>host or hostname</td>
<td>String</td>
Expand Down Expand Up @@ -218,7 +196,7 @@ var ds = loopback.createDataSource({
<th>Default value</th>
</tr>
</thead>
<tbody>
<tbody>
<tr>
<td>minConn</td>
<td>Minimum number of connections in the connection pool</td>
Expand Down Expand Up @@ -383,8 +361,8 @@ See [LoopBack types](http://loopback.io/doc/en/lb3/LoopBack-types.html) for de
<th>LoopBack Type</th>
<th>Oracle Type</th>
</tr>
</thead>
<tbody>
</thead>
<tbody>
<tr>
<td>String<br>JSON<br>Text<br>default</td>
<td>VARCHAR2
Expand Down Expand Up @@ -418,8 +396,8 @@ See [LoopBack types](http://loopback.io/doc/en/lb3/LoopBack-types.html) for de
<th>Oracle Type</th>
<th>LoopBack Type</th>
</tr>
</thead>
<tbody>
</thead>
<tbody>
<tr>
<td>CHAR(1)</td>
<td>Boolean</td>
Expand Down
19 changes: 10 additions & 9 deletions lib/oracle.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ exports.initialize = function initializeDataSource(dataSource, callback) {
poolPingInterval: undefined,
poolTimeout: undefined,
prefetchRows: undefined,
fetchArraySize: undefined,
Promise: undefined,
queueRequests: undefined,
queueTimeout: undefined,
Expand All @@ -63,7 +64,7 @@ exports.initialize = function initializeDataSource(dataSource, callback) {
poolTimeout: s.poolTimeout || s.timeout || 60,
autoCommit: s.autoCommit || s.isAutoCommit,
outFormat: oracle.OBJECT,
maxRows: s.maxRows || 100,
maxRows: s.maxRows || 0,
stmtCacheSize: s.stmtCacheSize || 30,
connectionClass: 'loopback-connector-oracle',
};
Expand Down Expand Up @@ -131,9 +132,9 @@ function Oracle(oracle, settings) {
fetchAsString: settings.fetchAsString || [oracle.CLOB],
fetchAsBuffer: settings.fetchAsBuffer || [oracle.BLOB],
lobPrefetchSize: settings.lobPrefetchSize,
maxRows: settings.maxRows,
maxRows: settings.maxRows | 0,
outFormat: oracle.OBJECT,
prefetchRows: settings.prefetchRows,
fetchArraySize: settings.fetchArraySize || settings.prefetchRows,
};
}

Expand Down Expand Up @@ -345,13 +346,13 @@ function dateToOracle(val, dateOnly) {
}

var dateStr = [
val.getFullYear(),
fz(val.getMonth() + 1),
fz(val.getDate()),
val.getUTCFullYear(),
fz(val.getUTCMonth() + 1),
fz(val.getUTCDate()),
].join('-') + ' ' + [
fz(val.getHours()),
fz(val.getMinutes()),
fz(val.getSeconds()),
fz(val.getUTCHours()),
fz(val.getUTCMinutes()),
fz(val.getUTCSeconds()),
].join(':');

if (!dateOnly) {
Expand Down
9 changes: 2 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,19 @@
"Connector"
],
"engines": {
"node": ">=4.0.0"
"node": ">=6.0.0"
},
"main": "index.js",
"scripts": {
"lint": "eslint .",
"test": "mocha --UV_THREADPOOL_SIZE=100 --require test/init/init.js test/*.js",
"posttest": "npm run lint"
},
"config": {
"oracleUrl": "http://7e9918db41dd01dbf98e-ec15952f71452bc0809d79c86f5751b6.r22.cf1.rackcdn.com",
"oracleVersion": "2.1.0",
"driverModule": "oracledb@^1.13.0"
},
"dependencies": {
"async": "^2.1.5",
"debug": "^2.1.1",
"loopback-connector": "^4.0.0",
"loopback-oracle-installer": "~3.0.0",
"oracledb": "^2.2.0",
"strong-globalize": "^2.6.2"
},
"devDependencies": {
Expand Down

0 comments on commit 226f0fd

Please sign in to comment.