json-sql-builder2
json-sql-builder2 copied to clipboard
support subquery expressions
exists is probably the most common
- https://www.postgresql.org/docs/11/functions-subquery.html
Superficially looks like a function. Any hints on crossdialect syntax?
Have a look at the from clause helper which already supports subqueries. https://github.com/planetarydev/json-sql-builder2/tree/master/sql/helpers/queries/from
function() {
return sql.build({
$select: {
$from: {
people: 'p',
skills: {
$select: { $from: 'people_skills' }
}
}
}
});
}
// SQL output
SELECT
*
FROM
people AS p,
(
SELECT
*
FROM
people_skills
) AS skills
// Values
{}
We only need to write an exists - helper
It is done by the select operator... https://github.com/planetarydev/json-sql-builder2/blob/master/sql/operators/select/select.js#L82