@less-is-more/less-js 1.2.12 → 1.2.16

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.2.12",
3
+ "version": "1.2.16",
4
4
  "description": "Fast develop kit for nodejs",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -12,7 +12,7 @@
12
12
  },
13
13
  "repository": {
14
14
  "type": "git",
15
- "url": "https://gitee.com/lim/less-js.git"
15
+ "url": "https://gitee.com/shengapp/lim-js"
16
16
  },
17
17
  "author": "Less Is More",
18
18
  "license": "MIT",
@@ -20,20 +20,20 @@
20
20
  "@alicloud/pop-core": "^1.7.10",
21
21
  "ejs": "^3.1.6",
22
22
  "fs-extra": "^10.0.0",
23
- "inquirer": "^8.1.2",
23
+ "inquirer": "^8.2.0",
24
24
  "multiparty": "^4.2.2",
25
- "mysql2": "^2.2.5",
26
- "pg-hstore": "^2.3.3",
25
+ "mysql2": "^2.3.3",
26
+ "pg-hstore": "^2.3.4",
27
27
  "querystring": "^0.2.1",
28
- "redis": "^3.1.2",
29
- "sequelize": "^6.6.2",
30
- "validator": "^13.6.0"
28
+ "redis": "^4.0.1",
29
+ "sequelize": "^6.13.0",
30
+ "validator": "^13.7.0"
31
31
  },
32
32
  "devDependencies": {
33
33
  "body": "^5.1.0",
34
- "mocha": "^8.3.2",
35
- "webpack": "^5.35.1",
36
- "webpack-cli": "^4.6.0",
34
+ "mocha": "^9.1.3",
35
+ "webpack": "^5.66.0",
36
+ "webpack-cli": "^4.9.1",
37
37
  "webpack-node-externals": "^3.0.0"
38
38
  }
39
39
  }
package/src/db.js CHANGED
@@ -102,7 +102,7 @@ module.exports = class Db {
102
102
  await this.add(model, nNewData);
103
103
  } else {
104
104
  let needUpdate = false;
105
- if ( compareColumn.length > 0) {
105
+ if (compareColumn.length > 0) {
106
106
  const nOldData = oldData[nOldIndex];
107
107
  for (let nColumn of compareColumn) {
108
108
  if (nOldData[nColumn] !== nNewData[nColumn]) {
@@ -164,7 +164,7 @@ module.exports = class Db {
164
164
  * @param {*} attributes 只返回属性
165
165
  * @returns
166
166
  */
167
- static async findAll(
167
+ static async findAll(
168
168
  model,
169
169
  params = {},
170
170
  order = [["id", "desc"]],
@@ -202,10 +202,26 @@ module.exports = class Db {
202
202
  }
203
203
  }
204
204
 
205
- static async sql(sql, values = [], type = this.SQL_TYPE_SELECT) {
206
- return await this.getInstance().query(sql, {
205
+ static async sql(
206
+ sql,
207
+ values = [],
208
+ type = this.SQL_TYPE_SELECT,
209
+ modelFormat = false
210
+ ) {
211
+ const result = await this.getInstance().query(sql, {
207
212
  type: type,
208
213
  replacements: values,
209
214
  });
215
+ if (modelFormat) {
216
+ return JSON.parse(this._toHump(JSON.stringify(result)));
217
+ } else {
218
+ return result;
219
+ }
220
+ }
221
+
222
+ static _toHump(text) {
223
+ return text.replace(/\_(\w)/g, (all, letter) => {
224
+ return letter.toUpperCase();
225
+ });
210
226
  }
211
227
  };
package/src/router.js CHANGED
@@ -53,8 +53,7 @@ module.exports = class Router {
53
53
  }
54
54
 
55
55
  static _getPath(req) {
56
- console.log("method: " + req.method);
57
- console.log("path: " + req.path);
56
+ console.log("path:", req.method, req.path);
58
57
  const paths = req.path.split("/");
59
58
  const className = paths.length > 2 ? "/" + paths[paths.length - 2] : "/";
60
59
  const methodName = paths[paths.length - 1];
@@ -73,8 +72,8 @@ module.exports = class Router {
73
72
  if (req.method == "POST") {
74
73
  if (isFile) {
75
74
  await this._getFile(req);
76
- console.log("params", req.params);
77
- console.log("files", req.files);
75
+ console.log("params:", req.params);
76
+ console.log("files:", req.files);
78
77
  } else {
79
78
  const data = await promisify(body)(req);
80
79
  console.log("body: " + decodeURIComponent(data));
@@ -106,11 +105,14 @@ module.exports = class Router {
106
105
  static _handleReturn(result, res) {
107
106
  if (!Param.isBlank(result)) {
108
107
  if (result instanceof Ret) {
108
+ console.log("return:", result.toString());
109
109
  res.send(result.toString());
110
110
  } else {
111
111
  if (typeof result === "string") {
112
+ console.log("return:", result);
112
113
  res.send(result);
113
114
  } else {
115
+ console.log("return:", JSON.stringify(result));
114
116
  res.send(JSON.stringify(result));
115
117
  }
116
118
  }
package/test/test-db.js CHANGED
@@ -114,6 +114,15 @@ describe("db.js", () => {
114
114
  let data = await Db.sql("select * from menu where id=?", [1]);
115
115
  console.log(data);
116
116
  });
117
+ it("to model", async () => {
118
+ let data = await Db.sql(
119
+ "select * from menu",
120
+ [],
121
+ Db.SQL_TYPE_SELECT,
122
+ true
123
+ );
124
+ console.log(JSON.stringify(data));
125
+ });
117
126
  it("insert", async () => {
118
127
  let data = await Db.sql(
119
128
  "insert into menu (name) values(?)",
@@ -177,5 +186,5 @@ describe("db.js", () => {
177
186
  console.log(data);
178
187
  assert(data.length > 0, "no data");
179
188
  });
180
- })
189
+ });
181
190
  });