Closed talkingtab closed 10 years ago
I did add a db.query('.quit'); and that did allow the program to exit.
sorry, what's the bug, exactly?
also you probably just need to db.close()
in order to exit … but again, I don't understand what's the bug. It works as expected with any special query that starts with a dot .
it just write and show what's returned.
when I run the example program from the command line
node dblite.js I expect it to terminate just as it would if I had a program with only the line console.log("FOO"):
It doesn't terminate, but just hangs until I use ctrl-c to kill the process.
dblite
is a module to manipulate databases … when you open one, you need to db.close()
it too. Why would you omit to close an opened database and why do you open it in first place?
I don't understand this bug or what you are trying to do.
When you use dot special queries you can queue them without problems.
So, here how I would solve your case. If there's anything else you need please let me know.
var dblite = require('dblite'),
db = dblite('./tags.db');
db
// silent exit (no bye-bye message)
.on('close', Object)
// error handler
.on('error', function(err) {
console.log('something terrible happened, rebooting', err);
process.exit();
})
// show databases
.query('.databases')
// exit
.query('.quit')
;
Bear in mind, there is no bug in this behavior.
I'm just exploring the module. I have some complex code that used the node-sqlite3 module, but that module doesn't work with the v0.11.x versions of node. So I found your code and adapted the example code you have in the readme.md file of the github repository. Perhaps one way to address the problem is to change the readme so that it uses the example you just posted above? I think your module is good thank you!
And I did try a db.close(); and that also does not terminate (on my system).
var dblite = require('dblite'), db = dblite('./tags.db'); // ready to go, i.e. db.query('.databases'); db.close();
Special queries with the .
are handled differently since these interact directly with the spawned program. db.close()
does not work in that case because it throws an error (if you use the error handler you'll notice that) because .database
and others with the .
will put dblite in a busy state and you can only keep queuing info or kill the process.
However, those special queries are not usually meant to be used if not during live console debugging, hence no need to terminate inline or close the db, since maybe you just want to know some info and change some behavior.
Glad you liked the module … and yes, the "beauty" of dblite is that it just works and on every platform … as long as spawn
and sqlite
cli are in place everyone should be good to go.
I'm using node v0.11.21 SQLite version 3.7.9 node --harmony dblite.js
Linux 3.2.0-24-virtual #37-Ubuntu SMP Wed Apr 25 12:51:49 UTC 2012 i686 i686 i386 GNU/Linux
var dblite = require('dblite'), db = dblite('./tags.db');
db.on('error', function(err) { console.log('something terrible happened, rebooting', err); process.exit(); }) // ready to go, i.e. db.query('.databases');
prints out the correct information, but hangs rather than completing.