json-sql-builder2 icon indicating copy to clipboard operation
json-sql-builder2 copied to clipboard

support subquery expressions

Open lagleki opened this issue 6 years ago • 2 comments

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?

lagleki avatar Aug 19 '19 13:08 lagleki

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

planetarydev avatar Aug 19 '19 14:08 planetarydev