csv-to-pg 3.3.3 → 3.4.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/esm/parser.js +5 -3
- package/esm/utils.js +12 -5
- package/package.json +6 -6
- package/parser.d.ts +1 -0
- package/parser.js +5 -3
- package/utils.d.ts +4 -2
- package/utils.js +12 -5
package/esm/parser.js
CHANGED
|
@@ -9,7 +9,7 @@ export class Parser {
|
|
|
9
9
|
}
|
|
10
10
|
async parse(data) {
|
|
11
11
|
const config = this.config;
|
|
12
|
-
const { schema, table, singleStmts, conflict, headers, delimeter } = config;
|
|
12
|
+
const { schema, table, singleStmts, conflict, conflictDoNothing, headers, delimeter } = config;
|
|
13
13
|
const opts = {};
|
|
14
14
|
if (headers)
|
|
15
15
|
opts.headers = headers;
|
|
@@ -44,7 +44,8 @@ export class Parser {
|
|
|
44
44
|
table,
|
|
45
45
|
types,
|
|
46
46
|
record,
|
|
47
|
-
conflict
|
|
47
|
+
conflict,
|
|
48
|
+
conflictDoNothing
|
|
48
49
|
}));
|
|
49
50
|
return deparse(stmts);
|
|
50
51
|
}
|
|
@@ -54,7 +55,8 @@ export class Parser {
|
|
|
54
55
|
table,
|
|
55
56
|
types,
|
|
56
57
|
records,
|
|
57
|
-
conflict
|
|
58
|
+
conflict,
|
|
59
|
+
conflictDoNothing
|
|
58
60
|
});
|
|
59
61
|
return deparse([stmt]);
|
|
60
62
|
}
|
package/esm/utils.js
CHANGED
|
@@ -106,7 +106,14 @@ const indexElem = (name) => ({
|
|
|
106
106
|
nulls_ordering: 'SORTBY_NULLS_DEFAULT'
|
|
107
107
|
}
|
|
108
108
|
});
|
|
109
|
-
const makeConflictClause = (conflictElems, fields) => {
|
|
109
|
+
const makeConflictClause = (conflictElems, fields, conflictDoNothing) => {
|
|
110
|
+
// If conflictDoNothing is true, generate ON CONFLICT DO NOTHING without specifying columns
|
|
111
|
+
// This catches any unique constraint violation
|
|
112
|
+
if (conflictDoNothing) {
|
|
113
|
+
return {
|
|
114
|
+
action: 'ONCONFLICT_NOTHING'
|
|
115
|
+
};
|
|
116
|
+
}
|
|
110
117
|
if (!conflictElems || !conflictElems.length)
|
|
111
118
|
return undefined;
|
|
112
119
|
const setElems = fields.filter((el) => !conflictElems.includes(el));
|
|
@@ -128,7 +135,7 @@ const makeConflictClause = (conflictElems, fields) => {
|
|
|
128
135
|
};
|
|
129
136
|
}
|
|
130
137
|
};
|
|
131
|
-
export const InsertOne = ({ schema = 'public', table, types, record, conflict }) => ({
|
|
138
|
+
export const InsertOne = ({ schema = 'public', table, types, record, conflict, conflictDoNothing }) => ({
|
|
132
139
|
RawStmt: {
|
|
133
140
|
stmt: {
|
|
134
141
|
InsertStmt: {
|
|
@@ -152,14 +159,14 @@ export const InsertOne = ({ schema = 'public', table, types, record, conflict })
|
|
|
152
159
|
limitOption: 'LIMIT_OPTION_DEFAULT'
|
|
153
160
|
}
|
|
154
161
|
},
|
|
155
|
-
onConflictClause: makeConflictClause(conflict, Object.keys(types)),
|
|
162
|
+
onConflictClause: makeConflictClause(conflict, Object.keys(types), conflictDoNothing),
|
|
156
163
|
override: 'OVERRIDING_NOT_SET'
|
|
157
164
|
}
|
|
158
165
|
},
|
|
159
166
|
stmt_len: 1
|
|
160
167
|
}
|
|
161
168
|
});
|
|
162
|
-
export const InsertMany = ({ schema = 'public', table, types, records, conflict }) => ({
|
|
169
|
+
export const InsertMany = ({ schema = 'public', table, types, records, conflict, conflictDoNothing }) => ({
|
|
163
170
|
RawStmt: {
|
|
164
171
|
stmt: {
|
|
165
172
|
InsertStmt: {
|
|
@@ -181,7 +188,7 @@ export const InsertMany = ({ schema = 'public', table, types, records, conflict
|
|
|
181
188
|
limitOption: 'LIMIT_OPTION_DEFAULT'
|
|
182
189
|
}
|
|
183
190
|
},
|
|
184
|
-
onConflictClause: makeConflictClause(conflict, Object.keys(types)),
|
|
191
|
+
onConflictClause: makeConflictClause(conflict, Object.keys(types), conflictDoNothing),
|
|
185
192
|
override: 'OVERRIDING_NOT_SET'
|
|
186
193
|
}
|
|
187
194
|
},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "csv-to-pg",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.4.0",
|
|
4
4
|
"author": "Dan Lynch <pyramation@gmail.com>",
|
|
5
5
|
"description": "csv to pg statements",
|
|
6
6
|
"main": "index.js",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"@types/js-yaml": "^4.0.9",
|
|
36
36
|
"makage": "^0.1.10",
|
|
37
|
-
"pgsql-parser": "^17.9.
|
|
37
|
+
"pgsql-parser": "^17.9.11"
|
|
38
38
|
},
|
|
39
39
|
"keywords": [
|
|
40
40
|
"csv",
|
|
@@ -44,11 +44,11 @@
|
|
|
44
44
|
],
|
|
45
45
|
"dependencies": {
|
|
46
46
|
"@pgsql/types": "^17.6.2",
|
|
47
|
-
"@pgsql/utils": "^17.8.
|
|
47
|
+
"@pgsql/utils": "^17.8.11",
|
|
48
48
|
"csv-parser": "^2.3.3",
|
|
49
|
-
"inquirerer": "^4.
|
|
49
|
+
"inquirerer": "^4.3.1",
|
|
50
50
|
"js-yaml": "^3.14.0",
|
|
51
|
-
"pgsql-deparser": "^17.17.
|
|
51
|
+
"pgsql-deparser": "^17.17.2"
|
|
52
52
|
},
|
|
53
|
-
"gitHead": "
|
|
53
|
+
"gitHead": "67155381d1850ec9fdaf8f80ef1c6b118a6111c7"
|
|
54
54
|
}
|
package/parser.d.ts
CHANGED
package/parser.js
CHANGED
|
@@ -12,7 +12,7 @@ class Parser {
|
|
|
12
12
|
}
|
|
13
13
|
async parse(data) {
|
|
14
14
|
const config = this.config;
|
|
15
|
-
const { schema, table, singleStmts, conflict, headers, delimeter } = config;
|
|
15
|
+
const { schema, table, singleStmts, conflict, conflictDoNothing, headers, delimeter } = config;
|
|
16
16
|
const opts = {};
|
|
17
17
|
if (headers)
|
|
18
18
|
opts.headers = headers;
|
|
@@ -47,7 +47,8 @@ class Parser {
|
|
|
47
47
|
table,
|
|
48
48
|
types,
|
|
49
49
|
record,
|
|
50
|
-
conflict
|
|
50
|
+
conflict,
|
|
51
|
+
conflictDoNothing
|
|
51
52
|
}));
|
|
52
53
|
return (0, pgsql_deparser_1.deparse)(stmts);
|
|
53
54
|
}
|
|
@@ -57,7 +58,8 @@ class Parser {
|
|
|
57
58
|
table,
|
|
58
59
|
types,
|
|
59
60
|
records,
|
|
60
|
-
conflict
|
|
61
|
+
conflict,
|
|
62
|
+
conflictDoNothing
|
|
61
63
|
});
|
|
62
64
|
return (0, pgsql_deparser_1.deparse)([stmt]);
|
|
63
65
|
}
|
package/utils.d.ts
CHANGED
|
@@ -11,16 +11,18 @@ interface InsertOneParams {
|
|
|
11
11
|
types: TypesMap;
|
|
12
12
|
record: Record<string, unknown>;
|
|
13
13
|
conflict?: string[];
|
|
14
|
+
conflictDoNothing?: boolean;
|
|
14
15
|
}
|
|
15
|
-
export declare const InsertOne: ({ schema, table, types, record, conflict }: InsertOneParams) => Node;
|
|
16
|
+
export declare const InsertOne: ({ schema, table, types, record, conflict, conflictDoNothing }: InsertOneParams) => Node;
|
|
16
17
|
interface InsertManyParams {
|
|
17
18
|
schema?: string;
|
|
18
19
|
table: string;
|
|
19
20
|
types: TypesMap;
|
|
20
21
|
records: Record<string, unknown>[];
|
|
21
22
|
conflict?: string[];
|
|
23
|
+
conflictDoNothing?: boolean;
|
|
22
24
|
}
|
|
23
|
-
export declare const InsertMany: ({ schema, table, types, records, conflict }: InsertManyParams) => Node;
|
|
25
|
+
export declare const InsertMany: ({ schema, table, types, records, conflict, conflictDoNothing }: InsertManyParams) => Node;
|
|
24
26
|
interface WrapOptions {
|
|
25
27
|
wrap?: string[];
|
|
26
28
|
wrapAst?: (val: Node) => Node;
|
package/utils.js
CHANGED
|
@@ -112,7 +112,14 @@ const indexElem = (name) => ({
|
|
|
112
112
|
nulls_ordering: 'SORTBY_NULLS_DEFAULT'
|
|
113
113
|
}
|
|
114
114
|
});
|
|
115
|
-
const makeConflictClause = (conflictElems, fields) => {
|
|
115
|
+
const makeConflictClause = (conflictElems, fields, conflictDoNothing) => {
|
|
116
|
+
// If conflictDoNothing is true, generate ON CONFLICT DO NOTHING without specifying columns
|
|
117
|
+
// This catches any unique constraint violation
|
|
118
|
+
if (conflictDoNothing) {
|
|
119
|
+
return {
|
|
120
|
+
action: 'ONCONFLICT_NOTHING'
|
|
121
|
+
};
|
|
122
|
+
}
|
|
116
123
|
if (!conflictElems || !conflictElems.length)
|
|
117
124
|
return undefined;
|
|
118
125
|
const setElems = fields.filter((el) => !conflictElems.includes(el));
|
|
@@ -134,7 +141,7 @@ const makeConflictClause = (conflictElems, fields) => {
|
|
|
134
141
|
};
|
|
135
142
|
}
|
|
136
143
|
};
|
|
137
|
-
const InsertOne = ({ schema = 'public', table, types, record, conflict }) => ({
|
|
144
|
+
const InsertOne = ({ schema = 'public', table, types, record, conflict, conflictDoNothing }) => ({
|
|
138
145
|
RawStmt: {
|
|
139
146
|
stmt: {
|
|
140
147
|
InsertStmt: {
|
|
@@ -158,7 +165,7 @@ const InsertOne = ({ schema = 'public', table, types, record, conflict }) => ({
|
|
|
158
165
|
limitOption: 'LIMIT_OPTION_DEFAULT'
|
|
159
166
|
}
|
|
160
167
|
},
|
|
161
|
-
onConflictClause: makeConflictClause(conflict, Object.keys(types)),
|
|
168
|
+
onConflictClause: makeConflictClause(conflict, Object.keys(types), conflictDoNothing),
|
|
162
169
|
override: 'OVERRIDING_NOT_SET'
|
|
163
170
|
}
|
|
164
171
|
},
|
|
@@ -166,7 +173,7 @@ const InsertOne = ({ schema = 'public', table, types, record, conflict }) => ({
|
|
|
166
173
|
}
|
|
167
174
|
});
|
|
168
175
|
exports.InsertOne = InsertOne;
|
|
169
|
-
const InsertMany = ({ schema = 'public', table, types, records, conflict }) => ({
|
|
176
|
+
const InsertMany = ({ schema = 'public', table, types, records, conflict, conflictDoNothing }) => ({
|
|
170
177
|
RawStmt: {
|
|
171
178
|
stmt: {
|
|
172
179
|
InsertStmt: {
|
|
@@ -188,7 +195,7 @@ const InsertMany = ({ schema = 'public', table, types, records, conflict }) => (
|
|
|
188
195
|
limitOption: 'LIMIT_OPTION_DEFAULT'
|
|
189
196
|
}
|
|
190
197
|
},
|
|
191
|
-
onConflictClause: makeConflictClause(conflict, Object.keys(types)),
|
|
198
|
+
onConflictClause: makeConflictClause(conflict, Object.keys(types), conflictDoNothing),
|
|
192
199
|
override: 'OVERRIDING_NOT_SET'
|
|
193
200
|
}
|
|
194
201
|
},
|