From e01c6cf4745ffdafc7db261dcf749daf72ad3f88 Mon Sep 17 00:00:00 2001 From: BTMuli Date: Wed, 25 Mar 2026 15:15:45 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20=E6=9B=B4=E6=96=B0=20AppData=20?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B=E5=AE=9A=E4=B9=89=EF=BC=8C=E7=AE=80=E5=8C=96?= =?UTF-8?q?=E6=8F=92=E5=85=A5=E6=95=B0=E6=8D=AE=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plugins/Sqlite/index.ts | 32 ++++++++++++-------------------- src/types/Sqlite/AppData.d.ts | 24 +++--------------------- 2 files changed, 15 insertions(+), 41 deletions(-) diff --git a/src/plugins/Sqlite/index.ts b/src/plugins/Sqlite/index.ts index c37f08f6..bbb565d9 100644 --- a/src/plugins/Sqlite/index.ts +++ b/src/plugins/Sqlite/index.ts @@ -1,6 +1,6 @@ /** * Sqlite 数据库操作类 - * @since Beta v0.9.5 + * @since Beta v0.9.9 */ import showSnackbar from "@comp/func/snackbar.js"; @@ -104,33 +104,25 @@ class Sqlite { return localVersion !== dbVersion; } - /** - * 插入应用数据 - * @since Alpha v0.2.0 - * @param key - 键 - * @param value - 值 - * @returns sql - */ - insertAppData(key: string, value: string): string { - return ` - INSERT INTO AppData (key, value, updated) - VALUES ('${key}', '${value}', datetime('now', 'localtime')) - ON CONFLICT(key) DO UPDATE SET value = '${value}', - updated = datetime('now', 'localtime'); - `; - } - /** * 保存 appData - * @since Beta v0.3.3 + * @since Beta v0.9.9 * @param key - 键 * @param value - 值 * @returns 无返回值 */ public async saveAppData(key: string, value: string): Promise { const db = await this.getDB(); - const sql = this.insertAppData(key, value); - await db.execute(sql); + await db.execute( + ` + INSERT INTO AppData (key, value, updated) + VALUES ($1, $2, datetime('now', 'localtime')) + ON CONFLICT(key) + DO UPDATE SET value = $2, + updated = datetime('now', 'localtime'); + `, + [key, value], + ); } /** diff --git a/src/types/Sqlite/AppData.d.ts b/src/types/Sqlite/AppData.d.ts index b6fc1251..e8efa53d 100644 --- a/src/types/Sqlite/AppData.d.ts +++ b/src/types/Sqlite/AppData.d.ts @@ -1,34 +1,16 @@ /** * AppData 表类型定义文件 - * @since Beta v0.4.1 + * @since Beta v0.9.9 */ declare namespace TGApp.Sqlite.AppData { - /** - * AppData 表键值 - * @since Beta v0.4.1 - * @TODO 枚举 - */ - enum DBKey { - /** 应用版本 */ - APP_VERSION = "appVersion", - /** 数据库更新时间 */ - DATA_UPDATED = "dataUpdated", - /** 当前用户 Cookie */ - COOKIE = "cookie", - /** 设备信息 */ - DEVICE_INFO = "deviceInfo", - /** 数据目录 */ - USER_DIR = "userDir", - } - /** * AppData 行数据 - * @since Beta v0.3.3 + * @since Beta v0.9.9 */ type Item = { /** 键 */ - key: DBKey; + key: string; /** 值 */ value: string; /** 更新时间 */