csv-to-pg 3.10.5 → 3.11.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.
Files changed (3) hide show
  1. package/esm/parse.js +16 -2
  2. package/package.json +2 -2
  3. 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) && value.length) {
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
- * Helper to create a NULL node or throw if field is required
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.5",
3
+ "version": "3.11.0",
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": "3b3735292589a49601f40645ea7880f584a23b77"
53
+ "gitHead": "b8ed57a447cd71b93094edf362e72b94801e5f3a"
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) && value.length) {
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
- * Helper to create a NULL node or throw if field is required
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)