Skip to content

Commit e9c42f7

Browse files
author
Roman Balayan
committed
Add lib and builds for realease 4.1.0
1 parent 21ba1e9 commit e9c42f7

File tree

16 files changed

+228
-220
lines changed

16 files changed

+228
-220
lines changed

README.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,38 @@
11
# node-oracledb-prebuilt-for-lambda
22

3-
- This module is derived from [node-oracledb-for-lambda](https://github.com/nalbion/node-oracledb-for-lambda).
4-
- Core oracledb libraries are also derived from [node-oracledb](https://github.com/oracle/node-oracledb) v4.0.1
5-
- 4.0.1-10a: Prebuilt for use with AWS Lambda nodejs10.x Runtime (Built using nodejsv10.16.3)
3+
- This module is forked from the currently un-maintained [node-oracledb-for-lambda](https://github.com/nalbion/node-oracledb-for-lambda).
4+
- Core oracledb libraries are also derived from [node-oracledb](https://github.com/oracle/node-oracledb) v4.1.0
5+
- 4.1.0: Prebuilt for use with AWS Lambda nodejs12.x Runtime (Built using nodejsv12.18.3)
66

77
The scripts to reproduce the build process can be found at [node-oracledb-lambda-test](https://github.com/romanbalayan/node-oracledb-lambda-test).
88

99
# Usage
1010

1111
```bash
12-
# nodejs10.x
13-
npm install --save oracledb-prebuilt-for-lambda@4.0.1-10a
12+
npm install --save oracledb-prebuilt-for-lambda@4.1.0
1413
```
1514

1615
# Versioning
17-
- Changed release version based on release of underlying node-oracledb and lambda node runtime version.
18-
- i.e. for nodejs10.x release based on oracledb 4.0.1, release will be 4.0.1-10a.
16+
- Changed release version to match that of underlying node-oracledb version.
17+
- i.e. for release based on oracledb 4.1.0, release will be oracledb-prebuilt-for-lambda@4.1.0
1918

2019

2120
# Releases
22-
| AWS Lambda Runtime | Release |
21+
| node-oracledb | Release |
2322
| ------------------- | ---------- |
24-
| nodejs10.x | 4.0.1-10a |
23+
| 4.0.1 | 1.0.3 |
24+
| 4.1.0 | 4.1.0 |
2525

2626

2727
# AWS Lambda NodeJS Runtimes
2828
https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtimes.html
2929
Data as of Nov 21, 2019
3030

31-
| Name | Identifier | Node.js Version | Operating System |
32-
| ------------- | ---------- | --------------- | ----------------- |
33-
| Node.js 12 | nodejs12.x | 12.13.0 | AWS Linux 2 |
34-
| Node.js 10 | nodejs10.x | 12.13.0 | AWS Linux 2 |
35-
| Node.js 8.10 | nodejs8.10 | 8.10 | AWS Linux |
31+
| Name | Identifier | Operating System |
32+
| ------------- | ---------- | ----------------- |
33+
| Node.js 12 | nodejs12.x | AWS Linux 2 |
34+
| Node.js 10 | nodejs10.x | AWS Linux 2 |
35+
3636

3737

3838
Due to the size of the Oracle libraries, you may need to deploy your zip file to S3 and get Lambda to download from the S3 URL.

build/Release/oracledb.node

6.22 KB
Binary file not shown.

lib/aqQueue.js

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,7 @@ const nodbUtil = require('./util.js');
2626
// Returns a single message from the queue, if one is available.
2727
//-----------------------------------------------------------------------------
2828
function deqOne(cb) {
29-
nodbUtil.assert(arguments.length === 1, 'NJS-009');
30-
nodbUtil.assert(typeof cb === 'function', 'NJS-005', 1);
31-
29+
nodbUtil.checkAsyncArgs(arguments, 1, 1);
3230
this._deqOne(cb);
3331
}
3432

@@ -39,9 +37,8 @@ function deqOne(cb) {
3937
// if any are available.
4038
//----------------------------------------------------------------------------
4139
function deqMany(maxMessages, cb) {
42-
nodbUtil.assert(arguments.length === 2, 'NJS-009');
40+
nodbUtil.checkAsyncArgs(arguments, 2, 2);
4341
nodbUtil.assert(typeof maxMessages === 'number', 'NJS-005', 1);
44-
nodbUtil.assert(typeof cb === 'function', 'NJS-005', 2);
4542

4643
this._deqMany(maxMessages, cb);
4744
}
@@ -52,10 +49,9 @@ function deqMany(maxMessages, cb) {
5249
// Enqueues a single message into the queue.
5350
//-----------------------------------------------------------------------------
5451
function enqOne(message, cb) {
55-
nodbUtil.assert(arguments.length === 2, 'NJS-009');
52+
nodbUtil.checkAsyncArgs(arguments, 2, 2);
5653
nodbUtil.assert(typeof message === 'object' || typeof message === 'string',
5754
'NJS-005', 1);
58-
nodbUtil.assert(typeof cb === 'function', 'NJS-005', 2);
5955

6056
this._enqOne(message, cb);
6157
}
@@ -67,9 +63,8 @@ function enqOne(message, cb) {
6763
// if any are available.
6864
//----------------------------------------------------------------------------
6965
function enqMany(messages, cb) {
70-
nodbUtil.assert(arguments.length === 2, 'NJS-009');
66+
nodbUtil.checkAsyncArgs(arguments, 2, 2);
7167
nodbUtil.assert(Array.isArray(messages), 'NJS-005', 1);
72-
nodbUtil.assert(typeof cb === 'function', 'NJS-005', 2);
7368

7469
this._enqMany(messages, cb);
7570
}

lib/connection.js

Lines changed: 60 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@
2121

2222
const BaseDbObject = require('./dbObject.js');
2323
const EventEmitter = require('events');
24-
const QueryStream = require('./querystream.js');
24+
const QueryStream = require('./queryStream.js');
2525
const nodbUtil = require('./util.js');
26+
const util = require('util');
2627

2728
// fetchRowsToReturn is used to materialize the rows for an execute call using
2829
// the resultSet returned from the C layer.
@@ -73,24 +74,21 @@ function execute(sql, a2, a3, a4) {
7374
let executeCb;
7475
let custExecuteCb;
7576

76-
nodbUtil.assert(arguments.length > 1 && arguments.length < 5, 'NJS-009');
77+
nodbUtil.checkAsyncArgs(arguments, 2, 4);
7778
nodbUtil.assert(typeof sql === 'string', 'NJS-005', 1);
7879

7980
switch (arguments.length) {
8081
case 2:
81-
nodbUtil.assert(typeof a2 === 'function', 'NJS-005', 2);
8282
executeCb = a2;
8383
break;
8484
case 3:
8585
nodbUtil.assert(nodbUtil.isObjectOrArray(a2), 'NJS-005', 2);
86-
nodbUtil.assert(typeof a3 === 'function', 'NJS-005', 3);
8786
binds = a2;
8887
executeCb = a3;
8988
break;
9089
case 4:
9190
nodbUtil.assert(nodbUtil.isObjectOrArray(a2), 'NJS-005', 2);
9291
nodbUtil.assert(nodbUtil.isObject(a3), 'NJS-005', 3);
93-
nodbUtil.assert(typeof a4 === 'function', 'NJS-005', 4);
9492
binds = a2;
9593
executeOpts = a3;
9694
executeCb = a4;
@@ -177,7 +175,7 @@ function executeMany(sql, bindsOrNumIters, a3, a4) {
177175
let executeCb;
178176
let okBinds;
179177

180-
nodbUtil.assert(arguments.length > 2 && arguments.length < 5, 'NJS-009');
178+
nodbUtil.checkAsyncArgs(arguments, 3, 4);
181179
nodbUtil.assert(typeof sql === 'string', 'NJS-005', 1);
182180
if (typeof bindsOrNumIters === 'number') {
183181
nodbUtil.assert(Number.isInteger(bindsOrNumIters), 'NJS-005', 2);
@@ -189,12 +187,10 @@ function executeMany(sql, bindsOrNumIters, a3, a4) {
189187

190188
switch (arguments.length) {
191189
case 3:
192-
nodbUtil.assert(typeof a3 === 'function', 'NJS-005', 3);
193190
executeCb = a3;
194191
break;
195192
case 4:
196193
nodbUtil.assert(nodbUtil.isObject(a3), 'NJS-005', 3);
197-
nodbUtil.assert(typeof a4 === 'function', 'NJS-005', 4);
198194
options = a3;
199195
executeCb = a4;
200196
break;
@@ -211,9 +207,8 @@ function executeMany(sql, bindsOrNumIters, a3, a4) {
211207
// first, but if not found, the database is queried and the result is cached
212208
// using the fully qualified name
213209
function getDbObjectClass(name, cb) {
214-
nodbUtil.assert(arguments.length === 2, 'NJS-009');
210+
nodbUtil.checkAsyncArgs(arguments, 2, 2);
215211
nodbUtil.assert(typeof name === 'string', 'NJS-005', 1);
216-
nodbUtil.assert(typeof cb === 'function', 'NJS-005', 2);
217212

218213
// check the cache; if the class is found there, nothing further to do
219214
let cls = this._dbObjectClasses[name];
@@ -228,41 +223,36 @@ function getDbObjectClass(name, cb) {
228223
}
229224

230225
// This getStatementInfo function is just a place holder to allow for easier extension later.
231-
function getStatementInfo(sql, getStatementInfoCb) {
226+
function getStatementInfo(sql, getStatementInfoCb) { //eslint-disable-line
232227
const self = this;
233228

234-
nodbUtil.assert(arguments.length === 2, 'NJS-009');
235-
nodbUtil.assert(typeof getStatementInfoCb === 'function', 'NJS-005', 1);
229+
nodbUtil.checkAsyncArgs(arguments, 2, 2);
236230

237231
self._getStatementInfo.apply(self, arguments);
238232
}
239233

240234
// This commit function is just a place holder to allow for easier extension later.
241-
function commit(commitCb) {
235+
function commit(commitCb) { //eslint-disable-line
242236
const self = this;
243237

244-
nodbUtil.assert(arguments.length === 1, 'NJS-009');
245-
nodbUtil.assert(typeof commitCb === 'function', 'NJS-005', 1);
246-
238+
nodbUtil.checkAsyncArgs(arguments, 1, 1);
247239
self._commit.apply(self, arguments);
248240
}
249241

250242
// This createLob function is just a place holder to allow for easier extension later.
251-
function createLob(type, createLobCb) {
243+
function createLob(type, createLobCb) { //eslint-disable-line
252244
const self = this;
253245

254-
nodbUtil.assert(arguments.length === 2, 'NJS-009');
255-
nodbUtil.assert(typeof createLobCb === 'function', 'NJS-005', 2);
246+
nodbUtil.checkAsyncArgs(arguments, 2, 2);
256247

257248
self._createLob.apply(self, arguments);
258249
}
259250

260251
// This rollback function is just a place holder to allow for easier extension later.
261-
function rollback(rollbackCb) {
252+
function rollback(rollbackCb) { //eslint-disable-line
262253
const self = this;
263254

264-
nodbUtil.assert(arguments.length === 1, 'NJS-009');
265-
nodbUtil.assert(typeof rollbackCb === 'function', 'NJS-005', 1);
255+
nodbUtil.checkAsyncArgs(arguments, 1, 1);
266256

267257
self._rollback.apply(self, arguments);
268258
}
@@ -274,23 +264,25 @@ function close(a1, a2) {
274264
let options = {};
275265
let closeCb;
276266

277-
nodbUtil.assert(arguments.length >= 1 && arguments.length <= 2, 'NJS-009');
267+
nodbUtil.checkAsyncArgs(arguments, 1, 2);
278268

279269
switch (arguments.length) {
280270
case 1:
281-
nodbUtil.assert(typeof a1 === 'function', 'NJS-005', 1);
282271
closeCb = a1;
283272
break;
284273
case 2:
285274
nodbUtil.assert(nodbUtil.isObject(a1), 'NJS-005', 1);
286-
nodbUtil.assert(typeof a2 === 'function', 'NJS-005', 2);
287275
options = a1;
288276
closeCb = a2;
289277
break;
290278
}
291279

292280
self._close(options, function(err) {
293281
if (!err) {
282+
for (const cls of Object.values(this._dbObjectClasses)) {
283+
cls.prototype.constructor = Object;
284+
cls.prototype = null;
285+
}
294286
self.emit('_after_close');
295287
}
296288

@@ -300,11 +292,10 @@ function close(a1, a2) {
300292

301293
// This break function is just a place holder to allow for easier extension later.
302294
// It's attached to the module as break is a reserved word.
303-
module.break = function(breakCb) {
295+
module.break = function(breakCb) { //eslint-disable-line
304296
const self = this;
305297

306-
nodbUtil.assert(arguments.length === 1, 'NJS-009');
307-
nodbUtil.assert(typeof breakCb === 'function', 'NJS-005', 1);
298+
nodbUtil.checkAsyncArgs(arguments, 1, 1);
308299

309300
self._break.apply(self, arguments);
310301
};
@@ -313,7 +304,7 @@ module.break = function(breakCb) {
313304
function changePassword(user, password, newPassword, changePasswordCb) {
314305
const self = this;
315306

316-
nodbUtil.assert(arguments.length === 4, 'NJS-009');
307+
nodbUtil.checkAsyncArgs(arguments, 4, 4);
317308
nodbUtil.assert(typeof user === 'string', 'NJS-005', 1);
318309
nodbUtil.assert(typeof password === 'string', 'NJS-005', 2);
319310
nodbUtil.assert(typeof newPassword === 'string', 'NJS-005', 3);
@@ -326,16 +317,15 @@ function changePassword(user, password, newPassword, changePasswordCb) {
326317
function getQueue(name, a2, a3) {
327318
let options = {};
328319
let queueCb;
329-
nodbUtil.assert(arguments.length >= 2 && arguments.length <= 3, 'NJS-009');
320+
321+
nodbUtil.checkAsyncArgs(arguments, 2, 3);
330322
nodbUtil.assert(typeof name === 'string', 'NJS-005', 1);
331323
switch (arguments.length) {
332324
case 2:
333-
nodbUtil.assert(typeof a2 === 'function', 'NJS-005', 2);
334325
queueCb = a2;
335326
break;
336327
case 3:
337328
nodbUtil.assert(nodbUtil.isObject(a2), 'NJS-005', 2);
338-
nodbUtil.assert(typeof a3 === 'function', 'NJS-005', 3);
339329
options = a2;
340330
queueCb = a3;
341331
break;
@@ -344,12 +334,10 @@ function getQueue(name, a2, a3) {
344334
}
345335

346336
// This ping function is just a place holder to allow for easier extension later.
347-
function ping(pingCb) {
337+
function ping(pingCb) { //eslint-disable-line
348338
const self = this;
349339

350-
nodbUtil.assert(arguments.length === 1, 'NJS-009');
351-
nodbUtil.assert(typeof pingCb === 'function', 'NJS-005', 1);
352-
340+
nodbUtil.checkAsyncArgs(arguments, 1, 1);
353341
self._ping.apply(self, arguments);
354342
}
355343

@@ -358,24 +346,47 @@ function ping(pingCb) {
358346
function subscribe(name, options, subscribeCb) {
359347
const self = this;
360348

361-
nodbUtil.assert(arguments.length == 3, 'NJS-009');
349+
nodbUtil.checkAsyncArgs(arguments, 3, 3);
362350
nodbUtil.assert(typeof name === 'string', 'NJS-005', 1);
363351
nodbUtil.assert(nodbUtil.isObject(options), 'NJS-005', 2);
364-
nodbUtil.assert(typeof subscribeCb === 'function', 'NJS-005', 3);
365352
self._subscribe.call(self, name, options, subscribeCb);
366353
}
367354

368355
// destroy a subscription which was earlier created using subscribe()
369356
function unsubscribe(name, cb) {
370357
const self = this;
371358

372-
nodbUtil.assert(arguments.length == 2, 'NJS-009');
359+
nodbUtil.checkAsyncArgs(arguments, 2, 2);
373360
nodbUtil.assert(typeof name === 'string', 'NJS-005', 1);
374-
nodbUtil.assert(typeof cb === 'function', 'NJS-005', 2);
375361

376362
self._unsubscribe.call(self, name, cb);
377363
}
378364

365+
// build a database object class
366+
function buildDbObjectClass(schema, name, fqn) {
367+
const DbObject = function(initialValue) {
368+
if (this.isCollection) {
369+
const proxy = new Proxy(this, BaseDbObject._collectionProxyHandler);
370+
if (initialValue !== undefined) {
371+
for (let i = 0; i < initialValue.length; i++) {
372+
this.append(initialValue[i]);
373+
}
374+
}
375+
return proxy;
376+
} else if (initialValue !== undefined) {
377+
Object.assign(this, initialValue);
378+
}
379+
};
380+
DbObject.prototype = Object.create(BaseDbObject.prototype);
381+
DbObject.prototype.constructor = DbObject;
382+
DbObject.prototype.schema = schema;
383+
DbObject.prototype.name = name;
384+
DbObject.prototype.fqn = fqn;
385+
DbObject.toString = function() {
386+
return 'DbObjectClass [' + fqn + ']';
387+
};
388+
return DbObject;
389+
}
379390

380391
// define class
381392
class Connection extends EventEmitter {
@@ -409,26 +420,20 @@ class Connection extends EventEmitter {
409420
const fqn = `${schema}.${name}`;
410421
let cls = this._dbObjectClasses[fqn];
411422
if (!cls) {
412-
class DbObject extends BaseDbObject {
413-
get [Symbol.toStringTag]() {
414-
return fqn;
415-
}
416-
}
417-
this._dbObjectClasses[fqn] = cls = DbObject;
418-
cls.prototype.schema = schema;
419-
cls.prototype.name = name;
420-
cls.prototype.fqn = fqn;
421-
cls.toString = function() {
422-
return 'DbObjectClass [' + fqn + ']';
423-
};
423+
cls = buildDbObjectClass(schema, name, fqn);
424+
this._dbObjectClasses[fqn] = cls;
424425
}
425426
return cls;
426427
}
427428

429+
_isDate(val) {
430+
return util.isDate(val);
431+
}
432+
428433
// To obtain a SodaDatabase object (high-level SODA object associated with
429434
// current connection)
430435
getSodaDatabase() {
431-
nodbUtil.assert(arguments.length === 0, 'NJS-009');
436+
nodbUtil.checkArgCount(arguments, 0, 0);
432437
return this._getSodaDatabase();
433438
}
434439

@@ -438,7 +443,7 @@ class Connection extends EventEmitter {
438443
const self = this;
439444
let stream;
440445

441-
nodbUtil.assert(arguments.length > 0 && arguments.length < 4, 'NJS-009');
446+
nodbUtil.checkArgCount(arguments, 1, 3);
442447
nodbUtil.assert(typeof sql === 'string', 'NJS-005', 1);
443448

444449
if (binding) {

0 commit comments

Comments
 (0)