idb-pconnector
Advanced tools
Comparing version 1.0.4 to 1.0.5
# idb-pconnector change log | ||
# 1.0.5 | ||
Patched `prepareExecute` issue outlined in [#40](https://github.com/IBM/nodejs-idb-pconnector/issues/40) | ||
- do not throw error when passing an object within the params array with value of null | ||
# 1.0.4 | ||
@@ -4,0 +8,0 @@ Patched require issue outlined in issue #32 (#33) |
const { dbconn } = require('idb-connector'); | ||
const Statement = require('./statement'); | ||
@@ -47,4 +48,2 @@ /** | ||
getStatement() { | ||
// eslint-disable-next-line global-require | ||
const Statement = require('./statement'); | ||
return new Statement(this); | ||
@@ -51,0 +50,0 @@ } |
@@ -331,3 +331,3 @@ const { | ||
if (!value) { | ||
if (!value && value !== null) { | ||
throw new Error('The parameter object must define a value property'); | ||
@@ -334,0 +334,0 @@ } |
const { dbstmt, SQL_SUCCESS, SQL_NO_DATA_FOUND } = require('idb-connector'); | ||
const Connection = require('./connection'); | ||
/** | ||
* This function is for internal use within Statement constructor. | ||
* When a connection object is not provided one will be created. | ||
* This behavior is a bit unorthodox and should be deprecated in a later release | ||
* Furthermore the require statement for connection is tucked away in this function \ | ||
* to avoid a circular dependency between connection and statement. | ||
* Another reason why this behavior should be removed in a later release. | ||
* Once deprecated this function can simply be removed. | ||
*/ | ||
function createConnection() { | ||
// eslint-disable-next-line global-require | ||
const Connection = require('./connection'); | ||
return new Connection({ url: '*LOCAL' }); | ||
} | ||
/** | ||
* @class Statement | ||
@@ -11,3 +25,7 @@ * @constructor | ||
class Statement { | ||
constructor(connection = new Connection().connect()) { | ||
constructor(connection) { | ||
if (!connection) { | ||
// eslint-disable-next-line no-param-reassign | ||
connection = createConnection(); | ||
} | ||
this.dbc = connection.dbconn; | ||
@@ -14,0 +32,0 @@ // eslint-disable-next-line new-cap |
{ | ||
"name": "idb-pconnector", | ||
"version": "1.0.4", | ||
"version": "1.0.5", | ||
"description": "Promise based DB2 Connector for IBM i", | ||
@@ -23,3 +23,3 @@ "main": "lib/idb-pconnector.js", | ||
"dependencies": { | ||
"idb-connector": "^1.1.8" | ||
"idb-connector": "^1.2.0" | ||
}, | ||
@@ -26,0 +26,0 @@ "devDependencies": { |
@@ -10,12 +10,28 @@ /* | ||
const { expect } = require('chai'); | ||
const idbp = require('../lib/idb-pconnector'); | ||
const DBPool = require('../lib/dbPool'); | ||
const { | ||
Connection, Statement, IN, OUT, NUMERIC, CHAR, SQL_ATTR_FOR_FETCH_ONLY, | ||
} = idbp; | ||
Connection, Statement, DBPool, IN, OUT, NUMERIC, CHAR, SQL_ATTR_FOR_FETCH_ONLY, NULL, | ||
} = require('../lib/idb-pconnector'); | ||
const lib = 'IDBPTEST'; | ||
const schema = 'IDBPTEST'; | ||
describe('Statement Class Tests', () => { | ||
before('setup schema for tests', async () => { | ||
const pool = new DBPool({ url: '*LOCAL' }, { incrementSize: 2 }); | ||
const createSchema = `CREATE SCHEMA ${schema}`; | ||
const findSchema = `SELECT SCHEMA_NAME FROM qsys2.sysschemas WHERE SCHEMA_NAME = '${schema}'`; | ||
const schemaResult = await pool.runSql(findSchema); | ||
if (!schemaResult.length) { | ||
await pool.runSql(createSchema).catch((error) => { | ||
// eslint-disable-next-line no-console | ||
console.log(`UNABLE TO CREATE ${schema} SCHEMA!`); | ||
throw error; | ||
}); | ||
// eslint-disable-next-line no-console | ||
console.log(`before hook: CREATED ${schema}`); | ||
} | ||
}); | ||
describe('constructor with connection parameter', () => { | ||
@@ -88,2 +104,20 @@ it('creates a new Statement object by passing a connection object', async () => { | ||
describe('bindParams', () => { | ||
before('create table for test', async () => { | ||
const pool = new DBPool({ url: '*LOCAL' }, { incrementSize: 2 }); | ||
const createTable = `CREATE TABLE ${schema}.SCORES(team VARCHAR(100) ALLOCATE(20), score INTEGER)`; | ||
const findTable = `SELECT OBJLONGNAME FROM TABLE (QSYS2.OBJECT_STATISTICS('${schema}', '*FILE')) AS X WHERE OBJLONGNAME = 'SCORES'`; | ||
const tableResult = await pool.runSql(findTable); | ||
if (!tableResult.length) { | ||
await pool.runSql(createTable).catch((error) => { | ||
// eslint-disable-next-line no-console | ||
console.log('Unable to create SCORES table'); | ||
throw error; | ||
}); | ||
// eslint-disable-next-line no-console | ||
console.log('before hook: CREATED SCORES TABLE'); | ||
} | ||
}); | ||
it('associate parameter markers in an SQL to app variables', async () => { | ||
@@ -122,2 +156,17 @@ const sql = 'INSERT INTO QIWS.QCUSTCDT(CUSNUM,LSTNAM,INIT,STREET,CITY,STATE,ZIPCOD,CDTLMT,CHGCOD,BALDUE,CDTDUE) VALUES (?,?,?,?,?,?,?,?,?,?,?) with NONE'; | ||
}); | ||
it('binds a null value, tests issue #40', async () => { | ||
const sql = `INSERT INTO ${schema}.SCORES(TEAM, SCORE) VALUES (?,?)`; | ||
const statement = new Statement(); | ||
const params = [ | ||
['EXAMPLE', IN, CHAR], // TEAM | ||
[null, IN, NULL], // SCORE | ||
]; | ||
await statement.prepare(sql); | ||
await statement.bindParam(params); | ||
await statement.execute(); | ||
}); | ||
}); | ||
@@ -190,18 +239,7 @@ | ||
const pool = new DBPool({ url: '*LOCAL' }); | ||
const findSp = `SELECT OBJLONGNAME FROM TABLE (QSYS2.OBJECT_STATISTICS('${schema}', '*PGM')) AS X`; | ||
const findLib = `SELECT SCHEMA_NAME FROM qsys2.sysschemas WHERE SCHEMA_NAME = '${lib}'`; | ||
const libResult = await pool.runSql(findLib); | ||
if (!libResult.length) { | ||
const createLib = `CRTLIB LIB(${lib}) TYPE(*TEST) TEXT('Used to test Node.js toolkit')`; | ||
// create the library | ||
await pool.prepareExecute('CALL QSYS2.QCMDEXC(?)', [{ value: createLib, io: 'in' }]); | ||
// eslint-disable-next-line no-console | ||
console.log('before hook: Created lib'); | ||
} | ||
const findSp = `SELECT OBJNAME FROM TABLE (QSYS2.OBJECT_STATISTICS('${lib}', '*PGM')) AS X`; | ||
const spResult = await pool.runSql(findSp); | ||
if (!spResult.length) { | ||
const createSP = `CREATE PROCEDURE ${lib}.MAXBAL (OUT OUTPUT DECIMAL(6,2)) | ||
const createSP = `CREATE PROCEDURE ${schema}.MAXBAL (OUT OUTPUT DECIMAL(6,2)) | ||
BEGIN | ||
@@ -213,3 +251,7 @@ DECLARE MAXBAL NUMERIC ( 6 , 2 ) ; | ||
await pool.runSql(createSP); | ||
await pool.runSql(createSP).catch((error) => { | ||
// eslint-disable-next-line no-console | ||
console.log('UNABLE TO CREATE STORED PROCEDURE!'); | ||
throw error; | ||
}); | ||
// eslint-disable-next-line no-console | ||
@@ -226,3 +268,3 @@ console.log('before hook: Created Stored Procedure'); | ||
await statement.prepare(`CALL ${lib}.MAXBAL(?)`); | ||
await statement.prepare(`CALL ${schema}.MAXBAL(?)`); | ||
await statement.bind([[bal, OUT, NUMERIC]]); | ||
@@ -229,0 +271,0 @@ const result = await statement.execute(); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
94567
1792
Updatedidb-connector@^1.2.0