Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mysql-rest

Package Overview
Dependencies
Maintainers
0
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mysql-rest - npm Package Compare versions

Comparing version 0.6.5 to 0.6.6

16

lib/xctrl.js

@@ -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 @@

3

package.json
{
"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",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc