123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- const {QueryFile} = require('../../query-file');
- const npm = {
- formatting: require('../../formatting')
- };
- function concat(queries, capSQL) {
- if (!Array.isArray(queries)) {
- throw new TypeError('Parameter \'queries\' must be an array.');
- }
- const fmOptions = {capSQL};
- const all = queries.map((q, index) => {
- if (typeof q === 'string') {
-
- return clean(q);
- }
- if (q && typeof q === 'object') {
- if (q instanceof QueryFile) {
-
- return clean(q[npm.formatting.as.ctf.toPostgres]());
- }
- if ('query' in q) {
-
- let opt = q.options && typeof q.options === 'object' ? q.options : {};
- opt = opt.capSQL === undefined ? Object.assign(opt, fmOptions) : opt;
- return clean(npm.formatting.as.format(q.query, q.values, opt));
- }
- }
- throw new Error(`Invalid query element at index ${index}.`);
- });
- return all.filter(q => q).join(';');
- }
- function clean(q) {
-
- return q.replace(/^[\s;]*|[\s;]*$/g, '');
- }
- module.exports = {concat};
|