📦 add(db): 添加数据库信息

This commit is contained in:
BTMuli
2023-04-25 20:57:38 +08:00
parent 89d2e214bc
commit b89c3ac101
3 changed files with 42 additions and 35 deletions

View File

@@ -53,6 +53,20 @@ class TGSqlite {
await db.close();
}
/**
* @description 获取数据库信息
* @memberof TGSqlite
* @since Alpha v0.1.4
* @returns {Promise<{ key: string, value: string, updated: string }[]>}
*/
public async getAppData (): Promise<Array<{ key: string, value: string, updated: string }>> {
const db = await Database.load(this.dbPath);
const sql = "SELECT * FROM AppData;";
const res: Array<{ key: string, value: string, updated: string }> = await db.select(sql);
await db.close();
return res;
}
/**
* @description 已有数据表跟触发器不变的情况下,更新数据库数据
* @memberof TGSqlite
@@ -80,8 +94,9 @@ class TGSqlite {
// 检测数据表是否都存在
const sqlT = "SELECT name FROM sqlite_master WHERE type='table' ORDER BY name;";
const res: Array<{ name: string }> = await db.select(sqlT);
if (res.length === this.tables.length) {
if (res.every((item) => this.tables.includes(item.name))) {
// 考虑到 sqlite_sequence 表,所以需要 +1
if (res.length === this.tables.length + 1) {
if (this.tables.every((item) => res.map((i) => i.name).includes(item))) {
isVertified = true;
}
}