@cool-midway+core+6.0.2.patch 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. diff --git a/node_modules/@cool-midway/core/module/import.js b/node_modules/@cool-midway/core/module/import.js
  2. index 38741fb..0437df1 100644
  3. --- a/node_modules/@cool-midway/core/module/import.js
  4. +++ b/node_modules/@cool-midway/core/module/import.js
  5. @@ -12,7 +12,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
  6. exports.CoolModuleImport = void 0;
  7. const decorator_1 = require("@midwayjs/decorator");
  8. const core_1 = require("../exception/core");
  9. -const Importer = require("mysql2-import");
  10. +// const Importer = require("mysql2-import");
  11. +const { Client } = require('pg')
  12. const fs = require("fs");
  13. const config_1 = require("./config");
  14. const path = require("path");
  15. @@ -26,7 +27,8 @@ let CoolModuleImport = class CoolModuleImport {
  16. async init() {
  17. // 是否需要导入
  18. if (this.coolConfig.initDB) {
  19. - await this.checkDbVersion();
  20. + //变更
  21. + // await this.checkDbVersion();
  22. const modules = this.coolModuleConfig.modules;
  23. const importLockPath = path.join(`${this.app.getBaseDir()}`, "..", "lock");
  24. if (!fs.existsSync(importLockPath)) {
  25. @@ -67,32 +69,63 @@ let CoolModuleImport = class CoolModuleImport {
  26. .ormConfig) === null || _a === void 0 ? void 0 : _a.default)
  27. ? this.ormConfig.default
  28. : this.ormConfig;
  29. - const importer = new Importer({
  30. - host,
  31. - password,
  32. - database,
  33. - charset,
  34. - port,
  35. - user: username,
  36. - });
  37. - await importer
  38. - .import(sqlPath)
  39. - .then(async () => {
  40. - clearInterval(t);
  41. - this.coreLogger.info("\x1B[36m [cool:core] midwayjs cool core init " +
  42. - module +
  43. - " database complete \x1B[0m");
  44. - fs.writeFileSync(lockPath, `time consuming:${second}s`);
  45. - })
  46. - .catch((err) => {
  47. - clearTimeout(t);
  48. - this.coreLogger.error("\x1B[36m [cool:core] midwayjs cool core init " +
  49. - module +
  50. - " database err please manual import \x1B[0m");
  51. - fs.writeFileSync(lockPath, `time consuming:${second}s`);
  52. - this.coreLogger.error(err);
  53. - this.coreLogger.error(`自动初始化模块[${module}]数据库失败,尝试手动导入数据库`);
  54. +
  55. + const client = new Client({
  56. + user: username,
  57. + host: host,
  58. + database: database,
  59. + password: password,
  60. + port: port,
  61. + })
  62. + //变更
  63. + client.connect();
  64. +
  65. + const sql = fs.readFileSync(sqlPath).toString();
  66. +
  67. + await client.query(sql).then(async () => {
  68. + clearInterval(t);
  69. + this.coreLogger.info("\x1B[36m [cool:core] midwayjs cool core init " +
  70. + module +
  71. + " database complete \x1B[0m");
  72. + fs.writeFileSync(lockPath, `time consuming:${second}s`);
  73. + })
  74. + .catch((err) => {
  75. + clearTimeout(t);
  76. + this.coreLogger.error("\x1B[36m [cool:core] midwayjs cool core init " +
  77. + module +
  78. + " database err please manual import \x1B[0m");
  79. + fs.writeFileSync(lockPath, `time consuming:${second}s`);
  80. + this.coreLogger.error(err);
  81. + this.coreLogger.error(`自动初始化模块[${module}]数据库失败,尝试手动导入数据库`);
  82. });
  83. +
  84. +
  85. + // const importer = new Importer({
  86. + // host,
  87. + // password,
  88. + // database,
  89. + // charset,
  90. + // port,
  91. + // user: username,
  92. + // });
  93. + // await importer
  94. + // .import(sqlPath)
  95. + // .then(async () => {
  96. + // clearInterval(t);
  97. + // this.coreLogger.info("\x1B[36m [cool:core] midwayjs cool core init " +
  98. + // module +
  99. + // " database complete \x1B[0m");
  100. + // fs.writeFileSync(lockPath, `time consuming:${second}s`);
  101. + // })
  102. + // .catch((err) => {
  103. + // clearTimeout(t);
  104. + // this.coreLogger.error("\x1B[36m [cool:core] midwayjs cool core init " +
  105. + // module +
  106. + // " database err please manual import \x1B[0m");
  107. + // fs.writeFileSync(lockPath, `time consuming:${second}s`);
  108. + // this.coreLogger.error(err);
  109. + // this.coreLogger.error(`自动初始化模块[${module}]数据库失败,尝试手动导入数据库`);
  110. + // });
  111. }
  112. }
  113. /**
  114. diff --git a/node_modules/@cool-midway/core/service/base.js b/node_modules/@cool-midway/core/service/base.js
  115. index b8ff5cd..d7c6c55 100644
  116. --- a/node_modules/@cool-midway/core/service/base.js
  117. +++ b/node_modules/@cool-midway/core/service/base.js
  118. @@ -145,16 +145,23 @@ let BaseService = class BaseService {
  119. if (!(await this.paramSafetyCheck(order + sort))) {
  120. throw new validate_1.CoolValidateException("非法传参~");
  121. }
  122. - sql += ` ORDER BY ${SqlString.escapeId(order)} ${this.checkSort(sort)}`;
  123. + //变更
  124. + // sql += ` ORDER BY ${SqlString.escapeId(order)} ${this.checkSort(sort)}`;
  125. + sql += ` ORDER BY "${order}" ${this.checkSort(sort)}`;
  126. }
  127. if (isExport && maxExportLimit > 0) {
  128. - this.sqlParams.push(parseInt(maxExportLimit));
  129. - sql += " LIMIT ? ";
  130. + //变更
  131. + // this.sqlParams.push(parseInt(maxExportLimit));
  132. + // sql += " LIMIT ? ";
  133. + sql += ` LIMIT ${parseInt(maxExportLimit)}
  134. + `;
  135. }
  136. if (!isExport) {
  137. - this.sqlParams.push((page - 1) * size);
  138. - this.sqlParams.push(parseInt(size));
  139. - sql += " LIMIT ?,? ";
  140. + //变更
  141. + // this.sqlParams.push((page - 1) * size);
  142. + // this.sqlParams.push(parseInt(size));
  143. + // sql += " LIMIT ?,? ";
  144. + sql += ` LIMIT ${parseInt(size)} OFFSET ${(page - 1) * size} `;
  145. }
  146. let params = [];
  147. params = params.concat(this.sqlParams);
  148. @@ -362,7 +369,9 @@ let BaseService = class BaseService {
  149. if (order && order == key) {
  150. sort = option.addOrderBy[key].toUpperCase();
  151. }
  152. - find.addOrderBy(SqlString.escapeId(key), this.checkSort(option.addOrderBy[key].toUpperCase()));
  153. + //变更
  154. + // find.addOrderBy(SqlString.escapeId(key), this.checkSort(option.addOrderBy[key].toUpperCase()));
  155. + find.addOrderBy('"'+key+'"', this.checkSort(option.addOrderBy[key].toUpperCase()));
  156. }
  157. }
  158. // 关键字模糊搜索
  159. @@ -397,10 +406,12 @@ let BaseService = class BaseService {
  160. c[key] = query[key];
  161. const eq = query[key] instanceof Array ? "in" : "=";
  162. if (eq === "in") {
  163. - find.andWhere(`${key} ${eq} (:${key})`, c);
  164. + //变更
  165. + find.andWhere(`"${key}" ${eq} (:${key})`, c);
  166. }
  167. else {
  168. - find.andWhere(`${key} ${eq} :${key}`, c);
  169. + //变更
  170. + find.andWhere(`"${key}" ${eq} :${key}`, c);
  171. }
  172. this.sqlParams.push(query[key]);
  173. }
  174. @@ -433,7 +444,9 @@ let BaseService = class BaseService {
  175. throw new validate_1.CoolValidateException(global_1.ERRINFO.SORTFIELD);
  176. }
  177. for (const i in sorts) {
  178. - find.addOrderBy(SqlString.escapeId(orders[i]), this.checkSort(sorts[i]));
  179. + //变更
  180. + // find.addOrderBy(SqlString.escapeId(orders[i]), this.checkSort(sorts[i]));
  181. + find.addOrderBy('"'+orders[i]+'"', this.checkSort(sorts[i]));
  182. }
  183. }
  184. if (option === null || option === void 0 ? void 0 : option.extend) {