planetarydev/json-sql-builder2

support subquery expressions

lagleki opened this issue · 2 comments

exists is probably the most common

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