Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
parentQueryBuilder.beforeLock("select", () => {
const id = this.rootValue.liveConditions.push(checkerGenerator) - 1;
// BEWARE: it's easy to override others' conditions, and that will cause issues. Be sensible.
const allRequirements = this.data.liveConditions.reduce(
(memo, [_checkerGenerator, requirements]) =>
requirements ? Object.assign(memo, requirements) : memo,
{}
);
parentQueryBuilder.select(
sql.fragment`\
json_build_object('__id', ${sql.value(id)}::int
${sql.join(
Object.keys(allRequirements).map(
key => sql.fragment`, ${sql.literal(key)}::text, ${allRequirements[key]}`
),
""
)})`,
"__live"
);
});
} else if (cb) {
// According to https://www.postgresql.org/docs/10/static/sql-createfunction.html,
// "If you omit the name for an output argument, the system will choose a default column name."
// In PG 9.x and 10, the column names appear to be assigned with a `column` prefix.
outputArgName !== "" ? outputArgName : `column${idx + 1}`
)}`
),
", "
)}
from (values ${sql.join(
values.map(value => sql.query`(${sql.value(value)}::text[])`),
", "
)}) as ${sqlValuesAlias}(output_value_list)`
: sql.query`\
select str::${sqlTypeIdentifier} as ${sqlResultSourceAlias}
from unnest((${sql.value(values)})::text[]) str`;
const { rows: filteredValuesResults } =
values.length > 0
? await performQuery(
pgClient,
sql.query`with ${sqlResultSourceAlias} as (${convertFieldBack}) ${sqlResultQuery}`
)
: { rows: [] };
const finalRows = rawValues.map(rawValue =>
/*
* We can't simply return 'null' here because this is expected to have
* come from PG, and that would never return 'null' for a row - only
* the fields within said row. Using `__isNull` here is a simple
* workaround to this, that's caught by `pg2gql`.
*/
rawValue === null ? { __isNull: true } : filteredValuesResults.shift()
);
const sqlCursors = rawCursors.map(val => sql.value(val));
for (let i = orderByExpressionsAndDirections.length - 1; i >= 0; i--) {
values.map(value => sql.query`(${sql.value(value)}::text[])`),
", "