csv-to-pg 3.10.4 → 3.10.5
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 +33 -0
- package/package.json +2 -2
- package/parse.js +33 -0
package/esm/parse.js
CHANGED
|
@@ -407,6 +407,39 @@ const getCoercionFunc = (type, from, opts, fieldName) => {
|
|
|
407
407
|
});
|
|
408
408
|
return wrapValue(val, opts);
|
|
409
409
|
};
|
|
410
|
+
case 'jsonb[]':
|
|
411
|
+
return (record) => {
|
|
412
|
+
const rawValue = record[from[0]];
|
|
413
|
+
if (isNullToken(rawValue)) {
|
|
414
|
+
return makeNullOrThrow(fieldName, rawValue, type, required, 'value is empty or null');
|
|
415
|
+
}
|
|
416
|
+
if (Array.isArray(rawValue)) {
|
|
417
|
+
if (rawValue.length === 0) {
|
|
418
|
+
return makeNullOrThrow(fieldName, rawValue, type, required, 'array is empty');
|
|
419
|
+
}
|
|
420
|
+
const elements = rawValue.map(el => JSON.stringify(el));
|
|
421
|
+
const arrayLiteral = psqlArray(elements);
|
|
422
|
+
if (isEmpty(arrayLiteral)) {
|
|
423
|
+
return makeNullOrThrow(fieldName, rawValue, type, required, 'failed to format array');
|
|
424
|
+
}
|
|
425
|
+
const val = nodes.aConst({
|
|
426
|
+
sval: ast.string({ sval: String(arrayLiteral) })
|
|
427
|
+
});
|
|
428
|
+
return wrapValue(val, opts);
|
|
429
|
+
}
|
|
430
|
+
// If it's a string, try to parse as JSON array
|
|
431
|
+
if (typeof rawValue === 'string') {
|
|
432
|
+
const parsed = parseJson(cleanseEmptyStrings(rawValue));
|
|
433
|
+
if (isEmpty(parsed)) {
|
|
434
|
+
return makeNullOrThrow(fieldName, rawValue, type, required, 'value is empty or null');
|
|
435
|
+
}
|
|
436
|
+
const val = nodes.aConst({
|
|
437
|
+
sval: ast.string({ sval: String(parsed) })
|
|
438
|
+
});
|
|
439
|
+
return wrapValue(val, opts);
|
|
440
|
+
}
|
|
441
|
+
return makeNullOrThrow(fieldName, rawValue, type, required, 'value is not an array');
|
|
442
|
+
};
|
|
410
443
|
default:
|
|
411
444
|
return (record) => {
|
|
412
445
|
const rawValue = record[from[0]];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "csv-to-pg",
|
|
3
|
-
"version": "3.10.
|
|
3
|
+
"version": "3.10.5",
|
|
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": "3b3735292589a49601f40645ea7880f584a23b77"
|
|
54
54
|
}
|
package/parse.js
CHANGED
|
@@ -416,6 +416,39 @@ const getCoercionFunc = (type, from, opts, fieldName) => {
|
|
|
416
416
|
});
|
|
417
417
|
return (0, utils_2.wrapValue)(val, opts);
|
|
418
418
|
};
|
|
419
|
+
case 'jsonb[]':
|
|
420
|
+
return (record) => {
|
|
421
|
+
const rawValue = record[from[0]];
|
|
422
|
+
if (isNullToken(rawValue)) {
|
|
423
|
+
return makeNullOrThrow(fieldName, rawValue, type, required, 'value is empty or null');
|
|
424
|
+
}
|
|
425
|
+
if (Array.isArray(rawValue)) {
|
|
426
|
+
if (rawValue.length === 0) {
|
|
427
|
+
return makeNullOrThrow(fieldName, rawValue, type, required, 'array is empty');
|
|
428
|
+
}
|
|
429
|
+
const elements = rawValue.map(el => JSON.stringify(el));
|
|
430
|
+
const arrayLiteral = psqlArray(elements);
|
|
431
|
+
if (isEmpty(arrayLiteral)) {
|
|
432
|
+
return makeNullOrThrow(fieldName, rawValue, type, required, 'failed to format array');
|
|
433
|
+
}
|
|
434
|
+
const val = utils_1.nodes.aConst({
|
|
435
|
+
sval: utils_1.ast.string({ sval: String(arrayLiteral) })
|
|
436
|
+
});
|
|
437
|
+
return (0, utils_2.wrapValue)(val, opts);
|
|
438
|
+
}
|
|
439
|
+
// If it's a string, try to parse as JSON array
|
|
440
|
+
if (typeof rawValue === 'string') {
|
|
441
|
+
const parsed = parseJson(cleanseEmptyStrings(rawValue));
|
|
442
|
+
if (isEmpty(parsed)) {
|
|
443
|
+
return makeNullOrThrow(fieldName, rawValue, type, required, 'value is empty or null');
|
|
444
|
+
}
|
|
445
|
+
const val = utils_1.nodes.aConst({
|
|
446
|
+
sval: utils_1.ast.string({ sval: String(parsed) })
|
|
447
|
+
});
|
|
448
|
+
return (0, utils_2.wrapValue)(val, opts);
|
|
449
|
+
}
|
|
450
|
+
return makeNullOrThrow(fieldName, rawValue, type, required, 'value is not an array');
|
|
451
|
+
};
|
|
419
452
|
default:
|
|
420
453
|
return (record) => {
|
|
421
454
|
const rawValue = record[from[0]];
|