nhuanhoangduc / cu8-sequelize-oracle

MIT License
26 stars 24 forks source link

Connection example #1

Open keyursakaria opened 8 years ago

keyursakaria commented 8 years ago

var oracledb = require('oracledb'); var Sequelize = require('sequelize-oracle'); var sequelize = new Sequelize('XE', 'system', 'password', { host: 'localhost', dialect: 'oracle', pool: { max: 5, min: 0, idle: 10000 }, });

Above code is what im using to connect to oracle. Can you help me out with this on how to connect

Error im getting :-

Error: timeout of 2000ms exceeded. Check your configuration and your database

rpavez commented 7 years ago

Here's a connection example, it would be great if it could be included in the README


var Sequelize = require('cu8-sequelize-oracle');

var sequelize = new Sequelize('orcl', USER, 'PASSWORD',{
    database: 'orcl',
    username: USER,
    password: 'PASSWORD',
    host:     '127.0.0.1',
    port:     '1521',
    pool:     {
      maxConnections: 5,
      maxIdleTime:    3000
    },
    dialect: 'oracle',
    logging: console.log
});

var Project = sequelize.define('project', {
  title: Sequelize.STRING,
  description: Sequelize.TEXT
})

var Task = sequelize.define('task', {
  title: Sequelize.STRING,
  description: Sequelize.TEXT,
  deadline: Sequelize.DATE
})

sequelize
.drop().then(function(){
    sequelize.sync({force:true}).then(function(){
        console.log("DB READY");
    });
});
rpavez commented 7 years ago

@keyursakaria You error is just a timeout, try to connect using sqlplus or SQLDeveloper first.

mrisney commented 6 years ago

connectString example ? I am using a SID, instead of a SERVICE_NAME, which is setup in TNSNAMES.ora how would I connect ? This is how I do it with straight oracledb :

class Database { connect() {

    var config = {
        user: scott",
        password: "tiger",
        connectString: "db4"
    };

    oracledb.autoCommit = true
    oracledb.outFormat = oracledb.OBJECT

    return new Promise((resolve, reject) => {
        oracledb.getConnection(config)
            .then(conn => {
                this._connection = conn
                resolve('connected to oracledb!')
            })
            .catch(err => reject(Error('failed to connect to oracledb : ' + err)))
    })
}
princekdwivedi commented 5 years ago

I sucessfully connected with below code

const http = require('http');
const oracledb = require('oracledb');
let error;
let user;
oracledb.getConnection(
    {
      user: 'awsuser12', 
      password: '2o0KxhCXeR7UccczzFJjQOyrcoBELsKcA6X7',
      connectString: 'whiz-oracle.tesrsds.eu-west-1.rds.amazonaws.com:1521/orcl'
    }, function(err, connection) {

    console.log('connection created');
        if (err) {console.log(err); }

            connection.execute('select user from dual', [], function(err, result) {
            console.log('executing query..');
            console.log(err);
            console.log(result);

                connection.close(function(err) {
                    if (err) {console.log(err);} else{
                    console.log('connection closed successfully');
                }

                }); 

            })
    }
);

But getting error while using sequalize-oracle orm my code is :

const Sequelize = require('sequelize-oracle');

let database = new Sequelize(
  'orcl',
  'testuser',
  'testuserpass', {
  host: 'whiz-oracle.clzhphljtuutsd.eu-west-1.rds.amazonaws.com',
  port: 1521,
  dialect: "oracle",
  dialectOptions: {
    connectTimeout: 6000
  },
  pool: {
    max: 5,
    min: 0,
    idle: 10000,
  },
  // logging: function (str) {
  //   console.log('database logging');
  //   console.log(str);
  // },
  define: {
    timestamps: false
  }
});

database
    .authenticate()
    .then(() => {
        console.log('Connection has been established successfully hhhhhh.');
    })
    .catch(err => {
        console.error('Unable to connect to the database:', err);
    });

Error: timeout of 2000ms exceeded. Check your configuration and your database Please help me to get rid of this.