Add DatabaseHandle and DB utilities, integrate API
Introduce a DatabaseHandle wrapper and helper functions for opening and decrypting NTQQ SQLite DBs (openDatabase, decryptAndOpen) in napcat-database; expose them from the package index. Add typed query/execute helpers and SQLInputValue typing. Extend NTQQDatabaseApi in napcat-core to provide high-level methods (openDecryptedDb, openDatabase, query, queryOne, execute) and export DatabaseHandle. Replace disabled inline test blocks with runtime DatabaseApi usage in napcat-framework and napcat-shell to test/read nt_msg.db via the new API. Misc: small cleanup of imports and comments.
This commit is contained in:
1 parent
b9dcedacf5
commit
0ddf21a2f5
5 files changed
+294
-37
No files matched your search
@@ -1,4 +1,3 @@
|
||||
import path from 'node:path';
|
||||
import { NapCatPathWrapper } from 'napcat-common/src/path';
|
||||
import { InitWebUi, WebUiConfig, webUiRuntimePort } from 'napcat-webui-backend/index';
|
||||
import { NapCatAdapterManager } from 'napcat-adapter';
|
||||
@@ -122,22 +121,21 @@ export async function NCoreInitFramework (
|
||||
WebUiDataRuntime.setQQDataPath(loaderObject.core.dataPath);
|
||||
InitWebUi(logger, pathWrapper, logSubscription, statusHelperSubscription).then().catch(e => logger.logError(e));
|
||||
|
||||
// // [测试代码 - 已禁用] 使用捕获的 passphrase 读取 nt_msg.db 的表信息
|
||||
// if (dbPassphrase) {
|
||||
// const sqliteOk = await checkSqliteAvailable();
|
||||
// if (!sqliteOk) {
|
||||
// logger.logWarn('[NapCat] [Database] node:sqlite 不可用');
|
||||
// } else {
|
||||
// const ntDbDir = path.resolve(loaderObject.core.dataPath, selfInfo.uin, 'nt_qq', 'nt_db');
|
||||
// const ntMsgDbPath = path.resolve(ntDbDir, 'nt_msg.db');
|
||||
// try {
|
||||
// const result = loaderObject.core.apis.DatabaseApi.readDatabase('nt_msg.db');
|
||||
// if (result) logger.log('[NapCat] [Database] \n' + loaderObject.core.apis.DatabaseApi.formatResults([result]));
|
||||
// } catch (e) {
|
||||
// logger.logError('[NapCat] [Database] 读取失败:', e);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// 测试 DatabaseApi
|
||||
if (dbPassphrase) {
|
||||
const dbApi = loaderObject.core.apis.DatabaseApi;
|
||||
const sqliteOk = await dbApi.isSqliteAvailable();
|
||||
if (sqliteOk) {
|
||||
try {
|
||||
const result = dbApi.readDatabase('nt_msg.db');
|
||||
if (result) {
|
||||
logger.log('[NapCat] [Database] nt_msg.db:\n' + dbApi.formatResults([result]));
|
||||
}
|
||||
} catch (e) {
|
||||
logger.logError('[NapCat] [Database] 读取失败:', e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 使用 NapCatAdapterManager 统一管理协议适配器
|
||||
const adapterManager = new NapCatAdapterManager(loaderObject.core, loaderObject.context, pathWrapper);
|
||||
|
||||
Reference in new issue
Block a user