I have a simple test or Node ORM and the application runs and creates the record. But it sits at the command prompt afterwards:
var orm = require("orm");
orm.connect('mysql://un-app:unpwd@localhost/dbn', function(err, db) {
var User = db.define('user', {
id : Number,
first_name : String,
last_name : String,
email : String,
added_on : Date,
active : Number,
password : String,
}) ;
var newUser = {
first_name: 'Ed'
, last_name: 'Davis'
, email: 'ez-eddie@hotmail.com'
, added_on: new Date().getTime()
, password: 'test' // encrypt('test')
}
User.create(newUser, function (err, user) {
console.log(user.id)
});
})
It just sits there:
C:\Users\todd\Documents\web\nodeTest\app>node create-user.js
1010
I am using windows - so a control-c gets me out of it. But that cannot be right, can it? Why is the application waiting there?
Supposedly you need to close the database connection explicitly to allow the control to fall through:
User.create(newUser, function (err, user) {
//console.log(err)
console.log(user.id)
console.log('end of connect')
db.close()
})
Can somebody elaborate why?