This commit is contained in:
Benjamin Toby 2024-12-12 14:38:37 +01:00
parent 1c2798b93f
commit 2a4e111160
2 changed files with 13 additions and 2 deletions

View File

@ -1,5 +1,7 @@
// @ts-check
const EJSON = require("./ejson");
/** @type {import("../types").SerializeQueryFnType} */
function serializeQuery({ query }) {
let str = "?";
@ -7,10 +9,19 @@ function serializeQuery({ query }) {
/** @type {string[]} */
const queryArr = [];
keys.forEach((key) => {
if (!key || !query[key]) return;
queryArr.push(`${key}=${query[key]}`);
const value = query[key];
if (typeof value === "object") {
const jsonStr = EJSON.stringify(value);
queryArr.push(`${key}=${encodeURIComponent(String(jsonStr))}`);
} else if (typeof value === "string" || typeof value === "number") {
queryArr.push(`${key}=${encodeURIComponent(value)}`);
}
});
str += queryArr.join("&");
return str;
}

View File

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