nodejs可以从sqlite db获取数据
这是我的简单代码,可以从我的sqlite DB中获取一些数据。
index.ts:
import { Database } from './Class/database';
Database.checkIfExists("some ID");
。
export class Database {
static sqlite3 = require("sqlite3").verbose();
static db = new Database.sqlite3.Database("database.db");
static checkIfExists(memberID: string) {
Database.db.run("SELECT * FROM Points WHERE DiscordID = $discordID", {
$discordID: memberID
}, function (err:any, row:any) {
console.log(row);
console.log(err);
});
}
}
数据库 即使只有“从点选择 *”,我也会变得相同。直接在SQL DB浏览器中运行此查询将向我显示正确的数据。
编辑:
用于更好测试的代码:
checkIfExists(memberID: string) {
this.db.run("SELECT * FROM Points", function (err:any, row:any) {
console.log(row);
console.log(err);
});
}
This is my simple code to get some data from my sqlite db.
Index.ts:
import { Database } from './Class/database';
Database.checkIfExists("some ID");
Database.ts:
export class Database {
static sqlite3 = require("sqlite3").verbose();
static db = new Database.sqlite3.Database("database.db");
static checkIfExists(memberID: string) {
Database.db.run("SELECT * FROM Points WHERE DiscordID = $discordID", {
$discordID: memberID
}, function (err:any, row:any) {
console.log(row);
console.log(err);
});
}
}
Do you guys have any idea why the first log does undefined
and the second one null
? Even with just "SELECT * FROM Points" I get the same. Running this query directly in the sql db browser will show me the correct data.
Edit:
Code for better testing:
checkIfExists(memberID: string) {
this.db.run("SELECT * FROM Points", function (err:any, row:any) {
console.log(row);
console.log(err);
});
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
方法Checkifexists不能是静态的,因为它是特定于实例的。应该这样:
Method checkIfExists cannot be static as it is instance specific. Should be like this: