I would like to try out node orm2, with sqlite. I tried the example code, and changed mysql to sqlite. It looks like this:
var orm = require("orm");
orm.connect('sqlite://D:/orm_test/database.db', function (err, db) {
// ...
});
I don't get any error, or warning. Just nothing happens. The callback is not called at all.
It does not work, even if I create database.db
before
According to the documentation the callback is only called when the connection is done successfully (or unsuccessfully)... So if your path is incorrect (for any reason, and your connection is NOT explicitly unsuccessfull), maybe there is no callback ?
You can avoid callback if you listen for the connect event directly as this :
var orm = require('orm');
var db = orm.connect('sqlite://D:/orm_test/database.db');
db.on('connect', function(err) {
if (err) return console.error('Connection error: ' + err);
// doSomething()...
});
The connection URL is like :
driver://username:password@hostname/database?option=value
You can use the debug option to prints queries into the console, maybe there will be more informations ?
EDIT :
Well, I just tried to use it and did that :
// REQUIRES
var express = require('express');
var app = express();
var orm = require("orm");
var sqlite3 = require('sqlite3');
// SERVER CONFIGURATION
var port = 5050;
// APP CONFIGURATION
app.use(express.static('public'));
app.use('/static', express.static(__dirname + '/public'));
app.set('views', __dirname + '/views');
// ROUTES
app.get('/', function(req, res){
orm.connect('sqlite://C:/Users/Me/Documents/Projects/test/database.db', function(err, db){
console.log('connected to this db : ' + JSON.stringify(db));
});
});
app.listen(port, function(){
console.info('Server successfully started, listening on port ' + port);
});
And it works... JSON.stringify shows what is the content of DB Object in the console. Does your code looks like this ?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With