db.ts 417 B

123456789101112131415161718192021
  1. import { Low, JSONFile } from "lowdb";
  2. type IDBData = {
  3. buildObj: {
  4. [key: string]: string[];
  5. };
  6. };
  7. // 单例
  8. export class DB {
  9. private static _db?: Low<IDBData>;
  10. public static getDB():Low<IDBData>{
  11. // 第一次初始化
  12. if (this._db == undefined) {
  13. const adapter = new JSONFile<IDBData>("./db.json");
  14. this._db = new Low(adapter);
  15. }
  16. return this._db;
  17. }
  18. }