add:添加sqlite保存激活记录

This commit is contained in:
贾同学
2025-10-24 15:10:23 +08:00
parent 005b5137cf
commit ba143138d1
15 changed files with 758 additions and 313 deletions

View File

@@ -0,0 +1,52 @@
import {type Database, SqliteStorage} from 'ee-core/storage';
import {getDataDir} from 'ee-core/ps';
import path from 'path';
/**
* sqlite数据存储
* @class
*/
class BasedbService {
dbname: string;
db!: Database;
storage!: SqliteStorage;
constructor(options: { dbname: string }) {
const { dbname } = options;
this.dbname = dbname;
}
/*
* 初始化
*/
protected _init(): void {
// 定义数据文件
const dbFile = path.join(getDataDir(), "db", this.dbname);
const sqliteOptions = {
timeout: 6000,
verbose: console.log
}
this.storage = new SqliteStorage(dbFile, sqliteOptions);
this.db = this.storage.db;
}
/*
* change data dir (sqlite)
*/
changeDataDir(dir: string): void {
// the absolute path of the db file
const dbFile = path.join(dir, this.dbname);
const sqliteOptions = {
timeout: 6000,
verbose: console.log
}
this.storage = new SqliteStorage(dbFile, sqliteOptions);
this.db = this.storage.db;
}
}
BasedbService.toString = () => '[class BasedbService]';
export {
BasedbService,
}