cu8-sequelize-oracle icon indicating copy to clipboard operation
cu8-sequelize-oracle copied to clipboard

Cannot read property 'getConnection'

Open crlome opened this issue 7 years ago • 4 comments

When I try to execute a select it marks the following error:

image

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!');

crlome avatar Aug 20 '17 01:08 crlome

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?

crlome avatar Aug 20 '17 05:08 crlome

Here is the solution or rather workaround I believe: https://github.com/nhuanhoangduc/cu8-sequelize-oracle/pull/5

vagabondan avatar Nov 14 '17 15:11 vagabondan

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

cgarrotti avatar May 03 '20 18:05 cgarrotti

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)

  1. Open your node.js project folder.
  2. Go to ./node_modules/cu8-sequelize-oracle/lib/dialects/abstract/connection-manager.js
  3. 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);
            });

        })
    });
};

Wonki4 avatar Dec 30 '21 12:12 Wonki4