@blazedpath/commons 0.0.8 → 0.0.9
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/blz-base/index.js +895 -893
- package/blz-cache/index.js +14 -25
- package/blz-core/index.js +349 -347
- package/blz-cryptography/index.js +49 -47
- package/blz-datetimes/index.js +350 -348
- package/blz-file/index.js +88 -83
- package/blz-hazelcast/index.js +103 -100
- package/blz-iterable/index.js +406 -404
- package/blz-json-schema/index.js +8 -6
- package/blz-jwt/index.js +92 -89
- package/blz-kafka/index.js +107 -105
- package/blz-math/index.js +129 -127
- package/blz-mongodb/index.js +35 -33
- package/blz-rds/index.js +46 -44
- package/blz-rds-mysql/index.js +23 -21
- package/blz-rds-mysqlx/index.js +22 -20
- package/blz-rds-oracle/index.js +204 -199
- package/blz-rds-postgres/index.js +22 -20
- package/blz-redis/index.js +125 -123
- package/blz-regex/index.js +24 -22
- package/blz-strings/index.js +167 -165
- package/blz-uuid/index.js +4 -2
- package/blz-yaml/index.js +19 -16
- package/package.json +1 -1
package/blz-rds-mysqlx/index.js
CHANGED
|
@@ -18,24 +18,26 @@ process.on('exit', async function () {
|
|
|
18
18
|
});
|
|
19
19
|
|
|
20
20
|
module.exports = {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
21
|
+
Backend: {
|
|
22
|
+
syntaxis: require("./syntaxis.json"),
|
|
23
|
+
executeProcedure,
|
|
24
|
+
executeSql: async function (connection, sql, parameters, options = {}) {
|
|
25
|
+
if (sql.indexOf("call") != -1) {
|
|
26
|
+
return await executeProcedure(connection, sql, parameters);
|
|
27
|
+
} else if (_.has(options, "bulkInsert")) {
|
|
28
|
+
return await executeBulkInsert(connection, sql, parameters, options);
|
|
29
|
+
} else if (_.has(options, "bulkMerge")) {
|
|
30
|
+
return await executeBulkMerge(connection, sql, parameters, options);
|
|
31
|
+
} else if (_.has(options, "queryOne") || _.has(options, "query")) {
|
|
32
|
+
return await executeQuery(connection, sql, parameters, options);
|
|
33
|
+
} else {
|
|
34
|
+
return await executeNonQuery(connection, sql, parameters, options);
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
beginTransaction,
|
|
38
|
+
close,
|
|
39
|
+
createRdsConnection,
|
|
40
|
+
commitTransaction,
|
|
41
|
+
rollbackTransaction
|
|
42
|
+
}
|
|
41
43
|
}
|
package/blz-rds-oracle/index.js
CHANGED
|
@@ -31,8 +31,8 @@ const getPool = async function (connection) {
|
|
|
31
31
|
connection = _.omit(connection, "dataSource", "providerName");
|
|
32
32
|
connection.sessionCallback = makeInitSessionCallback({ schema: connection.schema })
|
|
33
33
|
// Enable instant client mode in Node.js
|
|
34
|
-
if (process.env.LD_LIBRARY_PATH){
|
|
35
|
-
oracledb.initOracleClient(
|
|
34
|
+
if (process.env.LD_LIBRARY_PATH) {
|
|
35
|
+
oracledb.initOracleClient({ libDir: process.env.LD_LIBRARY_PATH, configDir: '', thin: false });
|
|
36
36
|
}
|
|
37
37
|
pool = await oracledb.createPool(connection);
|
|
38
38
|
pool.connectionName = connection.name;
|
|
@@ -68,13 +68,13 @@ const tryDatetime = function (value) {
|
|
|
68
68
|
if (match) {
|
|
69
69
|
const probableDate = new Date(value);
|
|
70
70
|
if (probableDate.toString() !== 'Invalid Date') {
|
|
71
|
-
return probableDate;
|
|
71
|
+
return probableDate;
|
|
72
72
|
}
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
75
|
return null;
|
|
76
76
|
};
|
|
77
|
-
const convertMilliseconds = function(strMilliseconds) {
|
|
77
|
+
const convertMilliseconds = function (strMilliseconds) {
|
|
78
78
|
if (strMilliseconds) {
|
|
79
79
|
if (strMilliseconds.length < 3)
|
|
80
80
|
strMilliseconds = strMilliseconds.padEnd(3, '0');
|
|
@@ -127,15 +127,15 @@ const getParameterType = function (type) {
|
|
|
127
127
|
case 'VARCHAR2':
|
|
128
128
|
return oracledb.STRING;
|
|
129
129
|
default:
|
|
130
|
-
return oracledb.STRING
|
|
130
|
+
return oracledb.STRING
|
|
131
131
|
}
|
|
132
132
|
}
|
|
133
133
|
|
|
134
|
-
const getOraParameters = function (parameters,options) {
|
|
134
|
+
const getOraParameters = function (parameters, options) {
|
|
135
135
|
let oraParameters = {};
|
|
136
136
|
if (parameters)
|
|
137
137
|
for (let i = 0; i < parameters.length; i++) {
|
|
138
|
-
let parameter = parameters[i];
|
|
138
|
+
let parameter = parameters[i];
|
|
139
139
|
let oraParameter = {};
|
|
140
140
|
// checks if i need to convert nodejs to oracle representation (bool -> 0,1) etcs
|
|
141
141
|
if (parameter.direction === 'in' || parameter.direction === 'in/out') {
|
|
@@ -175,7 +175,7 @@ const getOraParameters = function (parameters,options) {
|
|
|
175
175
|
if (parameter.isResultSet)
|
|
176
176
|
oraParameter.type = oracledb.CURSOR;
|
|
177
177
|
else {
|
|
178
|
-
if (parameter.dbTypes){
|
|
178
|
+
if (parameter.dbTypes) {
|
|
179
179
|
const oracleEntry = parameter.dbTypes.find(entry => entry.providerName === 'Oracle');
|
|
180
180
|
parameter.dbType = getParameterType(oracleEntry.dbType);
|
|
181
181
|
} else if (parameter.type) {
|
|
@@ -193,7 +193,7 @@ const getOraParameters = function (parameters,options) {
|
|
|
193
193
|
return oraParameters
|
|
194
194
|
}
|
|
195
195
|
|
|
196
|
-
const getOraOptions = function (options
|
|
196
|
+
const getOraOptions = function (options, bindDefs) {
|
|
197
197
|
let oraOptions = { autoCommit: !options.isTransactionRequest };
|
|
198
198
|
if (options && (options.query || options.queryOne)) {
|
|
199
199
|
oraOptions.resultSet = true;
|
|
@@ -210,29 +210,29 @@ const convertValueFromType = async function (value, type) {
|
|
|
210
210
|
return BlzBase.convertToString(value);
|
|
211
211
|
}
|
|
212
212
|
case 'integer': {
|
|
213
|
-
return
|
|
213
|
+
return BlzBase.convertToInteger(value);
|
|
214
214
|
}
|
|
215
215
|
case 'decimal': {
|
|
216
|
-
return
|
|
216
|
+
return BlzBase.convertToDecimal(value);
|
|
217
217
|
}
|
|
218
218
|
case 'boolean': {
|
|
219
|
-
return
|
|
219
|
+
return BlzBase.convertToBoolean(value);
|
|
220
220
|
}
|
|
221
221
|
case 'datetime': {
|
|
222
|
-
return
|
|
222
|
+
return BlzBase.convertToDatetime(value);
|
|
223
223
|
}
|
|
224
224
|
case 'date': {
|
|
225
|
-
return
|
|
225
|
+
return BlzBase.convertToDate(value);
|
|
226
226
|
}
|
|
227
227
|
case 'time': {
|
|
228
|
-
return
|
|
228
|
+
return BlzBase.convertToTime(value);
|
|
229
229
|
}
|
|
230
230
|
case 'binary': {
|
|
231
|
-
return
|
|
231
|
+
return BlzBase.convertToBinary(value);
|
|
232
232
|
}
|
|
233
|
-
default:{
|
|
233
|
+
default: {
|
|
234
234
|
// If i have a clob, or special type, the case might not be straightforward
|
|
235
|
-
if (value._type.name === 'DB_TYPE_CLOB'
|
|
235
|
+
if (value._type.name === 'DB_TYPE_CLOB') {
|
|
236
236
|
return await oraResult.outBinds[parameter.name].getData();
|
|
237
237
|
}
|
|
238
238
|
}
|
|
@@ -288,19 +288,19 @@ process.on('exit', async function () {
|
|
|
288
288
|
});
|
|
289
289
|
|
|
290
290
|
const getValue = function (source, type) {
|
|
291
|
-
const _type =
|
|
291
|
+
const _type = type ? type.toLowerCase() : typeof source
|
|
292
292
|
switch (_type.toLowerCase()) {
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
293
|
+
case 'boolean':
|
|
294
|
+
return source ? 1 : 0
|
|
295
|
+
case 'string':
|
|
296
|
+
return typeof source === 'string' || source === null || source === undefined ? source : source.toString()
|
|
297
|
+
case 'datetime':
|
|
298
|
+
case 'date':
|
|
299
|
+
case 'time':
|
|
300
|
+
return source ? new Date(source) : null
|
|
301
|
+
default:
|
|
302
|
+
return source
|
|
303
|
+
}
|
|
304
304
|
}
|
|
305
305
|
|
|
306
306
|
/**
|
|
@@ -343,10 +343,10 @@ const rowsToArray = function (columns, rows) {
|
|
|
343
343
|
const columnsCount = columns.length
|
|
344
344
|
for (const row of rows) {
|
|
345
345
|
const item = {}
|
|
346
|
-
for(let i=0
|
|
347
|
-
const column = columns[i]
|
|
346
|
+
for (let i = 0; i < columnsCount; i++) {
|
|
347
|
+
const column = columns[i]
|
|
348
348
|
const value = row[i]
|
|
349
|
-
item[column.name] = getValue(value,column.type)
|
|
349
|
+
item[column.name] = getValue(value, column.type)
|
|
350
350
|
}
|
|
351
351
|
array.push(item)
|
|
352
352
|
}
|
|
@@ -354,186 +354,191 @@ const rowsToArray = function (columns, rows) {
|
|
|
354
354
|
}
|
|
355
355
|
|
|
356
356
|
module.exports = {
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
catch (err) {
|
|
365
|
-
throw err;
|
|
366
|
-
}
|
|
367
|
-
},
|
|
368
|
-
executeSql: async function (connection, sql, parameters, options) {
|
|
369
|
-
if(_.has(options, "bulkInsert")) {
|
|
370
|
-
return await this._executeBulkInsert(connection, sql, parameters, options);
|
|
371
|
-
} else if(_.has(options, "bulkMerge")) {
|
|
372
|
-
return await this._executeBulkMerge(connection, sql, parameters, options);
|
|
373
|
-
} else {
|
|
374
|
-
return await this._executeSql(connection, sql, parameters, options);
|
|
375
|
-
}
|
|
376
|
-
},
|
|
377
|
-
_executeSql: async function (connection, sql, parameters, options) {
|
|
378
|
-
try{
|
|
379
|
-
let oraParameters = getOraParameters(parameters,options);
|
|
380
|
-
let oraOptions = getOraOptions(options)
|
|
381
|
-
let oraResult = await connection.execute(sql, oraParameters, oraOptions);
|
|
382
|
-
const result = await getResult(parameters, oraResult, options);
|
|
383
|
-
return result;
|
|
384
|
-
} catch (err) {
|
|
385
|
-
throw err
|
|
386
|
-
}
|
|
387
|
-
},
|
|
388
|
-
_executeBulkInsert: async function (connection, sql, rows, options) {
|
|
389
|
-
let autoincremental = null
|
|
390
|
-
if (options.autoincrementalData && options.autoincrementalData.pkColumnName) {
|
|
391
|
-
autoincremental = { name: options.autoincrementalData.pkColumnName ,
|
|
392
|
-
alias: options.autoincrementalData.pkColumnAlias,
|
|
393
|
-
sequence: options.autoincrementalData.sequenceName,
|
|
394
|
-
type: options.autoincrementalData.pkColumnType
|
|
395
|
-
}
|
|
396
|
-
}
|
|
397
|
-
const _sql = autoincremental ?
|
|
398
|
-
'INSERT INTO ' + options.rdsTable.tableName +
|
|
399
|
-
' (' + autoincremental.name + ',' + options.setsFields.join(', ') +
|
|
400
|
-
') VALUES ( ' + autoincremental.sequence + '.NEXTVAL, ' + options.setsFields.map((field) => ':' + field).join(', ') + ' ) ' +
|
|
401
|
-
' RETURNING ' + autoincremental.name + ' INTO :' + autoincremental.name
|
|
402
|
-
: sql + '(' +options.setsFields.map((field) => ':' + field).join(', ') + ' ) '
|
|
403
|
-
|
|
404
|
-
// solve max size for string fields
|
|
405
|
-
const columnsCount = options.columns.length
|
|
406
|
-
for(let i=0 ; i < columnsCount ; i++) {
|
|
407
|
-
const column = options.columns[i]
|
|
408
|
-
if (column.type === 'string') {
|
|
409
|
-
column.size = rows.reduce((max, row) => { return !row[i]?0:row[i].length > max ? row[i].length : max }, 0)
|
|
357
|
+
Backend: {
|
|
358
|
+
syntaxis: require('./syntaxis.json'),
|
|
359
|
+
createRdsConnection: async function (connection) {
|
|
360
|
+
try {
|
|
361
|
+
let oraPool = await getPool(connection);
|
|
362
|
+
let oraConnection = await oraPool.getConnection();
|
|
363
|
+
return oraConnection;
|
|
410
364
|
}
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
365
|
+
catch (err) {
|
|
366
|
+
throw err;
|
|
367
|
+
}
|
|
368
|
+
},
|
|
369
|
+
executeSql: async function (connection, sql, parameters, options) {
|
|
370
|
+
if (_.has(options, "bulkInsert")) {
|
|
371
|
+
return await this._executeBulkInsert(connection, sql, parameters, options);
|
|
372
|
+
} else if (_.has(options, "bulkMerge")) {
|
|
373
|
+
return await this._executeBulkMerge(connection, sql, parameters, options);
|
|
374
|
+
} else {
|
|
375
|
+
return await this._executeSql(connection, sql, parameters, options);
|
|
376
|
+
}
|
|
377
|
+
},
|
|
378
|
+
_executeSql: async function (connection, sql, parameters, options) {
|
|
379
|
+
try {
|
|
380
|
+
let oraParameters = getOraParameters(parameters, options);
|
|
381
|
+
let oraOptions = getOraOptions(options)
|
|
382
|
+
let oraResult = await connection.execute(sql, oraParameters, oraOptions);
|
|
383
|
+
const result = await getResult(parameters, oraResult, options);
|
|
384
|
+
return result;
|
|
385
|
+
} catch (err) {
|
|
386
|
+
throw err
|
|
387
|
+
}
|
|
388
|
+
},
|
|
389
|
+
_executeBulkInsert: async function (connection, sql, rows, options) {
|
|
390
|
+
let autoincremental = null
|
|
391
|
+
if (options.autoincrementalData && options.autoincrementalData.pkColumnName) {
|
|
392
|
+
autoincremental = {
|
|
393
|
+
name: options.autoincrementalData.pkColumnName,
|
|
394
|
+
alias: options.autoincrementalData.pkColumnAlias,
|
|
395
|
+
sequence: options.autoincrementalData.sequenceName,
|
|
396
|
+
type: options.autoincrementalData.pkColumnType
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
const _sql = autoincremental ?
|
|
400
|
+
'INSERT INTO ' + options.rdsTable.tableName +
|
|
401
|
+
' (' + autoincremental.name + ',' + options.setsFields.join(', ') +
|
|
402
|
+
') VALUES ( ' + autoincremental.sequence + '.NEXTVAL, ' + options.setsFields.map((field) => ':' + field).join(', ') + ' ) ' +
|
|
403
|
+
' RETURNING ' + autoincremental.name + ' INTO :' + autoincremental.name
|
|
404
|
+
: sql + '(' + options.setsFields.map((field) => ':' + field).join(', ') + ' ) '
|
|
405
|
+
|
|
406
|
+
// solve max size for string fields
|
|
407
|
+
const columnsCount = options.columns.length
|
|
408
|
+
for (let i = 0; i < columnsCount; i++) {
|
|
409
|
+
const column = options.columns[i]
|
|
410
|
+
if (column.type === 'string') {
|
|
411
|
+
column.size = rows.reduce((max, row) => { return !row[i] ? 0 : row[i].length > max ? row[i].length : max }, 0)
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
const bindDefs = {}
|
|
415
|
+
for (const column of options.columns) {
|
|
416
|
+
const bindDef = { type: getDbType(column.type) }
|
|
417
|
+
if (column.type === 'string') {
|
|
418
|
+
bindDef.maxSize = column.size
|
|
419
|
+
}
|
|
420
|
+
bindDefs[column.name] = bindDef
|
|
417
421
|
}
|
|
418
|
-
bindDefs[column.name] = bindDef
|
|
419
|
-
}
|
|
420
|
-
if (autoincremental) {
|
|
421
|
-
bindDefs[autoincremental.name] = { type: getDbType(autoincremental.type), dir: oracledb.BIND_OUT}
|
|
422
|
-
}
|
|
423
|
-
const oraOptions = getOraOptions(options,bindDefs)
|
|
424
|
-
const data = rowsToArray(options.columns,rows)
|
|
425
|
-
try {
|
|
426
|
-
const result = await connection.executeMany(_sql, data, oraOptions)
|
|
427
422
|
if (autoincremental) {
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
423
|
+
bindDefs[autoincremental.name] = { type: getDbType(autoincremental.type), dir: oracledb.BIND_OUT }
|
|
424
|
+
}
|
|
425
|
+
const oraOptions = getOraOptions(options, bindDefs)
|
|
426
|
+
const data = rowsToArray(options.columns, rows)
|
|
427
|
+
try {
|
|
428
|
+
const result = await connection.executeMany(_sql, data, oraOptions)
|
|
429
|
+
if (autoincremental) {
|
|
430
|
+
const ids = []
|
|
431
|
+
for (const i in result.outBinds) {
|
|
432
|
+
ids.push(result.outBinds[i][autoincremental.name][0])
|
|
433
|
+
}
|
|
434
|
+
return { rowsAffected: result.rowsAffected, ids }
|
|
435
|
+
} else {
|
|
436
|
+
return { rowsAffected: result.rowsAffected }
|
|
431
437
|
}
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
438
|
+
} catch (err) {
|
|
439
|
+
console.log(err)
|
|
440
|
+
throw err
|
|
435
441
|
}
|
|
436
|
-
}
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
sequence: options.autoincrementalData.sequenceName,
|
|
448
|
-
type: options.autoincrementalData.pkColumnType
|
|
449
|
-
}
|
|
450
|
-
}
|
|
451
|
-
const _sql = []
|
|
452
|
-
_sql.push('MERGE INTO ' + options.rdsTable.tableName + ' t USING (')
|
|
453
|
-
_sql.push('SELECT ')
|
|
454
|
-
let first = true
|
|
455
|
-
for (const column of options.columns) {
|
|
456
|
-
_sql.push((first?'': ', ') + ':' + column.name + ' AS ' + column.name)
|
|
457
|
-
first = false
|
|
458
|
-
}
|
|
459
|
-
_sql.push('FROM DUAL')
|
|
460
|
-
_sql.push(') s ON (')
|
|
461
|
-
first = true
|
|
462
|
-
for(const field of options.mergeFields) {
|
|
463
|
-
_sql.push((first?'': ' AND ') + 't.' + field + ' = s.' + field )
|
|
464
|
-
first = false
|
|
465
|
-
}
|
|
466
|
-
_sql.push(')')
|
|
467
|
-
_sql.push('WHEN MATCHED THEN UPDATE SET ')
|
|
468
|
-
first = true
|
|
469
|
-
for(const column of options.columns) {
|
|
470
|
-
if(options.mergeFields.includes(column.name)) continue
|
|
471
|
-
_sql.push((first?'': ',') + 't.' + column.name + ' = s.' + column.name)
|
|
472
|
-
first = false
|
|
473
|
-
}
|
|
474
|
-
_sql.push('WHEN NOT MATCHED THEN INSERT (')
|
|
475
|
-
if(autoincremental) {
|
|
476
|
-
_sql.push(autoincremental.name)
|
|
477
|
-
for(const column of options.columns) {
|
|
478
|
-
_sql.push(',' + column.name)
|
|
442
|
+
},
|
|
443
|
+
_executeBulkMerge: async function (connection, sql, rows, options) {
|
|
444
|
+
// example: https://stackoverflow.com/questions/67881781/how-to-execute-multiple-merge-into-query-on-oracle-db-from-node-js
|
|
445
|
+
let autoincremental = null
|
|
446
|
+
if (options.autoincrementalData && options.autoincrementalData.pkColumnName) {
|
|
447
|
+
autoincremental = {
|
|
448
|
+
name: options.autoincrementalData.pkColumnName,
|
|
449
|
+
alias: options.autoincrementalData.pkColumnAlias,
|
|
450
|
+
sequence: options.autoincrementalData.sequenceName,
|
|
451
|
+
type: options.autoincrementalData.pkColumnType
|
|
452
|
+
}
|
|
479
453
|
}
|
|
480
|
-
_sql
|
|
481
|
-
_sql.push(
|
|
482
|
-
|
|
483
|
-
|
|
454
|
+
const _sql = []
|
|
455
|
+
_sql.push('MERGE INTO ' + options.rdsTable.tableName + ' t USING (')
|
|
456
|
+
_sql.push('SELECT ')
|
|
457
|
+
let first = true
|
|
458
|
+
for (const column of options.columns) {
|
|
459
|
+
_sql.push((first ? '' : ', ') + ':' + column.name + ' AS ' + column.name)
|
|
460
|
+
first = false
|
|
484
461
|
}
|
|
485
|
-
|
|
462
|
+
_sql.push('FROM DUAL')
|
|
463
|
+
_sql.push(') s ON (')
|
|
486
464
|
first = true
|
|
487
|
-
for(const
|
|
488
|
-
_sql.push((first?'': '
|
|
465
|
+
for (const field of options.mergeFields) {
|
|
466
|
+
_sql.push((first ? '' : ' AND ') + 't.' + field + ' = s.' + field)
|
|
489
467
|
first = false
|
|
490
468
|
}
|
|
491
|
-
_sql.push(')
|
|
469
|
+
_sql.push(')')
|
|
470
|
+
_sql.push('WHEN MATCHED THEN UPDATE SET ')
|
|
492
471
|
first = true
|
|
493
|
-
for(const column of options.columns) {
|
|
494
|
-
|
|
472
|
+
for (const column of options.columns) {
|
|
473
|
+
if (options.mergeFields.includes(column.name)) continue
|
|
474
|
+
_sql.push((first ? '' : ',') + 't.' + column.name + ' = s.' + column.name)
|
|
495
475
|
first = false
|
|
496
476
|
}
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
477
|
+
_sql.push('WHEN NOT MATCHED THEN INSERT (')
|
|
478
|
+
if (autoincremental) {
|
|
479
|
+
_sql.push(autoincremental.name)
|
|
480
|
+
for (const column of options.columns) {
|
|
481
|
+
_sql.push(',' + column.name)
|
|
482
|
+
}
|
|
483
|
+
_sql.push(') VALUES (')
|
|
484
|
+
_sql.push(autoincremental.sequence + '.NEXTVAL')
|
|
485
|
+
for (const column of options.columns) {
|
|
486
|
+
_sql.push(',s.' + column.name)
|
|
487
|
+
}
|
|
488
|
+
} else {
|
|
489
|
+
first = true
|
|
490
|
+
for (const column of options.columns) {
|
|
491
|
+
_sql.push((first ? '' : ',') + column.name)
|
|
492
|
+
first = false
|
|
493
|
+
}
|
|
494
|
+
_sql.push(') VALUES (')
|
|
495
|
+
first = true
|
|
496
|
+
for (const column of options.columns) {
|
|
497
|
+
_sql.push((first ? '' : ',') + 's.' + column.name)
|
|
498
|
+
first = false
|
|
499
|
+
}
|
|
507
500
|
}
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
501
|
+
_sql.push(')')
|
|
502
|
+
const mergeSql = _sql.join(' ')
|
|
503
|
+
|
|
504
|
+
// solve max size for string fields
|
|
505
|
+
const columnsCount = options.columns.length
|
|
506
|
+
for (let i = 0; i < columnsCount; i++) {
|
|
507
|
+
const column = options.columns[i]
|
|
508
|
+
if (column.type === 'string') {
|
|
509
|
+
column.size = rows.reduce((max, row) => { return !row[i] ? 0 : row[i].length > max ? row[i].length : max }, 0)
|
|
510
|
+
}
|
|
514
511
|
}
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
512
|
+
const bindDefs = {}
|
|
513
|
+
for (const column of options.columns) {
|
|
514
|
+
const bindDef = { type: getDbType(column.type) }
|
|
515
|
+
if (column.type === 'string') {
|
|
516
|
+
bindDef.maxSize = column.size
|
|
517
|
+
}
|
|
518
|
+
bindDefs[column.name] = bindDef
|
|
519
|
+
}
|
|
520
|
+
const oraOptions = getOraOptions(options, bindDefs)
|
|
521
|
+
const data = rowsToArray(options.columns, rows)
|
|
522
|
+
try {
|
|
523
|
+
const result = await connection.executeMany(mergeSql, data, oraOptions)
|
|
524
|
+
return { rowsAffected: result.rowsAffected }
|
|
525
|
+
} catch (err) {
|
|
526
|
+
console.log(err)
|
|
527
|
+
throw err
|
|
528
|
+
}
|
|
529
|
+
},
|
|
530
|
+
close(nativeConnection) {
|
|
531
|
+
return nativeConnection.close();
|
|
532
|
+
},
|
|
533
|
+
beginTransaction(nativeConnection) {
|
|
534
|
+
//se utiliza la variable isTransactionRequest
|
|
535
|
+
},
|
|
536
|
+
commitTransaction(nativeConnection) {
|
|
537
|
+
return nativeConnection.commit();
|
|
538
|
+
},
|
|
539
|
+
rollbackTransaction(nativeConnection) {
|
|
540
|
+
return nativeConnection.rollback();
|
|
541
|
+
}
|
|
538
542
|
}
|
|
543
|
+
|
|
539
544
|
};
|
|
@@ -18,24 +18,26 @@ process.on('exit', async function () {
|
|
|
18
18
|
});
|
|
19
19
|
|
|
20
20
|
module.exports = {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
21
|
+
Backend: {
|
|
22
|
+
syntaxis: require('./syntaxis.json'),
|
|
23
|
+
executeProcedure,
|
|
24
|
+
executeSql: async function (connection, sql, parameters, options = {}) {
|
|
25
|
+
if (sql.indexOf("call") != -1) {
|
|
26
|
+
return await executeProcedure(connection, sql, parameters);
|
|
27
|
+
} else if (_.has(options, "bulkInsert")) {
|
|
28
|
+
return await executeBulkInsert(connection, sql, parameters, options);
|
|
29
|
+
} else if (_.has(options, "bulkMerge")) {
|
|
30
|
+
return await executeBulkMerge(connection, sql, parameters, options);
|
|
31
|
+
} else if (_.has(options, "queryOne") || _.has(options, "query")) {
|
|
32
|
+
return await executeQuery(connection, sql, parameters, options);
|
|
33
|
+
} else {
|
|
34
|
+
return await executeNonQuery(connection, sql, parameters, options);
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
beginTransaction,
|
|
38
|
+
close,
|
|
39
|
+
createRdsConnection,
|
|
40
|
+
commitTransaction,
|
|
41
|
+
rollbackTransaction
|
|
42
|
+
}
|
|
41
43
|
}
|