node-sqlite3
node-sqlite3 copied to clipboard
What happen if I do not pass a argument to #run and it get a error?
The #run method throw a exception or the error pass.?
Do you mean this?
var sqlite3 = require('sqlite3').verbose();
var db = new sqlite3.Database(':memory:');
try { db.run(); }
catch (e) {
console.log('got exception');
console.log(e);
}
Output:
got exception
[TypeError: SQL query expected]
Ok, but if I execute a invalid query a got a unhandled exception, is there others uhandleded exceptions cases that happens with this aproach?
db.run("INSERT INTO bookmark (id) VALUES (1)");
...
events.js:85
throw er; // Unhandled 'error' event
^
Error: SQLITE_ERROR: no such table: bookmark
at Error (native)
I think I understand your original question now. You were asking if you can pass a callback method without having to pass a query parameters argument [param, ...].
db.run("INSERT INTO bookmark (id) VALUES (1)", function(err) {
if (err)
console.log(err.message);
console.log("Finished callback");
});
SQLITE_ERROR: no such table: bookmark
Finished callback
The node-sqlite3 code checks if the last parameter is a function and uses that as the callback, so you can skip the optional parameters in-between and not have to use exceptions.