Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | 2x 2x 2x 2x 2x 2x 2x 2x 12x 12x 12x 2x 2x 2x 2x 2x 2x 2x 2x 2x |
import { CoreDatabase as Db } from "../modules/core/core.database";
import { existsSync } from 'fs';
import { resolve } from 'path';
import { connect } from "../database/connector";
import { Connection } from "mongoose";
export class Installer {
mongooseUri = '';
db: Connection;
constructor(mongooseUri: string) {
this.mongooseUri = mongooseUri;
this.db = connect(mongooseUri);
}
private static loadJson(dataFolder: string, file: string) {
const filePath = resolve(dataFolder, `data/export.${file}.json`);
Eif (existsSync(filePath)) {
return require(filePath);
}
return [];
}
async initData() {
const dataFolder = process.cwd();
await Db.Role.insertMany(Installer.loadJson(dataFolder, 'roles'));
await Db.Dict.insertMany(Installer.loadJson(dataFolder, 'dicts'));
await Db.Menu.insertMany(Installer.loadJson(dataFolder, 'menus'));
await Db.Group.insertMany(Installer.loadJson(dataFolder, 'groups'));
await Db.Setting.insertMany(Installer.loadJson(dataFolder, 'settings'));
await Db.Account.insertMany(Installer.loadJson(dataFolder, 'accounts'));
}
async drop() {
this.db.dropDatabase();
this.db.close();
}
} |