@ix-xs/node-comfort 1.0.56 → 1.0.57

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": "@ix-xs/node-comfort",
3
- "version": "1.0.56",
3
+ "version": "1.0.57",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "types": "types/index.d.ts",
@@ -59,10 +59,10 @@ module.exports = class localStorage {
59
59
  if (def.notNull) colDef += " NOT NULL";
60
60
  if (def.unique) colDef += " UNIQUE";
61
61
  if (def.defaultValue !== undefined) {
62
- colDef += ` DEFAULT ${JSON.stringify(def.defaultValue)}`;
62
+ colDef += ` DEFAULT ${this.#toSQLValue(def.defaultValue)}`;
63
63
  }
64
64
  if (def.values?.length) {
65
- colDef += ` CHECK(${col} IN (${def.values.map(v => JSON.stringify(v)).join(", ")}))`;
65
+ colDef += ` CHECK(${col} IN (${def.values.map(v => this.#toSQLValue(v)).join(", ")}))`;
66
66
  }
67
67
 
68
68
  return colDef;
@@ -106,6 +106,16 @@ module.exports = class localStorage {
106
106
  return `${firstCol} DESC`;
107
107
  }
108
108
 
109
+ #toSQLValue(value) {
110
+ if (value === null) return "NULL";
111
+ if (typeof value === "number") return String(value);
112
+ if (typeof value === "bigint") return String(value);
113
+ if (typeof value === "boolean") return value ? "1" : "0";
114
+ if (typeof value === "string") return `'${value.replace(/'/g, "''")}'`;
115
+
116
+ return `'${JSON.stringify(value).replace(/'/g, "''")}'`;
117
+ }
118
+
109
119
  /**
110
120
  * @param {object} table
111
121
  * @param {string} table.name