nhuanhoangduc / cu8-sequelize-oracle

MIT License
26 stars 24 forks source link

Cannot read property 'getConnection' #7

Open crlome opened 6 years ago

crlome commented 6 years ago

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 commented 6 years ago

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?

vagabondan commented 6 years ago

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

cgarrotti commented 4 years ago

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

Wonki4 commented 2 years ago

Still not working, too

i installed cu8-sequelize-oracle@1.0.5, 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);
            });
    
        })
    });
    };