I'm setting up Sequelize to manage postgres in a Node.js app.
I've required sequelize-postgres, as well as declared 'postgres' in the dialect attr when instantiating a new Sequelize object. But for some reason, it defaults to using mysql.
Exact error message:
/Users/...project/node_modules/sequelize/lib/dialects/mysql/connector-manager.js:306
var connection = mysql.createConnection(connectionConfig);
^
TypeError: Cannot call method 'createConnection' of undefined
at module.exports.connect (.../node_modules/sequelize/lib/dialects/mysql/connector-manager.js:306:28)
at Object.pool.Pooling.Pool.create
(.../node_modules/sequelize/lib/dialects/mysql/connector-manager.js:131:19)
at createResource (.../node_modules/sequelize/node_modules/generic-pool/lib/generic-pool.js:258:13)
at dispense (.../node_modules/sequelize/node_modules/generic-pool/lib/generic-pool.js:250:9)
at Object.me.acquire (.../node_modules/sequelize/node_modules/generic-pool/lib/generic-pool.js:316:5)
at null.fct (.../node_modules/sequelize/lib/dialects/mysql/connector-manager.js:241:19)
at null.<anonymous> (.../node_modules/sequelize/lib/emitters/custom-event-emitter.js:24:18)
at processImmediate [as _immediateCallback] (timers.js:336:15)
Any help is appreciated thank you!
Related
On the online JDL-studio, I create a JDL file without any errors. After importing it, I get an error "TypeError: cannot read property 'charCodeAt" of undefined". How to find out the cause?
Error running generator entities: TypeError: Cannot read property 'charCodeAt' of undefined
TypeError: Cannot read property 'charCodeAt' of undefined
at module.exports (/Users/me/Documents/workspace/myapp/node_modules/ret/lib/index.js:75:54)
at new RandExp (/Users/me/Documents/workspace/myapp/node_modules/randexp/lib/randexp.js:26:19)
at new RandexpWithFaker (/Users/me/Documents/workspace/myapp/node_modules/generator-jhipster/utils/faker.js:26:5)
at Faker.faker.createRandexp (/Users/me/Documents/workspace/myapp/node_modules/generator-jhipster/utils/faker.js:61:41)
at Object.field.createRandexp (/Users/me/Documents/workspace/myapp/node_modules/generator-jhipster/utils/field.js:360:37)
at generateFakeDataForField (/Users/me/Documents/workspace/myapp/node_modules/generator-jhipster/utils/field.js:101:29)
at Object.field.generateFakeData (/Users/me/Documents/workspace/myapp/node_modules/generator-jhipster/utils/field.js:365:16)
at /Users/me/Documents/workspace/myapp/node_modules/generator-jhipster/generators/database-changelog-liquibase/index.js:136:28
at Array.forEach (<anonymous>)
at module.exports.prepareFakeData (/Users/me/Documents/workspace/myapp/node_modules/generator-jhipster/generators/database-changelog-liquibase/index.js:120:18)
at Object.<anonymous> (/Users/me/Documents/workspace/myapp/node_modules/yeoman-generator/lib/index.js:1024:25)
at /Users/me/Documents/workspace/myapp/node_modules/run-async/index.js:49:25
at new Promise (<anonymous>)
at /Users/me/Documents/workspace/myapp/node_modules/run-async/index.js:26:19
at runLoop.add.once.once (/Users/me/Documents/workspace/myapp/node_modules/yeoman-generator/lib/index.js:1025:11)
at Immediate.<anonymous> (/Users/me/Documents/workspace/myapp/node_modules/grouped-queue/lib/subqueue.js:48:34)
ERROR! Cannot read property 'charCodeAt' of undefined
TypeError: Cannot read property 'charCodeAt' of undefined
at module.exports (/Users/me/Documents/workspace/myapp/node_modules/ret/lib/index.js:75:54)
at new RandExp (/Users/me/Documents/workspace/myapp/node_modules/randexp/lib/randexp.js:26:19)
at new RandexpWithFaker (/Users/me/Documents/workspace/myapp/node_modules/generator-jhipster/utils/faker.js:26:5)
at Faker.faker.createRandexp (/Users/me/Documents/workspace/myapp/node_modules/generator-jhipster/utils/faker.js:61:41)
at Object.field.createRandexp (/Users/me/Documents/workspace/myapp/node_modules/generator-jhipster/utils/field.js:360:37)
at generateFakeDataForField (/Users/me/Documents/workspace/myapp/node_modules/generator-jhipster/utils/field.js:101:29)
at Object.field.generateFakeData (/Users/me/Documents/workspace/myapp/node_modules/generator-jhipster/utils/field.js:365:16)
at /Users/me/Documents/workspace/myapp/node_modules/generator-jhipster/generators/database-changelog-liquibase/index.js:136:28
at Array.forEach (<anonymous>)
at module.exports.prepareFakeData (/Users/me/Documents/workspace/myapp/node_modules/generator-jhipster/generators/database-changelog-liquibase/index.js:120:18)
at Object.<anonymous> (/Users/me/Documents/workspace/myapp/node_modules/yeoman-generator/lib/index.js:1024:25)
at /Users/me/Documents/workspace/myapp/node_modules/run-async/index.js:49:25
at new Promise (<anonymous>)
at /Users/me/Documents/workspace/myapp/node_modules/run-async/index.js:26:19
at runLoop.add.once.once (/Users/me/Documents/workspace/myapp/node_modules/yeoman-generator/lib/index.js:1025:11)
at Immediate.<anonymous> (/Users/me/Documents/workspace/myapp/node_modules/grouped-queue/lib/subqueue.js:48:34)
I find that its cause is the following email pattern:
email String required minlength(6) maxlength(255) pattern(/^\w+([-+.']\w+)*#\w+([-.]\w+)*\.\w+([-.]\w+)*$/) unique,
Now, a question would be what is the acceptable email pattern for JHipster.
I'm attempting to use bluebird's promisify with the node-mysql package. Node version is 4.2.4
var Promise = require('bluebird');
var mysqlClient = Promise.promisifyAll(require("mysql/lib/Connection").prototype);
Promise.promisifyAll(require("mysql/lib/Pool").prototype);
var connectionOptions = ({
host: 'localhost',
user: 'root',
password: '',
database: 'my_db'
});
var firstPost = "some sql here";
var results = [];
mysqlClient.connectAsync(connectionOptions).then(function(connection){
connection.query(firstPost, function(){
console.log('i reached line 26 of a node script. a minor miracle')
});
}).catch(function(err) {
console.log(err);
});
I get the error
[TypeError: Cannot read property 'socketPath' of undefined]
Stack trace:
Unhandled rejection TypeError: Cannot read property 'socketPath' of undefined
at Connection.connect (/vagrant/spam_smasher/node_modules/mysql/lib/Connection.js:87:32)
at Connection.tryCatcher (/vagrant/spam_smasher/node_modules/bluebird/js/release/util.js:11:23)
at Connection.ret [as connectAsync] (eval at <anonymous> (/vagrant/spam_smasher/node_modules/bluebird/js/release/promisify.js:184:12), <anonymous>:13:39)
at Object.<anonymous> (/vagrant/spam_smasher/bluebird.js:24:13)
at Module._compile (module.js:435:26)
at Object.Module._extensions..js (module.js:442:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:313:12)
at Function.Module.runMain (module.js:467:10)
at startup (node.js:136:18)
at node.js:963:3
Why am I getting this error and/or how could I debug it further? I tried to remote debug it but am not sure what I'm looking at when I get a few steps down the prototype chain. The Async functions do appear to be attached to the MysqlClient object.
Remore debugging reveals that the following section in node-mysql's Connection.js file is throwing the error :
if (!this._connectCalled) {
this._connectCalled = true;
// Connect either via a UNIX domain socket or a TCP socket.
this._socket = (this.config.socketPath)
? Net.createConnection(this.config.socketPath)
: Net.createConnection(this.config.port, this.config.host);
socketpath is not something you need to define when using node-mysql directly
It seems the Bluebird docs are out of date. They miss that you also need ConnectionConfig to be available and so this was missing in my code, causing the error.
I chose to abandon this problem to preserve my sanity. There is further discussion here and you may also want to check out mysql-promise
sequelize: 1.7.0
pg: 2.11.1
posgreSql: 9.3 (pg server on my pc)
I have app that is using following config:
db: 'mysql://user:pass#localhost/dbname'
And it works with sequelize and mysql dialect.
When I change it to:
db: 'postgres://user:pass#localhost/dbname'
and dialect to postgres and try to sequelize.sync() I get following error:
{
"message":"syntax error at or near \"(\"",
"name":"error",
"stack":"error: syntax error at or near \"(\"\n at Connection.parseE (/Users/me/Desktop/node/myapp/node_modules/pg/lib/connection.js:561:11)\n at Connection.parseMessage (/Users/me/Desktop/node/myapp/node_modules/pg/lib/connection.js:390:17)\n at [object Object].<anonymous> (/Users/me/Desktop/node/myapp/node_modules/pg/lib/connection.js:92:20)\n at EventEmitter.emit (events.js:95:17)\n at Socket.<anonymous> (_stream_readable.js:746:14)\n at EventEmitter.emit (events.js:92:17)\n at emitReadable_ (_stream_readable.js:408:10)\n at emitReadable (_stream_readable.js:404:5)\n---------------------------------------------\n at module.exports.CustomEventEmitter.failure.CustomEventEmitter.fail.CustomEventEmitter.error (/Users/me/Desktop/node/myapp/node_modules/sequelize/lib/emitters/custom-event-emitter.js:93:10)\n at exec (/Users/me/Desktop/node/myapp/node_modules/sequelize/lib/query-chainer.js:92:14)\n at onError (/Users/me/Desktop/node/myapp/node_modules/sequelize/lib/query-chainer.js:72:11)\n at EventEmitter.emit (events.js:95:17)\n at module.exports.CustomEventEmitter.emit (/Users/me/Desktop/node/myapp/node_modules/sequelize/lib/emitters/custom-event-emitter.js:61:33)\n at [object Object].<anonymous> (/Users/me/Desktop/node/myapp/node_modules/sequelize/lib/emitters/custom-event-emitter.js:131:17)\n---------------------------------------------\n at module.exports.CustomEventEmitter.failure.CustomEventEmitter.fail.CustomEventEmitter.error (/Users/me/Desktop/node/myapp/node_modules/sequelize/lib/emitters/custom-event-emitter.js:93:10)\n at exec (/Users/me/Desktop/node/myapp/node_modules/sequelize/lib/query-chainer.js:92:14)\n at onError (/Users/me/Desktop/node/myapp/node_modules/sequelize/lib/query-chainer.js:72:11)\n at EventEmitter.emit (events.js:95:17)\n at module.exports.CustomEventEmitter.emit (/Users/me/Desktop/node/myapp/node_modules/sequelize/lib/emitters/custom-event-emitter.js:61:33)\n at [object Object].<anonymous> (/Users/me/Desktop/node/myapp/node_modules/sequelize/lib/emitters/custom-event-emitter.js:131:17)",
"code":"42601"
},
"msg":"uncaughtException",
"time":"2014-03-31T14:17:29.496Z",
"v":0
}
What I am doing wrong?
Before I created dbname database in pg there was error missing database so I guess sequelize is connected to pg but it generates some syntax errors in pgsql code??
the problem was that in model schema I had Sequelize.INTEGER(11) - and postgres does not allow to pass 11 as a size of INTEGER - this will be solved in 2.x.x version of Sequelize (You can find issue corresponding to this problem on sequelize github repo).
Sequelize and postgres work well for me. Did you set dialect, protocol, port correctly in config.js like this
{
"development":{
"username":"name",
"password":"pass",
"database":"db",
"dialect":"postgres",
"protocol":"postgres",
"host":"127.0.0.1",
"port":"5432"
},
...
I install redis on win7 by exe and I got nodeBB on
there are some first time config prompt and then
nodeBB even start populating database with default config.
After entering admin name email pwd, I got stuck here as below:
c:\Users\kaeyonbaker\Downloads\NodeBB-master\NodeBB-master\node_modules\redis\in
dex.js:535 throw err; ^ TypeError: Object # has no method 'genSalt' at
Object.User.hashPassword
(c:\Users\kaeyonbaker\Downloads\NodeBB-master\No
deBB-master\src\user.js:555:10) at
c:\Users\kaeyonbaker\Downloads\NodeBB-master\NodeBB-master\src\user.js:13
3:11 at try_callback
(c:\Users\kaeyonbaker\Downloads\NodeBB-master\NodeBB-master\
node_modules\redis\index.js:532:9) at RedisClient.return_reply
(c:\Users\kaeyonbaker\Downloads\NodeBB-master\No
deBB-master\node_modules\redis\index.js:614:13) at ReplyParser.
(c:\Users\kaeyonbaker\Downloads\NodeBB-master\Nod
eBB-master\node_modules\redis\index.js:266:14) at
ReplyParser.EventEmitter.emit (events.js:95:17) at
ReplyParser.send_reply
(c:\Users\kaeyonbaker\Downloads\NodeBB-master\Node
BB-master\node_modules\redis\lib\parser\javascript.js:300:10) at
ReplyParser.execute
(c:\Users\kaeyonbaker\Downloads\NodeBB-master\NodeBB-
master\node_modules\redis\lib\parser\javascript.js:189:22) at
RedisClient.on_data
(c:\Users\kaeyonbaker\Downloads\NodeBB-master\NodeBB-
master\node_modules\redis\index.js:488:27) at Socket.
(c:\Users\kaeyonbaker\Downloads\NodeBB-master\NodeBB-m
aster\node_modules\redis\index.js:82:14)
Then i change redis into mongo and i've got the similar error as below:
c:\Users\kaeyonbaker\Downloads\NodeBB-master\NodeBB-master\node_modules\mongodb\
lib\mongodb\connection\base.js:242 throw message; ^ TypeError: Object#
has no method 'genSalt' at Object.User.hashPassword (c:\Users\kaeyonbaker\Downloads\NodeBB-master\No
deBB-master\src\user.js:555:10) at
c:\Users\kaeyonbaker\Downloads\NodeBB-master\NodeBB-master\src\user.js:13
3:11 at
c:\Users\kaeyonbaker\Downloads\NodeBB-master\NodeBB-master\src\database\m
ongo.js:418:5 at
c:\Users\kaeyonbaker\Downloads\NodeBB-master\NodeBB-master\node_modules\m
ongodb\lib\mongodb\collection\core.js:703:14 at
c:\Users\kaeyonbaker\Downloads\NodeBB-master\NodeBB-master\node_modules\m
ongodb\lib\mongodb\db.js:1098:5 at
c:\Users\kaeyonbaker\Downloads\NodeBB-master\NodeBB-master\node_modules\m
ongodb\lib\mongodb\db.js:1806:9 at Server.Base.callHandler
(c:\Users\kaeyonbaker\Downloads\NodeBB-master\No
deBB-master\nodemodules\mongodb\lib\mongodb\connection\base.js:442:41)
at
c:\Users\kaeyonbaker\Downloads\NodeBB-master\NodeBB-master\node_modules\m
ongodb\lib\mongodb\connection\server.js:485:18 at MongoReply.parseBody
(c:\Users\kaeyonbaker\Downloads\NodeBB-master\NodeBB
-master\node_modules\mongodb\lib\mongodb\responses\mongo_reply.js:68:5)
at null. (c:\Users\kaeyonbaker\Downloads\NodeBB-master\NodeBB-mas
ter\node_modules\mongodb\lib\mongodb\connection\server.js:443:20)
I have been using MongoSkin( Nodejs ) plugin to connect Mongodb as below.
var db = mongo.db(dbconfig.mongo_ip+'/'+dbconfig.mongo_db_name);
db.collection('myprofile').findOne({_id:memberid}, function(err, session){
if(err){
db.close();
console.log(err.stack);
}
})
If i got the mongo connection error from node.js, then how do i reconnect the same using mongoskin,
Mongo Connect errr: Error: failed to connect to [localhost:27017]
at [object Object].<anonymous> (/usr/local/lib/node_modules/mongoskin/node_modules/mongodb/lib/mongodb/connection/server.js:184:51)
at [object Object].emit (events.js:45:17)
at [object Object].<anonymous> (/usr/local/lib/node_modules/mongoskin/node_modules/mongodb/lib/mongodb/connection/connection_pool.js:110:14)
at [object Object].emit (events.js:45:17)
at Socket.<anonymous> (/usr/local/lib/node_modules/mongoskin/node_modules/mongodb/lib/mongodb/connection/connection.js:301:10)
at Socket.emit (events.js:42:17)
at Array.33 (net.js:799:27)
at EventEmitter._tickCallback (node.js:108:26)
Please help me on this.
A good place to start is
https://github.com/kissjs/node-mongoskin/blob/master/test/db.js
but I assume you need to call open on db under mongoskin as well as in the driver.