@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 +1 -1
- package/src/localStorage.js +12 -2
package/package.json
CHANGED
package/src/localStorage.js
CHANGED
|
@@ -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 ${
|
|
62
|
+
colDef += ` DEFAULT ${this.#toSQLValue(def.defaultValue)}`;
|
|
63
63
|
}
|
|
64
64
|
if (def.values?.length) {
|
|
65
|
-
colDef += ` CHECK(${col} IN (${def.values.map(v =>
|
|
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
|