Skip to content

Commit

Permalink
Merge pull request #9 from singlestore-labs/feature/singlestore-type-…
Browse files Browse the repository at this point in the history
…tests

Feature/singlestore type tests
  • Loading branch information
Rodriguespn authored Aug 21, 2024
2 parents 345def7 + ae78e04 commit 8dd9d1d
Show file tree
Hide file tree
Showing 12 changed files with 3,288 additions and 0 deletions.
170 changes: 170 additions & 0 deletions drizzle-orm/src/singlestore-core/query-builders/select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,48 @@ 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/pg-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 @@ -521,6 +563,48 @@ 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}
*
* @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)
* );
* // or
* import { exceptAll } from 'drizzle-orm/pg-core'
*
* await exceptAll(
* db.select({
* productId: regularCustomerOrders.productId,
* quantityOrdered: regularCustomerOrders.quantityOrdered
* })
* .from(regularCustomerOrders),
* db.select({
* productId: vipCustomerOrders.productId,
* quantityOrdered: vipCustomerOrders.quantityOrdered
* })
* .from(vipCustomerOrders)
* );
* ```
*/
exceptAll = this.createSetOperator('except', true);

/**
* Adds `minus` set operator to the query.
*
Expand Down Expand Up @@ -943,7 +1027,9 @@ const getSingleStoreSetOperators = () => ({
union,
unionAll,
intersect,
intersectAll,
except,
exceptAll,
minus,
});

Expand Down Expand Up @@ -1028,6 +1114,48 @@ 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/mysql-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 @@ -1055,6 +1183,48 @@ export const intersect = createSetOperator('intersect', false);
*/
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}
*
* @example
*
* ```ts
* // Select all products that are ordered by regular customers but not by VIP customers
* import { exceptAll } from 'drizzle-orm/mysql-core'
*
* await exceptAll(
* 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)
* .exceptAll(
* db.select({
* productId: vipCustomerOrders.productId,
* quantityOrdered: vipCustomerOrders.quantityOrdered,
* })
* .from(vipCustomerOrders)
* );
* ```
*/
export const exceptAll = createSetOperator('except', true);

/**
* Adds `minus` set operator to the query.
*
Expand Down
Loading

0 comments on commit 8dd9d1d

Please sign in to comment.