Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
cmap(async function(me) {
const f_key_ids = uniq(filter((r) => !!r, pluck(me.left_key, results)));
if (me.rel_type == '-' || !f_key_ids.length) return recur([me, cat(map(r => r._ ? r._[me.as] : null, results))]);
return go(
(!me.left_join_over && me.left_joins.length ?
left_join_query : where_in_query)(me, SQL `WHERE ${IN(me.as + '.' + me.key, f_key_ids)}`, QUERY),
group_by((v) => v[me.key]),
function(groups) {
each(function(result) {
result._ = result._ || {};
result._[me.as] = (groups[result[me.left_key]] || []);
}, results);
return recur([me, cat(map(r => r._ ? r._[me.as] : null, results))]);
}
);
}),
() => results
FROM information_schema.columns
WHERE
table_name in (
SELECT tablename
FROM pg_tables
WHERE
tableowner=${connection_info.user || process.env.PGUSER}
) ORDER BY table_name;`,
group_by((v) => v.table_name),
map(v => pluck('column_name', v))),
await go(QUERY `
SELECT *
FROM INFORMATION_SCHEMA.view_column_usage
WHERE view_catalog=${connection_info.database || process.env.PGDATABASE}
;`,
group_by((v) => v.view_name),
map(v => pluck('column_name', v)))
);
function where_in_query(left, where_in, QUERY) {
const colums = uniq(add_column(left).originals.concat(left.key));
const query = left.query();
if (query && query.text) query.text = query.text.replace(/^\s*WHERE/i, 'AND');
return left.row_number.length == 2 ?
QUERY `
SELECT *
FROM (
SELECT
${COLUMN(...colums)},
ROW_NUMBER() OVER (PARTITION BY ${CL(left.key)} ORDER BY ${left.row_number[1]}) as "--row_number--"
FROM ${TB(left.table)} AS ${TB(left.as)}
${where_in || tag()}