postgrelize / Subquery
Interface: Subquery ​
Defined in: src/expressions/query-expressions.ts:27
SELECT embedded in another statement. Created by Model.subquery(), or by combining subqueries with a set operation. PostgreSQL extension.
Extends ​
Properties ​
build ​
readonlybuild: () =>QueryNode
Defined in: src/expressions/query-expressions.ts:31
Builds the query AST (called when the outer statement is compiled).
Returns ​
QueryNode
Methods ​
except() ​
except(
other,options?):Subquery
Defined in: src/expressions/query-expressions.ts:87
Rows of this query that are not in other (EXCEPT).
Parameters ​
other ​
Subquery
Query whose rows are removed.
options? ​
Readonly<{ all?: boolean; }>
all keeps duplicates.
Returns ​
Subquery
Combined subquery.
Example ​
const quiet = User.subquery({ attributes: ['id'] }).except(Post.subquery({ attributes: ['userId'] }));intersect() ​
intersect(
other,options?):Subquery
Defined in: src/expressions/query-expressions.ts:72
Rows that are in both this query and other (INTERSECT).
Parameters ​
other ​
Subquery
Query to intersect with.
options? ​
Readonly<{ all?: boolean; }>
all keeps duplicates.
Returns ​
Subquery
Combined subquery.
Example ​
const both = Post.subquery({ attributes: ['userId'] }).intersect(Task.subquery({ attributes: ['userId'] }));union() ​
union(
other,options?):Subquery
Defined in: src/expressions/query-expressions.ts:57
Rows of this query or of other, without duplicates unless all is set (UNION).
Both queries must select the same number of columns of compatible types. Use the result wherever a subquery fits: source, with, Op.in, insertFrom, merge.
Parameters ​
other ​
Subquery
Query to combine with.
options? ​
Readonly<{ all?: boolean; }>
all keeps duplicates.
Returns ​
Subquery
Combined subquery.
Example ​
const ids = Post.subquery({ attributes: ['userId'] }).union(Task.subquery({ attributes: ['userId'] }));
const users = await User.findAll({ where: { id: { [Op.in]: ids } } });