mysql-rest
Advanced tools
Comparing version 0.6.5 to 0.6.6
@@ -20,2 +20,3 @@ //define class | ||
async list(req, res) { | ||
let { _refby, _include } = req.query; | ||
let queryParamsObj = {}; | ||
@@ -31,2 +32,17 @@ queryParamsObj.query = ""; | ||
); | ||
if (_refby && results.length > 0) { | ||
let refTables = _refby.split(";"); | ||
for (let refTable of refTables) { | ||
await this.mysql.refBy(results, refTable); | ||
} | ||
} | ||
if (_include && results.length > 0) { | ||
let includeTables = _include.split(";"); | ||
for (let includeTable of includeTables) { | ||
await this.mysql.include(results, includeTable); | ||
} | ||
} | ||
let total = await this.total(req, res); | ||
@@ -33,0 +49,0 @@ let page = parseInt(req.query._p || "0"); |
@@ -7,2 +7,3 @@ "use strict"; | ||
const assert = require("assert"); | ||
const lodash = require("lodash"); | ||
@@ -1333,2 +1334,39 @@ //define class§ | ||
} | ||
async refBy(results, refTable) { | ||
let items = refTable.split(","); | ||
if (items.length !== 4) { | ||
return; | ||
} | ||
let ids = [].concat(results).map((o) => o[items[0]]); | ||
let sql = ` | ||
SELECT ${items[2]} FROM ${items[1]} | ||
WHERE ${items[2]} IN (${ids.join(",")}) | ||
GROUP BY ${items[2]}; | ||
`; | ||
let refByResults = await this.exec(sql, []); | ||
let refs = refByResults.map((o) => o[items[2]]); | ||
results.map((o) => { | ||
o[items[3]] = refs.includes(o[items[0]]); | ||
return o; | ||
}); | ||
} | ||
async include(results, includeTable) { | ||
let items = includeTable.split(","); | ||
if (items.length !== 3) { | ||
return; | ||
} | ||
let ids = [].concat(results).map((o) => o[items[0]]); | ||
let sql = ` | ||
SELECT * FROM ${items[1]} | ||
WHERE ${items[2]} IN (${lodash.uniq(ids).join(",")}); | ||
`; | ||
let includeResults = await this.exec(sql, []); | ||
results.map((o) => { | ||
let foud = includeResults.filter((i) => i[items[2]] === o[items[0]]); | ||
o[items[0]] = foud.length > 0 ? foud[0] : null; | ||
return o; | ||
}); | ||
} | ||
} | ||
@@ -1335,0 +1373,0 @@ |
{ | ||
"name": "mysql-rest", | ||
"version": "0.6.5", | ||
"version": "0.6.6", | ||
"description": "One command to generate REST APIs for any MySql database, support multi databases", | ||
@@ -34,2 +34,3 @@ "main": "index.js", | ||
"express": "^4.19.2", | ||
"lodash": "^4.17.21", | ||
"morgan": "^1.10.0", | ||
@@ -36,0 +37,0 @@ "multer": "^1.4.4", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2130790
4818
11
+ Addedlodash@^4.17.21
+ Addedlodash@4.17.21(transitive)