@less-is-more/less-js 1.4.9 → 1.4.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@less-is-more/less-js",
3
- "version": "1.4.9",
3
+ "version": "1.4.11",
4
4
  "description": "Fast develop kit for nodejs",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
package/src/db.js CHANGED
@@ -225,10 +225,19 @@ module.exports = class Db {
225
225
  replacements: values,
226
226
  });
227
227
  if (modelFormat) {
228
- return JSON.parse(this._toHump(JSON.stringify(result)));
229
- } else {
230
- return result;
228
+ // 如果不为空,循环转换为驼峰
229
+ if (result) {
230
+ for (let n of result) {
231
+ for (let key in n) {
232
+ if (key.includes("_")) {
233
+ n[this._toHump(key)] = n[key];
234
+ delete n[key];
235
+ }
236
+ }
237
+ }
238
+ }
231
239
  }
240
+ return result;
232
241
  }
233
242
 
234
243
  static _toHump(text) {
package/src/router.js CHANGED
@@ -18,6 +18,8 @@ module.exports = class Router {
18
18
  */
19
19
  static async route(targets, req, res, context) {
20
20
  const startTime = new Date().getTime();
21
+ // 兼容非阿里云
22
+ await this._handleParams(req);
21
23
  const { methodName, className } = this._getPath(req);
22
24
  if (methodName) {
23
25
  const controller = targets[className];
@@ -27,8 +29,6 @@ module.exports = class Router {
27
29
  const method = controller[methodName];
28
30
  if (method) {
29
31
  try {
30
- // 兼容非阿里云
31
- await this._handleParams(req);
32
32
  // before
33
33
  if (targets.before) {
34
34
  console.log("start before action");
@@ -61,7 +61,13 @@ module.exports = class Router {
61
61
  }
62
62
 
63
63
  static _getPath(req) {
64
- console.log("path:", req.method, req.path, req.headers["content-type"]);
64
+ console.log(
65
+ "path:",
66
+ req.method,
67
+ req.path,
68
+ req.headers["content-type"],
69
+ JSON.stringify(req.params)
70
+ );
65
71
  const paths = req.path.split("/");
66
72
  const className = paths.length > 2 ? "/" + paths[paths.length - 2] : "/";
67
73
  const methodName = paths[paths.length - 1];
package/test/test-db.js CHANGED
@@ -116,7 +116,7 @@ describe("db.js", () => {
116
116
  });
117
117
  it("to model", async () => {
118
118
  let data = await Db.sql(
119
- "select * from menu",
119
+ "select * from city",
120
120
  [],
121
121
  Db.SQL_TYPE_SELECT,
122
122
  true