diff --git a/node_modules/@cool-midway/core/module/import.js b/node_modules/@cool-midway/core/module/import.js index 38741fb..0437df1 100644 --- a/node_modules/@cool-midway/core/module/import.js +++ b/node_modules/@cool-midway/core/module/import.js @@ -12,7 +12,8 @@ Object.defineProperty(exports, "__esModule", { value: true }); exports.CoolModuleImport = void 0; const decorator_1 = require("@midwayjs/decorator"); const core_1 = require("../exception/core"); -const Importer = require("mysql2-import"); +// const Importer = require("mysql2-import"); +const { Client } = require('pg') const fs = require("fs"); const config_1 = require("./config"); const path = require("path"); @@ -26,7 +27,8 @@ let CoolModuleImport = class CoolModuleImport { async init() { // 是否需要导入 if (this.coolConfig.initDB) { - await this.checkDbVersion(); + //变更 + // await this.checkDbVersion(); const modules = this.coolModuleConfig.modules; const importLockPath = path.join(`${this.app.getBaseDir()}`, "..", "lock"); if (!fs.existsSync(importLockPath)) { @@ -67,32 +69,63 @@ let CoolModuleImport = class CoolModuleImport { .ormConfig) === null || _a === void 0 ? void 0 : _a.default) ? this.ormConfig.default : this.ormConfig; - const importer = new Importer({ - host, - password, - database, - charset, - port, - user: username, - }); - await importer - .import(sqlPath) - .then(async () => { - clearInterval(t); - this.coreLogger.info("\x1B[36m [cool:core] midwayjs cool core init " + - module + - " database complete \x1B[0m"); - fs.writeFileSync(lockPath, `time consuming:${second}s`); - }) - .catch((err) => { - clearTimeout(t); - this.coreLogger.error("\x1B[36m [cool:core] midwayjs cool core init " + - module + - " database err please manual import \x1B[0m"); - fs.writeFileSync(lockPath, `time consuming:${second}s`); - this.coreLogger.error(err); - this.coreLogger.error(`自动初始化模块[${module}]数据库失败,尝试手动导入数据库`); + + const client = new Client({ + user: username, + host: host, + database: database, + password: password, + port: port, + }) + //变更 + client.connect(); + + const sql = fs.readFileSync(sqlPath).toString(); + + await client.query(sql).then(async () => { + clearInterval(t); + this.coreLogger.info("\x1B[36m [cool:core] midwayjs cool core init " + + module + + " database complete \x1B[0m"); + fs.writeFileSync(lockPath, `time consuming:${second}s`); + }) + .catch((err) => { + clearTimeout(t); + this.coreLogger.error("\x1B[36m [cool:core] midwayjs cool core init " + + module + + " database err please manual import \x1B[0m"); + fs.writeFileSync(lockPath, `time consuming:${second}s`); + this.coreLogger.error(err); + this.coreLogger.error(`自动初始化模块[${module}]数据库失败,尝试手动导入数据库`); }); + + + // const importer = new Importer({ + // host, + // password, + // database, + // charset, + // port, + // user: username, + // }); + // await importer + // .import(sqlPath) + // .then(async () => { + // clearInterval(t); + // this.coreLogger.info("\x1B[36m [cool:core] midwayjs cool core init " + + // module + + // " database complete \x1B[0m"); + // fs.writeFileSync(lockPath, `time consuming:${second}s`); + // }) + // .catch((err) => { + // clearTimeout(t); + // this.coreLogger.error("\x1B[36m [cool:core] midwayjs cool core init " + + // module + + // " database err please manual import \x1B[0m"); + // fs.writeFileSync(lockPath, `time consuming:${second}s`); + // this.coreLogger.error(err); + // this.coreLogger.error(`自动初始化模块[${module}]数据库失败,尝试手动导入数据库`); + // }); } } /** diff --git a/node_modules/@cool-midway/core/service/base.js b/node_modules/@cool-midway/core/service/base.js index b8ff5cd..d7c6c55 100644 --- a/node_modules/@cool-midway/core/service/base.js +++ b/node_modules/@cool-midway/core/service/base.js @@ -145,16 +145,23 @@ let BaseService = class BaseService { if (!(await this.paramSafetyCheck(order + sort))) { throw new validate_1.CoolValidateException("非法传参~"); } - sql += ` ORDER BY ${SqlString.escapeId(order)} ${this.checkSort(sort)}`; + //变更 + // sql += ` ORDER BY ${SqlString.escapeId(order)} ${this.checkSort(sort)}`; + sql += ` ORDER BY "${order}" ${this.checkSort(sort)}`; } if (isExport && maxExportLimit > 0) { - this.sqlParams.push(parseInt(maxExportLimit)); - sql += " LIMIT ? "; + //变更 + // this.sqlParams.push(parseInt(maxExportLimit)); + // sql += " LIMIT ? "; + sql += ` LIMIT ${parseInt(maxExportLimit)} + `; } if (!isExport) { - this.sqlParams.push((page - 1) * size); - this.sqlParams.push(parseInt(size)); - sql += " LIMIT ?,? "; + //变更 + // this.sqlParams.push((page - 1) * size); + // this.sqlParams.push(parseInt(size)); + // sql += " LIMIT ?,? "; + sql += ` LIMIT ${parseInt(size)} OFFSET ${(page - 1) * size} `; } let params = []; params = params.concat(this.sqlParams); @@ -362,7 +369,9 @@ let BaseService = class BaseService { if (order && order == key) { sort = option.addOrderBy[key].toUpperCase(); } - find.addOrderBy(SqlString.escapeId(key), this.checkSort(option.addOrderBy[key].toUpperCase())); + //变更 + // find.addOrderBy(SqlString.escapeId(key), this.checkSort(option.addOrderBy[key].toUpperCase())); + find.addOrderBy('"'+key+'"', this.checkSort(option.addOrderBy[key].toUpperCase())); } } // 关键字模糊搜索 @@ -397,10 +406,12 @@ let BaseService = class BaseService { c[key] = query[key]; const eq = query[key] instanceof Array ? "in" : "="; if (eq === "in") { - find.andWhere(`${key} ${eq} (:${key})`, c); + //变更 + find.andWhere(`"${key}" ${eq} (:${key})`, c); } else { - find.andWhere(`${key} ${eq} :${key}`, c); + //变更 + find.andWhere(`"${key}" ${eq} :${key}`, c); } this.sqlParams.push(query[key]); } @@ -433,7 +444,9 @@ let BaseService = class BaseService { throw new validate_1.CoolValidateException(global_1.ERRINFO.SORTFIELD); } for (const i in sorts) { - find.addOrderBy(SqlString.escapeId(orders[i]), this.checkSort(sorts[i])); + //变更 + // find.addOrderBy(SqlString.escapeId(orders[i]), this.checkSort(sorts[i])); + find.addOrderBy('"'+orders[i]+'"', this.checkSort(sorts[i])); } } if (option === null || option === void 0 ? void 0 : option.extend) {