This commit is contained in:
Benjamin Toby 2025-01-01 09:01:39 +01:00
parent c208975b44
commit 956497a499
3 changed files with 34 additions and 7 deletions

View File

@ -0,0 +1,30 @@
// @ts-check
const EJSON = require("./ejson");
/**
*
* @param {string | Object<string,any>} query
* @returns {Object<string,any>}
*/
function deserializeQuery(query) {
/** @type {Object<string,any>} */
let queryObject =
typeof query == "object" ? query : Object(EJSON.parse(query));
const keys = Object.keys(queryObject);
for (let i = 0; i < keys.length; i++) {
const key = keys[i];
const value = queryObject[key];
if (typeof value == "string") {
if (value.match(/^\{|^\[/)) {
queryObject[key] = EJSON.parse(value);
}
}
}
return queryObject;
}
module.exports = deserializeQuery;

View File

@ -1,6 +1,6 @@
{
"name": "@moduletrace/datasquirel",
"version": "3.2.9",
"version": "3.3.0",
"description": "Cloud-based SQL data management tool",
"main": "index.js",
"bin": {

View File

@ -81,16 +81,13 @@ async function get({
const queryObject = {
db: process.env.DSQL_API_DB_NAME || String(db),
query: String(
query
.replace(/\n|\r|\n\r/g, "")
.replace(/ {2,}/g, " ")
.replace(/ /g, "+")
query.replace(/\n|\r|\n\r/g, "").replace(/ {2,}/g, " ")
),
queryValues: queryValues ? JSON.stringify(queryValues) : undefined,
tableName,
};
const queryString = serializeQuery({ query: queryObject });
const queryString = serializeQuery({ ...queryObject });
let path = `/api/query/${
user_id || grabedHostNames.user_id
@ -109,7 +106,7 @@ async function get({
},
port,
hostname: host,
path: encodeURI(path),
path,
};
scheme