@vanit-co/sql-ts 0.6.0 → 0.8.0
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/dist/index.js +4 -4
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -26,7 +26,7 @@ const stringfyIdentifierAndRaw = (quote = '') => (s) => {
|
|
|
26
26
|
return [strings, binds, [...merge, ss, bs.content]];
|
|
27
27
|
}
|
|
28
28
|
else if (bs && bs[SYM_IDENTIFIER]) {
|
|
29
|
-
return [strings, binds, [...merge, ss, (quote + bs.content + quote)]];
|
|
29
|
+
return [strings, binds, [...merge, ss, (quote + bs.content.replaceAll(quote, quote + quote) + quote)]];
|
|
30
30
|
}
|
|
31
31
|
else if (bs !== undefined) {
|
|
32
32
|
return [[...strings, merge.join('') + ss], [...binds, bs], []];
|
|
@@ -115,7 +115,7 @@ const alias = transformer(tableWithAlias, (s, c) => [
|
|
|
115
115
|
[' as ', identifier(`${c.prefix}_${c.name}`)]
|
|
116
116
|
]);
|
|
117
117
|
const buildTag = (fn) => (strings, ...binds) => {
|
|
118
|
-
const [s, v] = ramda.transpose(zipLongest(strings, binds).flatMap(fn));
|
|
118
|
+
const [s, v] = ramda.transpose(zipLongest(strings, binds.map(b => b === undefined ? null : b)).flatMap(fn));
|
|
119
119
|
return result(fragment(s, v ?? []));
|
|
120
120
|
};
|
|
121
121
|
const sql = buildTag(pure);
|
|
@@ -129,14 +129,14 @@ const insert = (table, ...colsVals) => {
|
|
|
129
129
|
const colBinds = columns.map(c => identifier(c));
|
|
130
130
|
const [valStrings, valBinds] = colsVals.reduce(([ss, bs], row, rowIdx) => {
|
|
131
131
|
const rowStrings = columns.map((_, colIdx) => colIdx === 0 ? (rowIdx === 0 ? ') values (' : ') ,(') : ' ,');
|
|
132
|
-
return [[...ss, ...rowStrings], [...bs, ...columns.map(c => row[c])]];
|
|
132
|
+
return [[...ss, ...rowStrings], [...bs, ...columns.map(c => row[c] ?? null)]];
|
|
133
133
|
}, [[], []]);
|
|
134
134
|
return result(fragment(['insert into ', ...colStrings, ...valStrings, ')'], [identifier(tableName), ...colBinds, ...valBinds]));
|
|
135
135
|
};
|
|
136
136
|
const update = (table, colsVals) => {
|
|
137
137
|
const tableName = table[SYM_TABLE].name;
|
|
138
138
|
const entries = Object.entries(colsVals);
|
|
139
|
-
const [strings, binds] = entries.reduce(([ss, bs], [colName, value], i) => [[...ss, i === 0 ? ' set ' : ' ,', ' = '], [...bs, identifier(colName), value]], [['update '], [identifier(tableName)]]);
|
|
139
|
+
const [strings, binds] = entries.reduce(([ss, bs], [colName, value], i) => [[...ss, i === 0 ? ' set ' : ' ,', ' = '], [...bs, identifier(colName), value ?? null]], [['update '], [identifier(tableName)]]);
|
|
140
140
|
return result(fragment([...strings, ''], binds));
|
|
141
141
|
};
|
|
142
142
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vanit-co/sql-ts",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"description": "A TypeScript SQL query builder using tagged template literals. Write plain SQL with safe, automatic parameter binding and properly quoted identifiers. No DSL to learn, no magic, no ORM.",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"main": "./dist/index.js",
|