在这里,我尝试分发npm软件包sqllite3
。我遇到错误。我在做什么错了?
代码:
const sqlite3 = require("sqlite3").verbose();
var path = require("path");
let db = new sqlite3.Database(
path.join(__dirname, "..", "db", "some.db"),
sqlite3.OPEN_READWRITE | sqlite3.OPEN_CREATE,
err => {
console.log(err);
}
);
function awaitRunner(db) {
return async function run() {
var args = Array.prototype.slice.call(arguments);
return new Promise(function(resolve, reject) {
db.run.apply(null, args.concat(cb));
function cb(err) {
if (err) {
reject();
}
resolve();
}
});
};
}
async function run() {
const runner = awaitRunner(db);
await runner(`CREATE TABLE IF NOT EXISTS Currencies(
id integer NOT NULL PRIMARY KEY AUTOINCREMENT,
name text NOT NULL UNIQUE)`);
db.close();
}
run();
输出:
(node:91895) UnhandledPromiseRejectionWarning: Unhandled
promise rejection (rejection id: 2): TypeError: Database object expected
(node:91895) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
null