Skip to content

Commit

Permalink
Disallow INTERSECT ALL and EXCEPT ALL; Allow MINUS
Browse files Browse the repository at this point in the history
  • Loading branch information
drodrigues4 committed Jul 24, 2024
1 parent 23aa8d2 commit d4e4045
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 153 deletions.
183 changes: 32 additions & 151 deletions drizzle-orm/src/singlestore-core/query-builders/select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -494,48 +494,6 @@ export abstract class SingleStoreSelectQueryBuilderBase<
*/
intersect = this.createSetOperator('intersect', false);

/**
* Adds `intersect all` set operator to the query.
*
* Calling this method will retain only the rows that are present in both result sets including all duplicates.
*
* See docs: {@link https://orm.drizzle.team/docs/set-operations#intersect-all}
*
* @example
*
* ```ts
* // Select all products and quantities that are ordered by both regular and VIP customers
* await db.select({
* productId: regularCustomerOrders.productId,
* quantityOrdered: regularCustomerOrders.quantityOrdered
* })
* .from(regularCustomerOrders)
* .intersectAll(
* db.select({
* productId: vipCustomerOrders.productId,
* quantityOrdered: vipCustomerOrders.quantityOrdered
* })
* .from(vipCustomerOrders)
* );
* // or
* import { intersectAll } from 'drizzle-orm/singlestore-core'
*
* await intersectAll(
* db.select({
* productId: regularCustomerOrders.productId,
* quantityOrdered: regularCustomerOrders.quantityOrdered
* })
* .from(regularCustomerOrders),
* db.select({
* productId: vipCustomerOrders.productId,
* quantityOrdered: vipCustomerOrders.quantityOrdered
* })
* .from(vipCustomerOrders)
* );
* ```
*/
intersectAll = this.createSetOperator('intersect', true);

/**
* Adds `except` set operator to the query.
*
Expand Down Expand Up @@ -564,46 +522,29 @@ export abstract class SingleStoreSelectQueryBuilderBase<
except = this.createSetOperator('except', false);

/**
* Adds `except all` set operator to the query.
*
* Calling this method will retrieve all rows from the left query, except for the rows that are present in the result set of the right query.
*
* See docs: {@link https://orm.drizzle.team/docs/set-operations#except-all}
*
* Adds `minus` set operator to the query.
*
* This is an alias of `except` supported by SingleStore.
*
* @example
*
* ```ts
* // Select all products that are ordered by regular customers but not by VIP customers
* await db.select({
* productId: regularCustomerOrders.productId,
* quantityOrdered: regularCustomerOrders.quantityOrdered,
* })
* .from(regularCustomerOrders)
* .exceptAll(
* db.select({
* productId: vipCustomerOrders.productId,
* quantityOrdered: vipCustomerOrders.quantityOrdered,
* })
* .from(vipCustomerOrders)
* );
* // Select all courses offered in department A but not in department B
* await db.select({ courseName: depA.courseName })
* .from(depA)
* .minus(
* db.select({ courseName: depB.courseName }).from(depB)
* );
* // or
* import { exceptAll } from 'drizzle-orm/singlestore-core'
*
* await exceptAll(
* db.select({
* productId: regularCustomerOrders.productId,
* quantityOrdered: regularCustomerOrders.quantityOrdered
* })
* .from(regularCustomerOrders),
* db.select({
* productId: vipCustomerOrders.productId,
* quantityOrdered: vipCustomerOrders.quantityOrdered
* })
* .from(vipCustomerOrders)
* import { minus } from 'drizzle-orm/singlestore-core'
*
* await minus(
* db.select({ courseName: depA.courseName }).from(depA),
* db.select({ courseName: depB.courseName }).from(depB)
* );
* ```
*/
exceptAll = this.createSetOperator('except', true);
minus = this.createSetOperator('except', false);

/** @internal */
addSetOperators(setOperators: SingleStoreSelectConfig['setOperators']): SingleStoreSelectWithout<
Expand Down Expand Up @@ -1002,9 +943,8 @@ const getSingleStoreSetOperators = () => ({
union,
unionAll,
intersect,
intersectAll,
except,
exceptAll,
minus,
});

/**
Expand Down Expand Up @@ -1088,48 +1028,6 @@ export const unionAll = createSetOperator('union', true);
*/
export const intersect = createSetOperator('intersect', false);

/**
* Adds `intersect all` set operator to the query.
*
* Calling this method will retain only the rows that are present in both result sets including all duplicates.
*
* See docs: {@link https://orm.drizzle.team/docs/set-operations#intersect-all}
*
* @example
*
* ```ts
* // Select all products and quantities that are ordered by both regular and VIP customers
* import { intersectAll } from 'drizzle-orm/singlestore-core'
*
* await intersectAll(
* db.select({
* productId: regularCustomerOrders.productId,
* quantityOrdered: regularCustomerOrders.quantityOrdered
* })
* .from(regularCustomerOrders),
* db.select({
* productId: vipCustomerOrders.productId,
* quantityOrdered: vipCustomerOrders.quantityOrdered
* })
* .from(vipCustomerOrders)
* );
* // or
* await db.select({
* productId: regularCustomerOrders.productId,
* quantityOrdered: regularCustomerOrders.quantityOrdered
* })
* .from(regularCustomerOrders)
* .intersectAll(
* db.select({
* productId: vipCustomerOrders.productId,
* quantityOrdered: vipCustomerOrders.quantityOrdered
* })
* .from(vipCustomerOrders)
* );
* ```
*/
export const intersectAll = createSetOperator('intersect', true);

/**
* Adds `except` set operator to the query.
*
Expand Down Expand Up @@ -1158,43 +1056,26 @@ export const intersectAll = createSetOperator('intersect', true);
export const except = createSetOperator('except', false);

/**
* Adds `except all` set operator to the query.
*
* Calling this method will retrieve all rows from the left query, except for the rows that are present in the result set of the right query.
*
* See docs: {@link https://orm.drizzle.team/docs/set-operations#except-all}
*
* Adds `minus` set operator to the query.
*
* This is an alias of `except` supported by SingleStore.
*
* @example
*
* ```ts
* // Select all products that are ordered by regular customers but not by VIP customers
* import { exceptAll } from 'drizzle-orm/singlestore-core'
* // Select all courses offered in department A but not in department B
* import { minus } from 'drizzle-orm/singlestore-core'
*
* await exceptAll(
* db.select({
* productId: regularCustomerOrders.productId,
* quantityOrdered: regularCustomerOrders.quantityOrdered
* })
* .from(regularCustomerOrders),
* db.select({
* productId: vipCustomerOrders.productId,
* quantityOrdered: vipCustomerOrders.quantityOrdered
* })
* .from(vipCustomerOrders)
* await minus(
* db.select({ courseName: depA.courseName }).from(depA),
* db.select({ courseName: depB.courseName }).from(depB)
* );
* // or
* await db.select({
* productId: regularCustomerOrders.productId,
* quantityOrdered: regularCustomerOrders.quantityOrdered,
* })
* .from(regularCustomerOrders)
* .exceptAll(
* db.select({
* productId: vipCustomerOrders.productId,
* quantityOrdered: vipCustomerOrders.quantityOrdered,
* })
* .from(vipCustomerOrders)
* );
* await db.select({ courseName: depA.courseName })
* .from(depA)
* .minus(
* db.select({ courseName: depB.courseName }).from(depB)
* );
* ```
*/
export const exceptAll = createSetOperator('except', true);
export const minus = createSetOperator('except', true);
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,5 @@ export type GetSingleStoreSetOperators = {
intersect: SingleStoreCreateSetOperatorFn;
except: SingleStoreCreateSetOperatorFn;
unionAll: SingleStoreCreateSetOperatorFn;
intersectAll: SingleStoreCreateSetOperatorFn;
exceptAll: SingleStoreCreateSetOperatorFn;
minus: SingleStoreCreateSetOperatorFn;
};

0 comments on commit d4e4045

Please sign in to comment.