cu8-sequelize-oracle
cu8-sequelize-oracle copied to clipboard
Cannot read property 'getConnection'
When I try to execute a select it marks the following error:
My code is:
var SequelizeMod = require('cu8-sequelize-oracle');
var sequelize = new SequelizeMod('xe', 'test', 'test', {
host: 'xxx.xxx.xxx.xxx',
database: 'xe',
username: 'test',
password: 'test',
port: '1521',
pool: {
maxConnections: 5,
maxIdleTime: 3000
},
dialect: 'oracle',
});
var Project = sequelize.define('project', {
title: SequelizeMod.STRING,
description: SequelizeMod.STRING
})
var models = {
project: Project,
};
models.project.findAll({})
.then(function(res, err) {
console.log(res, err)
})
======================================= When I test with native oracledb, everything works fine
var dbConfig = {
user : 'test',
password : 'test',
connectString : 'xxx.xxx.xxx.xxx/xe',
externalAuth : false
};
var oracledb = require('oracledb');
oracledb.getConnection(
{
user : dbConfig.user,
password : dbConfig.password,
connectString : dbConfig.connectString
},
function(err, connection) {
if (err) {
console.error(err.message);
return;
}
console.log('Connection was successful!');
I think the error is that the ConnectionManager.prototype.initPools function of the \cu8-sequelize-oracle\lib\dialects\abstract\connection-manager.js file has a _this.lib.createPool function that does an asynchronous , Then when I try to run findAll, the pool is not yet created, any idea how to solve this?
Here is the solution or rather workaround I believe: https://github.com/nhuanhoangduc/cu8-sequelize-oracle/pull/5
Still not working ! Updated for last version ! This error: (node:16200) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'getConnection' of undefined at D:\licenca\myapp\node_modules\cu8-sequelize-oracle\lib\dialects\abstract\connection-manager.js:73:19
Still not working, too
i installed [email protected], but the fix code doens't be included in this version. Please release new version...(This Problem is fatal)
I leave temporary solution here(Written by rpavez Rodrigo on cu8-sequelize-oracle Contributor)
- Open your node.js project folder.
- Go to ./node_modules/cu8-sequelize-oracle/lib/dialects/abstract/connection-manager.js
- Replace the ConnectionManager.prototype.getConnection function to this code
ConnectionManager.prototype.getConnection = function(options) {
var self = this;
options = options || {};
// this.pool._logStats();
function checkIfPoolDefined(callback) {
if(self.pool) {
{ callback() }
}
else {
console.log("Waiting for pool...")
setTimeout(function() {
checkIfPoolDefined(callback);
}, 250);
}
}
return new Promise(function(resolve, reject) {
checkIfPoolDefined(function() {
self.pool.getConnection((err, connection) => {
if (err) {
reject(err);
return;
}
resolve(connection);
});
})
});
};