import path from "path"; import {getDataDir} from "ee-core/ps"; import {Database, SqliteStorage} from "ee-core/storage"; class DbStorage { private static sqliteOptions = { timeout: 6000, verbose: console.log } private static storage : SqliteStorage private static db : Database /** * 初始化Sqlite数据库 */ public static _init() { const dbFile = path.join(getDataDir(),'db', 'print-utils.db') if (!DbStorage.storage || !DbStorage.db) { DbStorage.storage = new SqliteStorage(dbFile, DbStorage.sqliteOptions) DbStorage.db = DbStorage.storage.db } } public static getDb() { DbStorage._init() return DbStorage.db } public static checkTableExists(tableName: String) { // language=SQL format=false const masterStmt = DbStorage.getDb().prepare(`SELECT * FROM sqlite_master WHERE type=? AND name = ?`); return masterStmt.get('table', tableName) as Boolean } } DbStorage.toString = () => '[class DbStorage]' export { DbStorage }