@l-v-yonsama/multi-platform-database-drivers 0.8.21 → 0.8.32

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.
@@ -46,11 +46,12 @@ const createUndoChangeSQL = ({ schemaName, tableName, columns, diffResult, bindO
46
46
  return list;
47
47
  };
48
48
  exports.createUndoChangeSQL = createUndoChangeSQL;
49
- const toInsertStatement = ({ schemaName, tableName, tableComment, columns, values, bindOption, withComment, compactSql, quote, }) => {
49
+ const toInsertStatement = ({ schemaName, tableName, tableComment, columns, values, bindOption, withComment, compactSql, quote, sqlLang, }) => {
50
50
  const tableNameWithSchema = createTableNameWithSchema({
51
51
  schema: schemaName,
52
52
  table: tableName,
53
53
  quote,
54
+ sqlLang,
54
55
  });
55
56
  const { specifyValuesWithBindParameters, toPositionedParameter, toPositionalCharacter, } = bindOption;
56
57
  const pChar = toPositionalCharacter !== null && toPositionalCharacter !== void 0 ? toPositionalCharacter : '$';
@@ -64,7 +65,7 @@ const toInsertStatement = ({ schemaName, tableName, tableComment, columns, value
64
65
  var _a;
65
66
  const column = columns.find((it) => (0, rdh_1.equalsIgnoreCase)(it.name, key));
66
67
  const colType = (_a = column === null || column === void 0 ? void 0 : column.type) !== null && _a !== void 0 ? _a : rdh_1.GeneralColumnType.UNKNOWN;
67
- columnNames.push(`${wrapQuote(key, quote)}`);
68
+ columnNames.push(`${quote ? wrapQuote(key, '`') : key}`);
68
69
  if (specifyValuesWithBindParameters) {
69
70
  const value = toBindValue(colType, values[key]);
70
71
  binds.push(value);
@@ -86,25 +87,42 @@ const toInsertStatement = ({ schemaName, tableName, tableComment, columns, value
86
87
  query += `-- ${tableComment + os.EOL}`;
87
88
  }
88
89
  if (compactSql) {
89
- query += `INSERT INTO ${tableNameWithSchema} (${columnNames.join(',')}) VALUES (${specifyValuesWithBindParameters
90
- ? placeHolders.join(',')
91
- : embdeddedValues.join(',')})`;
90
+ if (sqlLang === 'partiql') {
91
+ query += `INSERT INTO ${tableNameWithSchema} VALUE {${columnNames
92
+ .map((it, idx) => `${wrapSingleQuote(it)}: ${embdeddedValues[idx]}`)
93
+ .join(',' + os.EOL)}}`;
94
+ }
95
+ else {
96
+ query += `INSERT INTO ${tableNameWithSchema} (${columnNames.join(',')}) VALUES (${specifyValuesWithBindParameters
97
+ ? placeHolders.join(',')
98
+ : embdeddedValues.join(',')})`;
99
+ }
92
100
  }
93
101
  else {
94
- query += `INSERT INTO ${tableNameWithSchema + os.EOL} (${os.EOL} `;
95
- query += `${columnNames.join(',' + os.EOL + ' ')}${os.EOL}`;
96
- query += `) VALUES (${os.EOL}`;
97
- if (specifyValuesWithBindParameters) {
98
- for (let i = 0; i < placeHolders.length; i++) {
99
- query += ` ${placeHolders[i]}${i < placeHolders.length - 1 ? ',' : ''}${withComment ? ' -- ' + columnComments[i] : ''}${os.EOL}`;
102
+ if (sqlLang === 'partiql') {
103
+ query += `INSERT INTO ${tableNameWithSchema} ${os.EOL}`;
104
+ query += `VALUE {${os.EOL}`;
105
+ for (let i = 0; i < embdeddedValues.length; i++) {
106
+ query += ` ${wrapSingleQuote(columnNames[i])}: ${embdeddedValues[i]}${i < embdeddedValues.length - 1 ? ',' : ''}${withComment ? ' -- ' + columnComments[i] : ''}${os.EOL}`;
100
107
  }
108
+ query += `}${os.EOL}`;
101
109
  }
102
110
  else {
103
- for (let i = 0; i < embdeddedValues.length; i++) {
104
- query += ` ${embdeddedValues[i]}${i < embdeddedValues.length - 1 ? ',' : ''}${withComment ? ' -- ' + columnComments[i] : ''}${os.EOL}`;
111
+ query += `INSERT INTO ${tableNameWithSchema + os.EOL} (${os.EOL} `;
112
+ query += `${columnNames.join(',' + os.EOL + ' ')}${os.EOL}`;
113
+ query += `) VALUES (${os.EOL}`;
114
+ if (specifyValuesWithBindParameters) {
115
+ for (let i = 0; i < placeHolders.length; i++) {
116
+ query += ` ${placeHolders[i]}${i < placeHolders.length - 1 ? ',' : ''}${withComment ? ' -- ' + columnComments[i] : ''}${os.EOL}`;
117
+ }
105
118
  }
119
+ else {
120
+ for (let i = 0; i < embdeddedValues.length; i++) {
121
+ query += ` ${embdeddedValues[i]}${i < embdeddedValues.length - 1 ? ',' : ''}${withComment ? ' -- ' + columnComments[i] : ''}${os.EOL}`;
122
+ }
123
+ }
124
+ query += `)${os.EOL}`;
106
125
  }
107
- query += `)${os.EOL}`;
108
126
  }
109
127
  return {
110
128
  query,
@@ -112,11 +130,12 @@ const toInsertStatement = ({ schemaName, tableName, tableComment, columns, value
112
130
  };
113
131
  };
114
132
  exports.toInsertStatement = toInsertStatement;
115
- const toUpdateStatement = ({ schemaName, tableName, columns, values, conditions, bindOption, quote, }) => {
133
+ const toUpdateStatement = ({ schemaName, tableName, columns, values, conditions, bindOption, quote, sqlLang, }) => {
116
134
  const tableNameWithSchema = createTableNameWithSchema({
117
135
  schema: schemaName,
118
136
  table: tableName,
119
137
  quote,
138
+ sqlLang,
120
139
  });
121
140
  const { specifyValuesWithBindParameters, toPositionedParameter, toPositionalCharacter, } = bindOption;
122
141
  const pChar = toPositionalCharacter !== null && toPositionalCharacter !== void 0 ? toPositionalCharacter : '$';
@@ -127,25 +146,35 @@ const toUpdateStatement = ({ schemaName, tableName, columns, values, conditions,
127
146
  Object.keys(values).forEach((key) => {
128
147
  var _a, _b;
129
148
  const colType = (_b = (_a = columns.find((it) => (0, rdh_1.equalsIgnoreCase)(it.name, key))) === null || _a === void 0 ? void 0 : _a.type) !== null && _b !== void 0 ? _b : rdh_1.GeneralColumnType.UNKNOWN;
130
- if (specifyValuesWithBindParameters) {
131
- setList.push(`${wrapQuote(key, quote)} = ${toPositionedParameter === true ? `${pChar}${index + 1}` : '?'}`);
132
- binds.push(toBindValue(colType, values[key]));
133
- index++;
149
+ if (sqlLang === 'partiql') {
150
+ setList.push(`${wrapDoubleQuote(key)} = ${toEmbeddedStringValue(colType, values[key])}`);
134
151
  }
135
152
  else {
136
- setList.push(`${wrapQuote(key, quote)} = ${toEmbeddedStringValue(colType, values[key])}`);
153
+ if (specifyValuesWithBindParameters) {
154
+ setList.push(`${quote ? wrapBackQuote(key) : key} = ${toPositionedParameter === true ? `${pChar}${index + 1}` : '?'}`);
155
+ binds.push(toBindValue(colType, values[key]));
156
+ index++;
157
+ }
158
+ else {
159
+ setList.push(`${quote ? wrapBackQuote(key) : key} = ${toEmbeddedStringValue(colType, values[key])}`);
160
+ }
137
161
  }
138
162
  });
139
163
  Object.keys(conditions).forEach((key) => {
140
164
  var _a, _b;
141
165
  const colType = (_b = (_a = columns.find((it) => (0, rdh_1.equalsIgnoreCase)(it.name, key))) === null || _a === void 0 ? void 0 : _a.type) !== null && _b !== void 0 ? _b : rdh_1.GeneralColumnType.UNKNOWN;
142
- if (specifyValuesWithBindParameters) {
143
- conditionList.push(`${wrapQuote(key, quote)} = ${toPositionedParameter === true ? `$${index + 1}` : '?'}`);
144
- binds.push(toBindValue(colType, conditions[key]));
145
- index++;
166
+ if (sqlLang === 'partiql') {
167
+ conditionList.push(`${wrapDoubleQuote(key)} = ${toEmbeddedStringValue(colType, conditions[key])}`);
146
168
  }
147
169
  else {
148
- conditionList.push(`${wrapQuote(key, quote)} = ${toEmbeddedStringValue(colType, conditions[key])}`);
170
+ if (specifyValuesWithBindParameters) {
171
+ conditionList.push(`${quote ? wrapBackQuote(key) : key} = ${toPositionedParameter === true ? `$${index + 1}` : '?'}`);
172
+ binds.push(toBindValue(colType, conditions[key]));
173
+ index++;
174
+ }
175
+ else {
176
+ conditionList.push(`${quote ? wrapBackQuote(key) : key} = ${toEmbeddedStringValue(colType, conditions[key])}`);
177
+ }
149
178
  }
150
179
  });
151
180
  const query = `UPDATE ${tableNameWithSchema} SET ${setList.join(',')} WHERE ${conditionList.join(' AND ')}`;
@@ -155,11 +184,12 @@ const toUpdateStatement = ({ schemaName, tableName, columns, values, conditions,
155
184
  };
156
185
  };
157
186
  exports.toUpdateStatement = toUpdateStatement;
158
- const toDeleteStatement = ({ schemaName, tableName, columns, conditions, bindOption, quote, }) => {
187
+ const toDeleteStatement = ({ schemaName, tableName, columns, conditions, bindOption, quote, sqlLang, }) => {
159
188
  const tableNameWithSchema = createTableNameWithSchema({
160
189
  schema: schemaName,
161
190
  table: tableName,
162
191
  quote,
192
+ sqlLang,
163
193
  });
164
194
  const { specifyValuesWithBindParameters, toPositionedParameter, toPositionalCharacter, } = bindOption;
165
195
  const pChar = toPositionalCharacter !== null && toPositionalCharacter !== void 0 ? toPositionalCharacter : '$';
@@ -168,12 +198,17 @@ const toDeleteStatement = ({ schemaName, tableName, columns, conditions, bindOpt
168
198
  Object.keys(conditions).forEach((key, index) => {
169
199
  var _a, _b;
170
200
  const colType = (_b = (_a = columns.find((it) => (0, rdh_1.equalsIgnoreCase)(it.name, key))) === null || _a === void 0 ? void 0 : _a.type) !== null && _b !== void 0 ? _b : rdh_1.GeneralColumnType.UNKNOWN;
171
- if (specifyValuesWithBindParameters) {
172
- conditionList.push(`${wrapQuote(key, quote)} = ${toPositionedParameter === true ? `${pChar}${index + 1}` : '?'}`);
173
- binds.push(toBindValue(colType, conditions[key]));
201
+ if (sqlLang === 'partiql') {
202
+ conditionList.push(`${wrapDoubleQuote(key)} = ${toEmbeddedStringValue(colType, conditions[key])}`);
174
203
  }
175
204
  else {
176
- conditionList.push(`${wrapQuote(key, quote)} = ${toEmbeddedStringValue(colType, conditions[key])}`);
205
+ if (specifyValuesWithBindParameters) {
206
+ conditionList.push(`${quote ? wrapBackQuote(key) : key} = ${toPositionedParameter === true ? `${pChar}${index + 1}` : '?'}`);
207
+ binds.push(toBindValue(colType, conditions[key]));
208
+ }
209
+ else {
210
+ conditionList.push(`${quote ? wrapBackQuote(key) : key} = ${toEmbeddedStringValue(colType, conditions[key])}`);
211
+ }
177
212
  }
178
213
  });
179
214
  const query = `DELETE FROM ${tableNameWithSchema} WHERE ${conditionList.join(' AND ')}`;
@@ -202,8 +237,8 @@ const toViewDataNormalizedQuery = (params) => {
202
237
  });
203
238
  };
204
239
  exports.toViewDataNormalizedQuery = toViewDataNormalizedQuery;
205
- const createConditionalClause = ({ conditions, columns, params, indent, quote, }) => {
206
- var _a, _b, _c, _d;
240
+ const createConditionalClause = ({ conditions, columns, params, indent, quote, sqlLang, }) => {
241
+ var _a, _b, _c, _d, _e, _f, _g, _h;
207
242
  const queries = [];
208
243
  let andOr = 'AND';
209
244
  const nestedList = [];
@@ -222,6 +257,7 @@ const createConditionalClause = ({ conditions, columns, params, indent, quote, }
222
257
  params,
223
258
  indent: indent + ' ',
224
259
  quote,
260
+ sqlLang,
225
261
  });
226
262
  queries.push(`(${os.EOL}${q}${os.EOL}${indent})`);
227
263
  }
@@ -237,86 +273,195 @@ const createConditionalClause = ({ conditions, columns, params, indent, quote, }
237
273
  colType = (0, types_1.parseDynamoAttrType)(mcol.attrType);
238
274
  }
239
275
  }
240
- let q = `${wrapQuote(fact, quote)} ${(0, RuleEngine_1.operatorToSQLString)(operator)} `;
241
- if (operator === 'isNull' || operator === 'isNotNull') {
242
- }
243
- else if (operator === 'between' ||
244
- operator === 'in' ||
245
- operator === 'notIn') {
246
- let val = null;
247
- if (value === undefined || value === null) {
248
- val = null;
276
+ let q = `${sqlLang === 'partiql'
277
+ ? wrapDoubleQuote(fact)
278
+ : quote
279
+ ? wrapBackQuote(fact)
280
+ : fact}`;
281
+ q += ` ${(0, RuleEngine_1.operatorToSQLString)(operator)} `;
282
+ if (sqlLang === 'partiql') {
283
+ if (operator === 'isNull' || operator === 'isNotNull') {
249
284
  }
250
- else {
251
- let arr = [];
252
- if (Array.isArray(value)) {
253
- arr = value;
285
+ else if (operator === 'like') {
286
+ if (value === undefined || value === null) {
287
+ q = `Contains(${wrapDoubleQuote(fact)}, NULL)`;
288
+ }
289
+ else {
290
+ let s = value + '';
291
+ if (s.startsWith('%')) {
292
+ s = s.substring(1);
293
+ if (s.endsWith('%')) {
294
+ s = s.substring(0, s.length - 1);
295
+ }
296
+ q = `Contains(${wrapDoubleQuote(fact)}, ${wrapSingleQuote(s)})`;
297
+ }
298
+ else {
299
+ if (s.endsWith('%')) {
300
+ s = s.substring(0, s.length - 1);
301
+ q = `begins_with(${wrapDoubleQuote(fact)}, ${wrapSingleQuote(s)})`;
302
+ }
303
+ else {
304
+ q = `Contains(${wrapDoubleQuote(fact)}, ${wrapSingleQuote(s)})`;
305
+ }
306
+ }
307
+ }
308
+ }
309
+ else if (operator === 'between' ||
310
+ operator === 'in' ||
311
+ operator === 'notIn') {
312
+ let val = null;
313
+ if (value === undefined || value === null) {
314
+ val = null;
315
+ }
316
+ else {
317
+ let arr = [];
318
+ if (Array.isArray(value)) {
319
+ arr = value;
320
+ }
321
+ else if (value.startsWith('[') && value.endsWith(']')) {
322
+ arr = JSON.parse(value);
323
+ }
324
+ else {
325
+ arr = ('' + value).split(/,/).map((it) => it.trim());
326
+ }
327
+ if ((0, rdh_1.isNumericLike)(colType)) {
328
+ val = arr.map((it) => { var _a; return (_a = (0, rdh_1.toNum)(it)) !== null && _a !== void 0 ? _a : null; });
329
+ }
330
+ else if ((0, rdh_1.isBooleanLike)(colType)) {
331
+ val = arr.map((it) => { var _a; return (_a = (0, rdh_1.toBoolean)(it)) !== null && _a !== void 0 ? _a : null; });
332
+ }
333
+ else {
334
+ val = arr.map((it) => it + '');
335
+ }
254
336
  }
255
- else if (value.startsWith('[') && value.endsWith(']')) {
256
- arr = JSON.parse(value);
337
+ if (operator === 'between') {
338
+ if (val === null) {
339
+ q += `NULL AND NULL`;
340
+ }
341
+ else {
342
+ if ((0, rdh_1.isNumericLike)(colType) || (0, rdh_1.isBooleanLike)(colType)) {
343
+ q += `${val[0]} AND ${val[1]}`;
344
+ }
345
+ else {
346
+ q += `${wrapSingleQuote(val[0])} AND ${wrapSingleQuote(val[1])}`;
347
+ }
348
+ }
257
349
  }
258
350
  else {
259
- arr = ('' + value).split(/,/).map((it) => it.trim());
351
+ if ((0, rdh_1.isNumericLike)(colType) || (0, rdh_1.isBooleanLike)(colType)) {
352
+ q += `( ${val.map((it) => `${it}`).join(',')} )`;
353
+ }
354
+ else {
355
+ q += `( ${val.map((it) => wrapSingleQuote(it)).join(',')} )`;
356
+ }
260
357
  }
358
+ }
359
+ else {
360
+ let val = null;
261
361
  if ((0, rdh_1.isNumericLike)(colType)) {
262
- val = arr.map((it) => { var _a; return (_a = (0, rdh_1.toNum)(it)) !== null && _a !== void 0 ? _a : null; });
362
+ val = (_a = (0, rdh_1.toNum)(value)) !== null && _a !== void 0 ? _a : null;
263
363
  }
264
364
  else if ((0, rdh_1.isBooleanLike)(colType)) {
265
- val = arr.map((it) => { var _a; return (_a = (0, rdh_1.toBoolean)(it)) !== null && _a !== void 0 ? _a : null; });
365
+ val = (_b = (0, rdh_1.toBoolean)(value)) !== null && _b !== void 0 ? _b : null;
266
366
  }
267
367
  else if ((0, rdh_1.isDateTimeOrDate)(colType)) {
268
- val = arr.map((it) => { var _a; return (_a = (0, rdh_1.toDate)(it)) !== null && _a !== void 0 ? _a : null; });
368
+ val = (_c = (0, rdh_1.toDate)(value)) !== null && _c !== void 0 ? _c : null;
269
369
  }
270
370
  else if ((0, rdh_1.isTime)(colType)) {
271
- val = arr.map((it) => { var _a; return (_a = (0, rdh_1.toTime)(it)) !== null && _a !== void 0 ? _a : null; });
371
+ val = (_d = (0, rdh_1.toTime)(value)) !== null && _d !== void 0 ? _d : null;
272
372
  }
273
373
  else {
274
- val = arr.map((it) => it + '');
374
+ val = value;
275
375
  }
276
- }
277
- if (operator === 'between') {
278
- const bindName1 = `val${params.pos}`;
279
- params.pos++;
280
- const bindName2 = `val${params.pos}`;
281
- params.pos++;
282
- q += `:${bindName1} AND :${bindName2}`;
283
- if (val === null) {
284
- params.bindParams[bindName1] = null;
285
- params.bindParams[bindName2] = null;
376
+ if ((0, rdh_1.isNumericLike)(colType) || (0, rdh_1.isBooleanLike)(colType)) {
377
+ q += `${val}`;
286
378
  }
287
379
  else {
288
- params.bindParams[bindName1] = val[0];
289
- params.bindParams[bindName2] = val[1];
380
+ q += wrapSingleQuote(val);
290
381
  }
291
382
  }
292
- else {
293
- const bindName = `val${params.pos}`;
294
- params.pos++;
295
- q += `(:${bindName})`;
296
- params.bindParams[bindName] = val;
297
- }
298
383
  }
299
384
  else {
300
- let val = null;
301
- if ((0, rdh_1.isNumericLike)(colType)) {
302
- val = (_a = (0, rdh_1.toNum)(value)) !== null && _a !== void 0 ? _a : null;
303
- }
304
- else if ((0, rdh_1.isBooleanLike)(colType)) {
305
- val = (_b = (0, rdh_1.toBoolean)(value)) !== null && _b !== void 0 ? _b : null;
385
+ if (operator === 'isNull' || operator === 'isNotNull') {
306
386
  }
307
- else if ((0, rdh_1.isDateTimeOrDate)(colType)) {
308
- val = (_c = (0, rdh_1.toDate)(value)) !== null && _c !== void 0 ? _c : null;
309
- }
310
- else if ((0, rdh_1.isTime)(colType)) {
311
- val = (_d = (0, rdh_1.toTime)(value)) !== null && _d !== void 0 ? _d : null;
387
+ else if (operator === 'between' ||
388
+ operator === 'in' ||
389
+ operator === 'notIn') {
390
+ let val = null;
391
+ if (value === undefined || value === null) {
392
+ val = null;
393
+ }
394
+ else {
395
+ let arr = [];
396
+ if (Array.isArray(value)) {
397
+ arr = value;
398
+ }
399
+ else if (value.startsWith('[') && value.endsWith(']')) {
400
+ arr = JSON.parse(value);
401
+ }
402
+ else {
403
+ arr = ('' + value).split(/,/).map((it) => it.trim());
404
+ }
405
+ if ((0, rdh_1.isNumericLike)(colType)) {
406
+ val = arr.map((it) => { var _a; return (_a = (0, rdh_1.toNum)(it)) !== null && _a !== void 0 ? _a : null; });
407
+ }
408
+ else if ((0, rdh_1.isBooleanLike)(colType)) {
409
+ val = arr.map((it) => { var _a; return (_a = (0, rdh_1.toBoolean)(it)) !== null && _a !== void 0 ? _a : null; });
410
+ }
411
+ else if ((0, rdh_1.isDateTimeOrDate)(colType)) {
412
+ val = arr.map((it) => { var _a; return (_a = (0, rdh_1.toDate)(it)) !== null && _a !== void 0 ? _a : null; });
413
+ }
414
+ else if ((0, rdh_1.isTime)(colType)) {
415
+ val = arr.map((it) => { var _a; return (_a = (0, rdh_1.toTime)(it)) !== null && _a !== void 0 ? _a : null; });
416
+ }
417
+ else {
418
+ val = arr.map((it) => it + '');
419
+ }
420
+ }
421
+ if (operator === 'between') {
422
+ const bindName1 = `val${params.pos}`;
423
+ params.pos++;
424
+ const bindName2 = `val${params.pos}`;
425
+ params.pos++;
426
+ q += `:${bindName1} AND :${bindName2}`;
427
+ if (val === null) {
428
+ params.bindParams[bindName1] = null;
429
+ params.bindParams[bindName2] = null;
430
+ }
431
+ else {
432
+ params.bindParams[bindName1] = val[0];
433
+ params.bindParams[bindName2] = val[1];
434
+ }
435
+ }
436
+ else {
437
+ const bindName = `val${params.pos}`;
438
+ params.pos++;
439
+ q += `(:${bindName})`;
440
+ params.bindParams[bindName] = val;
441
+ }
312
442
  }
313
443
  else {
314
- val = value;
444
+ let val = null;
445
+ if ((0, rdh_1.isNumericLike)(colType)) {
446
+ val = (_e = (0, rdh_1.toNum)(value)) !== null && _e !== void 0 ? _e : null;
447
+ }
448
+ else if ((0, rdh_1.isBooleanLike)(colType)) {
449
+ val = (_f = (0, rdh_1.toBoolean)(value)) !== null && _f !== void 0 ? _f : null;
450
+ }
451
+ else if ((0, rdh_1.isDateTimeOrDate)(colType)) {
452
+ val = (_g = (0, rdh_1.toDate)(value)) !== null && _g !== void 0 ? _g : null;
453
+ }
454
+ else if ((0, rdh_1.isTime)(colType)) {
455
+ val = (_h = (0, rdh_1.toTime)(value)) !== null && _h !== void 0 ? _h : null;
456
+ }
457
+ else {
458
+ val = value;
459
+ }
460
+ const bindName = `val${params.pos}`;
461
+ q += `:${bindName}`;
462
+ params.bindParams[bindName] = val;
463
+ params.pos++;
315
464
  }
316
- const bindName = `val${params.pos}`;
317
- q += `:${bindName}`;
318
- params.bindParams[bindName] = val;
319
- params.pos++;
320
465
  }
321
466
  queries.push(q);
322
467
  }
@@ -811,11 +956,20 @@ const createReservedWordProposal = (word) => {
811
956
  kind: types_1.ProposalKind.ReservedWord,
812
957
  };
813
958
  };
814
- const wrapQuote = (s, withQuote) => {
815
- if (withQuote === true) {
816
- return `\`${s}\``;
959
+ const wrapSingleQuote = (input) => wrapQuote(input, "'");
960
+ const wrapDoubleQuote = (input) => wrapQuote(input, '"');
961
+ const wrapBackQuote = (input) => wrapQuote(input, '`');
962
+ const wrapQuote = (input, quoteChar) => {
963
+ switch (quoteChar) {
964
+ case '"':
965
+ return `"${input.replace(/"/g, '""')}"`;
966
+ case "'":
967
+ return `'${input.replace(/'/g, "''")}'`;
968
+ case '`':
969
+ return `\`${input.replace(/`/g, '``')}\``;
970
+ default:
971
+ throw new Error('Invalid quote char');
817
972
  }
818
- return s;
819
973
  };
820
974
  const unwrapQuote = (s) => {
821
975
  if (s.startsWith('"') && s.endsWith('"')) {
@@ -826,11 +980,14 @@ const unwrapQuote = (s) => {
826
980
  }
827
981
  return s;
828
982
  };
829
- const createTableNameWithSchema = ({ schema, table, quote, }) => {
983
+ const createTableNameWithSchema = ({ schema, table, quote, sqlLang, }) => {
984
+ if (sqlLang === 'partiql') {
985
+ return wrapDoubleQuote(table);
986
+ }
830
987
  if (schema) {
831
- return `${wrapQuote(schema, quote)}.${wrapQuote(table, quote)}`;
988
+ return `${quote ? wrapBackQuote(schema) : schema}.${quote ? wrapBackQuote(table) : table}`;
832
989
  }
833
- return `${wrapQuote(table, quote)}`;
990
+ return `${quote ? wrapBackQuote(table) : table}`;
834
991
  };
835
992
  const FUNCTION_MATCHER = new RegExp(`(${constant_1.FUNCTIONS.join('|')})\\([^)]+?\\)`, 'gi');
836
993
  const toBindValue = (colType, value) => {
@@ -865,7 +1022,7 @@ const toEmbeddedStringValue = (colType, value) => {
865
1022
  return 'NULL';
866
1023
  }
867
1024
  if ((0, rdh_1.isTextLike)(colType) || (0, rdh_1.isEnumOrSet)(colType)) {
868
- return `'${value.replace(/'/, "''")}'`;
1025
+ return wrapSingleQuote(value);
869
1026
  }
870
1027
  if ((0, rdh_1.isJsonLike)(colType)) {
871
1028
  return `'${JSON.stringify(value)}'`;
@@ -957,11 +1114,12 @@ const createQNamesUsingLocation = ({ tableName, schemaName, location, sql, }) =>
957
1114
  schemaName,
958
1115
  };
959
1116
  };
960
- const toGeneralQuery = ({ selectClause, tableRes, schemaName, conditions, quote, limit, limitAsTop, }) => {
1117
+ const toGeneralQuery = ({ selectClause, tableRes, schemaName, conditions, quote, sqlLang, limit, limitAsTop, }) => {
961
1118
  const tableNameWithSchema = createTableNameWithSchema({
962
1119
  schema: schemaName,
963
1120
  table: tableRes.name,
964
1121
  quote,
1122
+ sqlLang,
965
1123
  });
966
1124
  const params = {
967
1125
  pos: 1,
@@ -979,6 +1137,7 @@ const toGeneralQuery = ({ selectClause, tableRes, schemaName, conditions, quote,
979
1137
  params,
980
1138
  indent: ' ',
981
1139
  quote,
1140
+ sqlLang,
982
1141
  });
983
1142
  if (q) {
984
1143
  query += os.EOL + 'WHERE' + os.EOL + q;