csv-to-pg 3.10.5 → 3.10.6
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/esm/parse.js +16 -2
- package/package.json +2 -2
- package/parse.js +16 -2
package/esm/parse.js
CHANGED
|
@@ -79,9 +79,13 @@ const escapeArrayElement = (value) => {
|
|
|
79
79
|
};
|
|
80
80
|
/**
|
|
81
81
|
* Convert an array to PostgreSQL array literal format with proper escaping.
|
|
82
|
+
* Returns '{}' for empty arrays instead of undefined.
|
|
82
83
|
*/
|
|
83
84
|
const psqlArray = (value) => {
|
|
84
|
-
if (Array.isArray(value)
|
|
85
|
+
if (Array.isArray(value)) {
|
|
86
|
+
if (value.length === 0) {
|
|
87
|
+
return '{}';
|
|
88
|
+
}
|
|
85
89
|
return `{${value.map(escapeArrayElement).join(',')}}`;
|
|
86
90
|
}
|
|
87
91
|
return undefined;
|
|
@@ -172,12 +176,22 @@ export class ValidationError extends Error {
|
|
|
172
176
|
}
|
|
173
177
|
}
|
|
174
178
|
/**
|
|
175
|
-
*
|
|
179
|
+
* Check if a type is an array type (e.g. 'text[]', 'uuid[]', 'jsonb[]')
|
|
180
|
+
*/
|
|
181
|
+
const isArrayType = (type) => type.endsWith('[]');
|
|
182
|
+
/**
|
|
183
|
+
* Helper to create a NULL node or throw if field is required.
|
|
184
|
+
* For array types, emits an empty array literal '{}' instead of NULL.
|
|
176
185
|
*/
|
|
177
186
|
const makeNullOrThrow = (fieldName, rawValue, type, required, reason) => {
|
|
178
187
|
if (required) {
|
|
179
188
|
throw new ValidationError(fieldName, rawValue, type, reason);
|
|
180
189
|
}
|
|
190
|
+
if (isArrayType(type)) {
|
|
191
|
+
return nodes.aConst({
|
|
192
|
+
sval: ast.string({ sval: '{}' })
|
|
193
|
+
});
|
|
194
|
+
}
|
|
181
195
|
return nodes.aConst({ isnull: true });
|
|
182
196
|
};
|
|
183
197
|
// type (int, text, etc)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "csv-to-pg",
|
|
3
|
-
"version": "3.10.
|
|
3
|
+
"version": "3.10.6",
|
|
4
4
|
"author": "Dan Lynch <pyramation@gmail.com>",
|
|
5
5
|
"description": "csv to pg statements",
|
|
6
6
|
"main": "index.js",
|
|
@@ -50,5 +50,5 @@
|
|
|
50
50
|
"js-yaml": "^4.1.0",
|
|
51
51
|
"pgsql-deparser": "^17.18.1"
|
|
52
52
|
},
|
|
53
|
-
"gitHead": "
|
|
53
|
+
"gitHead": "bb4bb793b38016e5e88c0271f8924b0362463596"
|
|
54
54
|
}
|
package/parse.js
CHANGED
|
@@ -85,9 +85,13 @@ const escapeArrayElement = (value) => {
|
|
|
85
85
|
};
|
|
86
86
|
/**
|
|
87
87
|
* Convert an array to PostgreSQL array literal format with proper escaping.
|
|
88
|
+
* Returns '{}' for empty arrays instead of undefined.
|
|
88
89
|
*/
|
|
89
90
|
const psqlArray = (value) => {
|
|
90
|
-
if (Array.isArray(value)
|
|
91
|
+
if (Array.isArray(value)) {
|
|
92
|
+
if (value.length === 0) {
|
|
93
|
+
return '{}';
|
|
94
|
+
}
|
|
91
95
|
return `{${value.map(escapeArrayElement).join(',')}}`;
|
|
92
96
|
}
|
|
93
97
|
return undefined;
|
|
@@ -181,12 +185,22 @@ class ValidationError extends Error {
|
|
|
181
185
|
}
|
|
182
186
|
exports.ValidationError = ValidationError;
|
|
183
187
|
/**
|
|
184
|
-
*
|
|
188
|
+
* Check if a type is an array type (e.g. 'text[]', 'uuid[]', 'jsonb[]')
|
|
189
|
+
*/
|
|
190
|
+
const isArrayType = (type) => type.endsWith('[]');
|
|
191
|
+
/**
|
|
192
|
+
* Helper to create a NULL node or throw if field is required.
|
|
193
|
+
* For array types, emits an empty array literal '{}' instead of NULL.
|
|
185
194
|
*/
|
|
186
195
|
const makeNullOrThrow = (fieldName, rawValue, type, required, reason) => {
|
|
187
196
|
if (required) {
|
|
188
197
|
throw new ValidationError(fieldName, rawValue, type, reason);
|
|
189
198
|
}
|
|
199
|
+
if (isArrayType(type)) {
|
|
200
|
+
return utils_1.nodes.aConst({
|
|
201
|
+
sval: utils_1.ast.string({ sval: '{}' })
|
|
202
|
+
});
|
|
203
|
+
}
|
|
190
204
|
return utils_1.nodes.aConst({ isnull: true });
|
|
191
205
|
};
|
|
192
206
|
// type (int, text, etc)
|