select.d.cts 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569
  1. import type { CacheConfig, WithCacheConfig } from "../../cache/core/types.cjs";
  2. import { entityKind } from "../../entity.cjs";
  3. import { TypedQueryBuilder } from "../../query-builders/query-builder.cjs";
  4. import type { BuildSubquerySelection, GetSelectTableName, GetSelectTableSelection, JoinNullability, SelectMode, SelectResult } from "../../query-builders/select.types.cjs";
  5. import { QueryPromise } from "../../query-promise.cjs";
  6. import type { RunnableQuery } from "../../runnable-query.cjs";
  7. import { SQL } from "../../sql/sql.cjs";
  8. import type { ColumnsSelection, Placeholder, Query, SQLWrapper } from "../../sql/sql.cjs";
  9. import type { SQLiteColumn } from "../columns/index.cjs";
  10. import type { SQLiteDialect } from "../dialect.cjs";
  11. import type { SQLiteSession } from "../session.cjs";
  12. import type { SubqueryWithSelection } from "../subquery.cjs";
  13. import type { SQLiteTable } from "../table.cjs";
  14. import { Subquery } from "../../subquery.cjs";
  15. import { type ValueOrArray } from "../../utils.cjs";
  16. import { SQLiteViewBase } from "../view-base.cjs";
  17. import type { CreateSQLiteSelectFromBuilderMode, GetSQLiteSetOperators, SelectedFields, SetOperatorRightSelect, SQLiteCreateSetOperatorFn, SQLiteSelectConfig, SQLiteSelectCrossJoinFn, SQLiteSelectDynamic, SQLiteSelectExecute, SQLiteSelectHKT, SQLiteSelectHKTBase, SQLiteSelectJoinFn, SQLiteSelectPrepare, SQLiteSelectWithout, SQLiteSetOperatorExcludedMethods, SQLiteSetOperatorWithResult } from "./select.types.cjs";
  18. export declare class SQLiteSelectBuilder<TSelection extends SelectedFields | undefined, TResultType extends 'sync' | 'async', TRunResult, TBuilderMode extends 'db' | 'qb' = 'db'> {
  19. static readonly [entityKind]: string;
  20. private fields;
  21. private session;
  22. private dialect;
  23. private withList;
  24. private distinct;
  25. constructor(config: {
  26. fields: TSelection;
  27. session: SQLiteSession<any, any, any, any> | undefined;
  28. dialect: SQLiteDialect;
  29. withList?: Subquery[];
  30. distinct?: boolean;
  31. });
  32. from<TFrom extends SQLiteTable | Subquery | SQLiteViewBase | SQL>(source: TFrom): CreateSQLiteSelectFromBuilderMode<TBuilderMode, GetSelectTableName<TFrom>, TResultType, TRunResult, TSelection extends undefined ? GetSelectTableSelection<TFrom> : TSelection, TSelection extends undefined ? 'single' : 'partial'>;
  33. }
  34. export declare abstract class SQLiteSelectQueryBuilderBase<THKT extends SQLiteSelectHKTBase, TTableName extends string | undefined, TResultType extends 'sync' | 'async', TRunResult, TSelection extends ColumnsSelection, TSelectMode extends SelectMode, TNullabilityMap extends Record<string, JoinNullability> = TTableName extends string ? Record<TTableName, 'not-null'> : {}, TDynamic extends boolean = false, TExcludedMethods extends string = never, TResult extends any[] = SelectResult<TSelection, TSelectMode, TNullabilityMap>[], TSelectedFields extends ColumnsSelection = BuildSubquerySelection<TSelection, TNullabilityMap>> extends TypedQueryBuilder<TSelectedFields, TResult> {
  35. static readonly [entityKind]: string;
  36. readonly _: {
  37. readonly dialect: 'sqlite';
  38. readonly hkt: THKT;
  39. readonly tableName: TTableName;
  40. readonly resultType: TResultType;
  41. readonly runResult: TRunResult;
  42. readonly selection: TSelection;
  43. readonly selectMode: TSelectMode;
  44. readonly nullabilityMap: TNullabilityMap;
  45. readonly dynamic: TDynamic;
  46. readonly excludedMethods: TExcludedMethods;
  47. readonly result: TResult;
  48. readonly selectedFields: TSelectedFields;
  49. readonly config: SQLiteSelectConfig;
  50. };
  51. protected joinsNotNullableMap: Record<string, boolean>;
  52. private tableName;
  53. private isPartialSelect;
  54. protected session: SQLiteSession<any, any, any, any> | undefined;
  55. protected dialect: SQLiteDialect;
  56. protected cacheConfig?: WithCacheConfig;
  57. protected usedTables: Set<string>;
  58. constructor({ table, fields, isPartialSelect, session, dialect, withList, distinct }: {
  59. table: SQLiteSelectConfig['table'];
  60. fields: SQLiteSelectConfig['fields'];
  61. isPartialSelect: boolean;
  62. session: SQLiteSession<any, any, any, any> | undefined;
  63. dialect: SQLiteDialect;
  64. withList: Subquery[] | undefined;
  65. distinct: boolean | undefined;
  66. });
  67. private createJoin;
  68. /**
  69. * Executes a `left join` operation by adding another table to the current query.
  70. *
  71. * Calling this method associates each row of the table with the corresponding row from the joined table, if a match is found. If no matching row exists, it sets all columns of the joined table to null.
  72. *
  73. * See docs: {@link https://orm.drizzle.team/docs/joins#left-join}
  74. *
  75. * @param table the table to join.
  76. * @param on the `on` clause.
  77. *
  78. * @example
  79. *
  80. * ```ts
  81. * // Select all users and their pets
  82. * const usersWithPets: { user: User; pets: Pet | null; }[] = await db.select()
  83. * .from(users)
  84. * .leftJoin(pets, eq(users.id, pets.ownerId))
  85. *
  86. * // Select userId and petId
  87. * const usersIdsAndPetIds: { userId: number; petId: number | null; }[] = await db.select({
  88. * userId: users.id,
  89. * petId: pets.id,
  90. * })
  91. * .from(users)
  92. * .leftJoin(pets, eq(users.id, pets.ownerId))
  93. * ```
  94. */
  95. leftJoin: SQLiteSelectJoinFn<this, TDynamic, "left">;
  96. /**
  97. * Executes a `right join` operation by adding another table to the current query.
  98. *
  99. * Calling this method associates each row of the joined table with the corresponding row from the main table, if a match is found. If no matching row exists, it sets all columns of the main table to null.
  100. *
  101. * See docs: {@link https://orm.drizzle.team/docs/joins#right-join}
  102. *
  103. * @param table the table to join.
  104. * @param on the `on` clause.
  105. *
  106. * @example
  107. *
  108. * ```ts
  109. * // Select all users and their pets
  110. * const usersWithPets: { user: User | null; pets: Pet; }[] = await db.select()
  111. * .from(users)
  112. * .rightJoin(pets, eq(users.id, pets.ownerId))
  113. *
  114. * // Select userId and petId
  115. * const usersIdsAndPetIds: { userId: number | null; petId: number; }[] = await db.select({
  116. * userId: users.id,
  117. * petId: pets.id,
  118. * })
  119. * .from(users)
  120. * .rightJoin(pets, eq(users.id, pets.ownerId))
  121. * ```
  122. */
  123. rightJoin: SQLiteSelectJoinFn<this, TDynamic, "right">;
  124. /**
  125. * Executes an `inner join` operation, creating a new table by combining rows from two tables that have matching values.
  126. *
  127. * Calling this method retrieves rows that have corresponding entries in both joined tables. Rows without matching entries in either table are excluded, resulting in a table that includes only matching pairs.
  128. *
  129. * See docs: {@link https://orm.drizzle.team/docs/joins#inner-join}
  130. *
  131. * @param table the table to join.
  132. * @param on the `on` clause.
  133. *
  134. * @example
  135. *
  136. * ```ts
  137. * // Select all users and their pets
  138. * const usersWithPets: { user: User; pets: Pet; }[] = await db.select()
  139. * .from(users)
  140. * .innerJoin(pets, eq(users.id, pets.ownerId))
  141. *
  142. * // Select userId and petId
  143. * const usersIdsAndPetIds: { userId: number; petId: number; }[] = await db.select({
  144. * userId: users.id,
  145. * petId: pets.id,
  146. * })
  147. * .from(users)
  148. * .innerJoin(pets, eq(users.id, pets.ownerId))
  149. * ```
  150. */
  151. innerJoin: SQLiteSelectJoinFn<this, TDynamic, "inner">;
  152. /**
  153. * Executes a `full join` operation by combining rows from two tables into a new table.
  154. *
  155. * Calling this method retrieves all rows from both main and joined tables, merging rows with matching values and filling in `null` for non-matching columns.
  156. *
  157. * See docs: {@link https://orm.drizzle.team/docs/joins#full-join}
  158. *
  159. * @param table the table to join.
  160. * @param on the `on` clause.
  161. *
  162. * @example
  163. *
  164. * ```ts
  165. * // Select all users and their pets
  166. * const usersWithPets: { user: User | null; pets: Pet | null; }[] = await db.select()
  167. * .from(users)
  168. * .fullJoin(pets, eq(users.id, pets.ownerId))
  169. *
  170. * // Select userId and petId
  171. * const usersIdsAndPetIds: { userId: number | null; petId: number | null; }[] = await db.select({
  172. * userId: users.id,
  173. * petId: pets.id,
  174. * })
  175. * .from(users)
  176. * .fullJoin(pets, eq(users.id, pets.ownerId))
  177. * ```
  178. */
  179. fullJoin: SQLiteSelectJoinFn<this, TDynamic, "full">;
  180. /**
  181. * Executes a `cross join` operation by combining rows from two tables into a new table.
  182. *
  183. * Calling this method retrieves all rows from both main and joined tables, merging all rows from each table.
  184. *
  185. * See docs: {@link https://orm.drizzle.team/docs/joins#cross-join}
  186. *
  187. * @param table the table to join.
  188. *
  189. * @example
  190. *
  191. * ```ts
  192. * // Select all users, each user with every pet
  193. * const usersWithPets: { user: User; pets: Pet; }[] = await db.select()
  194. * .from(users)
  195. * .crossJoin(pets)
  196. *
  197. * // Select userId and petId
  198. * const usersIdsAndPetIds: { userId: number; petId: number; }[] = await db.select({
  199. * userId: users.id,
  200. * petId: pets.id,
  201. * })
  202. * .from(users)
  203. * .crossJoin(pets)
  204. * ```
  205. */
  206. crossJoin: SQLiteSelectCrossJoinFn<this, TDynamic>;
  207. private createSetOperator;
  208. /**
  209. * Adds `union` set operator to the query.
  210. *
  211. * Calling this method will combine the result sets of the `select` statements and remove any duplicate rows that appear across them.
  212. *
  213. * See docs: {@link https://orm.drizzle.team/docs/set-operations#union}
  214. *
  215. * @example
  216. *
  217. * ```ts
  218. * // Select all unique names from customers and users tables
  219. * await db.select({ name: users.name })
  220. * .from(users)
  221. * .union(
  222. * db.select({ name: customers.name }).from(customers)
  223. * );
  224. * // or
  225. * import { union } from 'drizzle-orm/sqlite-core'
  226. *
  227. * await union(
  228. * db.select({ name: users.name }).from(users),
  229. * db.select({ name: customers.name }).from(customers)
  230. * );
  231. * ```
  232. */
  233. union: <TValue extends SQLiteSetOperatorWithResult<TResult>>(rightSelection: ((setOperators: GetSQLiteSetOperators) => SetOperatorRightSelect<TValue, TResult>) | SetOperatorRightSelect<TValue, TResult>) => SQLiteSelectWithout<this, TDynamic, SQLiteSetOperatorExcludedMethods, true>;
  234. /**
  235. * Adds `union all` set operator to the query.
  236. *
  237. * Calling this method will combine the result-set of the `select` statements and keep all duplicate rows that appear across them.
  238. *
  239. * See docs: {@link https://orm.drizzle.team/docs/set-operations#union-all}
  240. *
  241. * @example
  242. *
  243. * ```ts
  244. * // Select all transaction ids from both online and in-store sales
  245. * await db.select({ transaction: onlineSales.transactionId })
  246. * .from(onlineSales)
  247. * .unionAll(
  248. * db.select({ transaction: inStoreSales.transactionId }).from(inStoreSales)
  249. * );
  250. * // or
  251. * import { unionAll } from 'drizzle-orm/sqlite-core'
  252. *
  253. * await unionAll(
  254. * db.select({ transaction: onlineSales.transactionId }).from(onlineSales),
  255. * db.select({ transaction: inStoreSales.transactionId }).from(inStoreSales)
  256. * );
  257. * ```
  258. */
  259. unionAll: <TValue extends SQLiteSetOperatorWithResult<TResult>>(rightSelection: ((setOperators: GetSQLiteSetOperators) => SetOperatorRightSelect<TValue, TResult>) | SetOperatorRightSelect<TValue, TResult>) => SQLiteSelectWithout<this, TDynamic, SQLiteSetOperatorExcludedMethods, true>;
  260. /**
  261. * Adds `intersect` set operator to the query.
  262. *
  263. * Calling this method will retain only the rows that are present in both result sets and eliminate duplicates.
  264. *
  265. * See docs: {@link https://orm.drizzle.team/docs/set-operations#intersect}
  266. *
  267. * @example
  268. *
  269. * ```ts
  270. * // Select course names that are offered in both departments A and B
  271. * await db.select({ courseName: depA.courseName })
  272. * .from(depA)
  273. * .intersect(
  274. * db.select({ courseName: depB.courseName }).from(depB)
  275. * );
  276. * // or
  277. * import { intersect } from 'drizzle-orm/sqlite-core'
  278. *
  279. * await intersect(
  280. * db.select({ courseName: depA.courseName }).from(depA),
  281. * db.select({ courseName: depB.courseName }).from(depB)
  282. * );
  283. * ```
  284. */
  285. intersect: <TValue extends SQLiteSetOperatorWithResult<TResult>>(rightSelection: ((setOperators: GetSQLiteSetOperators) => SetOperatorRightSelect<TValue, TResult>) | SetOperatorRightSelect<TValue, TResult>) => SQLiteSelectWithout<this, TDynamic, SQLiteSetOperatorExcludedMethods, true>;
  286. /**
  287. * Adds `except` set operator to the query.
  288. *
  289. * Calling this method will retrieve all unique rows from the left query, except for the rows that are present in the result set of the right query.
  290. *
  291. * See docs: {@link https://orm.drizzle.team/docs/set-operations#except}
  292. *
  293. * @example
  294. *
  295. * ```ts
  296. * // Select all courses offered in department A but not in department B
  297. * await db.select({ courseName: depA.courseName })
  298. * .from(depA)
  299. * .except(
  300. * db.select({ courseName: depB.courseName }).from(depB)
  301. * );
  302. * // or
  303. * import { except } from 'drizzle-orm/sqlite-core'
  304. *
  305. * await except(
  306. * db.select({ courseName: depA.courseName }).from(depA),
  307. * db.select({ courseName: depB.courseName }).from(depB)
  308. * );
  309. * ```
  310. */
  311. except: <TValue extends SQLiteSetOperatorWithResult<TResult>>(rightSelection: ((setOperators: GetSQLiteSetOperators) => SetOperatorRightSelect<TValue, TResult>) | SetOperatorRightSelect<TValue, TResult>) => SQLiteSelectWithout<this, TDynamic, SQLiteSetOperatorExcludedMethods, true>;
  312. /**
  313. * Adds a `where` clause to the query.
  314. *
  315. * Calling this method will select only those rows that fulfill a specified condition.
  316. *
  317. * See docs: {@link https://orm.drizzle.team/docs/select#filtering}
  318. *
  319. * @param where the `where` clause.
  320. *
  321. * @example
  322. * You can use conditional operators and `sql function` to filter the rows to be selected.
  323. *
  324. * ```ts
  325. * // Select all cars with green color
  326. * await db.select().from(cars).where(eq(cars.color, 'green'));
  327. * // or
  328. * await db.select().from(cars).where(sql`${cars.color} = 'green'`)
  329. * ```
  330. *
  331. * You can logically combine conditional operators with `and()` and `or()` operators:
  332. *
  333. * ```ts
  334. * // Select all BMW cars with a green color
  335. * await db.select().from(cars).where(and(eq(cars.color, 'green'), eq(cars.brand, 'BMW')));
  336. *
  337. * // Select all cars with the green or blue color
  338. * await db.select().from(cars).where(or(eq(cars.color, 'green'), eq(cars.color, 'blue')));
  339. * ```
  340. */
  341. where(where: ((aliases: TSelection) => SQL | undefined) | SQL | undefined): SQLiteSelectWithout<this, TDynamic, 'where'>;
  342. /**
  343. * Adds a `having` clause to the query.
  344. *
  345. * Calling this method will select only those rows that fulfill a specified condition. It is typically used with aggregate functions to filter the aggregated data based on a specified condition.
  346. *
  347. * See docs: {@link https://orm.drizzle.team/docs/select#aggregations}
  348. *
  349. * @param having the `having` clause.
  350. *
  351. * @example
  352. *
  353. * ```ts
  354. * // Select all brands with more than one car
  355. * await db.select({
  356. * brand: cars.brand,
  357. * count: sql<number>`cast(count(${cars.id}) as int)`,
  358. * })
  359. * .from(cars)
  360. * .groupBy(cars.brand)
  361. * .having(({ count }) => gt(count, 1));
  362. * ```
  363. */
  364. having(having: ((aliases: this['_']['selection']) => SQL | undefined) | SQL | undefined): SQLiteSelectWithout<this, TDynamic, 'having'>;
  365. /**
  366. * Adds a `group by` clause to the query.
  367. *
  368. * Calling this method will group rows that have the same values into summary rows, often used for aggregation purposes.
  369. *
  370. * See docs: {@link https://orm.drizzle.team/docs/select#aggregations}
  371. *
  372. * @example
  373. *
  374. * ```ts
  375. * // Group and count people by their last names
  376. * await db.select({
  377. * lastName: people.lastName,
  378. * count: sql<number>`cast(count(*) as int)`
  379. * })
  380. * .from(people)
  381. * .groupBy(people.lastName);
  382. * ```
  383. */
  384. groupBy(builder: (aliases: this['_']['selection']) => ValueOrArray<SQLiteColumn | SQL | SQL.Aliased>): SQLiteSelectWithout<this, TDynamic, 'groupBy'>;
  385. groupBy(...columns: (SQLiteColumn | SQL)[]): SQLiteSelectWithout<this, TDynamic, 'groupBy'>;
  386. /**
  387. * Adds an `order by` clause to the query.
  388. *
  389. * Calling this method will sort the result-set in ascending or descending order. By default, the sort order is ascending.
  390. *
  391. * See docs: {@link https://orm.drizzle.team/docs/select#order-by}
  392. *
  393. * @example
  394. *
  395. * ```
  396. * // Select cars ordered by year
  397. * await db.select().from(cars).orderBy(cars.year);
  398. * ```
  399. *
  400. * You can specify whether results are in ascending or descending order with the `asc()` and `desc()` operators.
  401. *
  402. * ```ts
  403. * // Select cars ordered by year in descending order
  404. * await db.select().from(cars).orderBy(desc(cars.year));
  405. *
  406. * // Select cars ordered by year and price
  407. * await db.select().from(cars).orderBy(asc(cars.year), desc(cars.price));
  408. * ```
  409. */
  410. orderBy(builder: (aliases: this['_']['selection']) => ValueOrArray<SQLiteColumn | SQL | SQL.Aliased>): SQLiteSelectWithout<this, TDynamic, 'orderBy'>;
  411. orderBy(...columns: (SQLiteColumn | SQL)[]): SQLiteSelectWithout<this, TDynamic, 'orderBy'>;
  412. /**
  413. * Adds a `limit` clause to the query.
  414. *
  415. * Calling this method will set the maximum number of rows that will be returned by this query.
  416. *
  417. * See docs: {@link https://orm.drizzle.team/docs/select#limit--offset}
  418. *
  419. * @param limit the `limit` clause.
  420. *
  421. * @example
  422. *
  423. * ```ts
  424. * // Get the first 10 people from this query.
  425. * await db.select().from(people).limit(10);
  426. * ```
  427. */
  428. limit(limit: number | Placeholder): SQLiteSelectWithout<this, TDynamic, 'limit'>;
  429. /**
  430. * Adds an `offset` clause to the query.
  431. *
  432. * Calling this method will skip a number of rows when returning results from this query.
  433. *
  434. * See docs: {@link https://orm.drizzle.team/docs/select#limit--offset}
  435. *
  436. * @param offset the `offset` clause.
  437. *
  438. * @example
  439. *
  440. * ```ts
  441. * // Get the 10th-20th people from this query.
  442. * await db.select().from(people).offset(10).limit(10);
  443. * ```
  444. */
  445. offset(offset: number | Placeholder): SQLiteSelectWithout<this, TDynamic, 'offset'>;
  446. toSQL(): Query;
  447. as<TAlias extends string>(alias: TAlias): SubqueryWithSelection<this['_']['selectedFields'], TAlias>;
  448. $dynamic(): SQLiteSelectDynamic<this>;
  449. }
  450. export interface SQLiteSelectBase<TTableName extends string | undefined, TResultType extends 'sync' | 'async', TRunResult, TSelection extends ColumnsSelection, TSelectMode extends SelectMode = 'single', TNullabilityMap extends Record<string, JoinNullability> = TTableName extends string ? Record<TTableName, 'not-null'> : {}, TDynamic extends boolean = false, TExcludedMethods extends string = never, TResult extends any[] = SelectResult<TSelection, TSelectMode, TNullabilityMap>[], TSelectedFields extends ColumnsSelection = BuildSubquerySelection<TSelection, TNullabilityMap>> extends SQLiteSelectQueryBuilderBase<SQLiteSelectHKT, TTableName, TResultType, TRunResult, TSelection, TSelectMode, TNullabilityMap, TDynamic, TExcludedMethods, TResult, TSelectedFields>, QueryPromise<TResult> {
  451. }
  452. export declare class SQLiteSelectBase<TTableName extends string | undefined, TResultType extends 'sync' | 'async', TRunResult, TSelection, TSelectMode extends SelectMode = 'single', TNullabilityMap extends Record<string, JoinNullability> = TTableName extends string ? Record<TTableName, 'not-null'> : {}, TDynamic extends boolean = false, TExcludedMethods extends string = never, TResult = SelectResult<TSelection, TSelectMode, TNullabilityMap>[], TSelectedFields extends ColumnsSelection = BuildSubquerySelection<TSelection, TNullabilityMap>> extends SQLiteSelectQueryBuilderBase<SQLiteSelectHKT, TTableName, TResultType, TRunResult, TSelection, TSelectMode, TNullabilityMap, TDynamic, TExcludedMethods, TResult, TSelectedFields> implements RunnableQuery<TResult, 'sqlite'>, SQLWrapper {
  453. static readonly [entityKind]: string;
  454. $withCache(config?: {
  455. config?: CacheConfig;
  456. tag?: string;
  457. autoInvalidate?: boolean;
  458. } | false): this;
  459. prepare(): SQLiteSelectPrepare<this>;
  460. run: ReturnType<this['prepare']>['run'];
  461. all: ReturnType<this['prepare']>['all'];
  462. get: ReturnType<this['prepare']>['get'];
  463. values: ReturnType<this['prepare']>['values'];
  464. execute(): Promise<SQLiteSelectExecute<this>>;
  465. }
  466. /**
  467. * Adds `union` set operator to the query.
  468. *
  469. * Calling this method will combine the result sets of the `select` statements and remove any duplicate rows that appear across them.
  470. *
  471. * See docs: {@link https://orm.drizzle.team/docs/set-operations#union}
  472. *
  473. * @example
  474. *
  475. * ```ts
  476. * // Select all unique names from customers and users tables
  477. * import { union } from 'drizzle-orm/sqlite-core'
  478. *
  479. * await union(
  480. * db.select({ name: users.name }).from(users),
  481. * db.select({ name: customers.name }).from(customers)
  482. * );
  483. * // or
  484. * await db.select({ name: users.name })
  485. * .from(users)
  486. * .union(
  487. * db.select({ name: customers.name }).from(customers)
  488. * );
  489. * ```
  490. */
  491. export declare const union: SQLiteCreateSetOperatorFn;
  492. /**
  493. * Adds `union all` set operator to the query.
  494. *
  495. * Calling this method will combine the result-set of the `select` statements and keep all duplicate rows that appear across them.
  496. *
  497. * See docs: {@link https://orm.drizzle.team/docs/set-operations#union-all}
  498. *
  499. * @example
  500. *
  501. * ```ts
  502. * // Select all transaction ids from both online and in-store sales
  503. * import { unionAll } from 'drizzle-orm/sqlite-core'
  504. *
  505. * await unionAll(
  506. * db.select({ transaction: onlineSales.transactionId }).from(onlineSales),
  507. * db.select({ transaction: inStoreSales.transactionId }).from(inStoreSales)
  508. * );
  509. * // or
  510. * await db.select({ transaction: onlineSales.transactionId })
  511. * .from(onlineSales)
  512. * .unionAll(
  513. * db.select({ transaction: inStoreSales.transactionId }).from(inStoreSales)
  514. * );
  515. * ```
  516. */
  517. export declare const unionAll: SQLiteCreateSetOperatorFn;
  518. /**
  519. * Adds `intersect` set operator to the query.
  520. *
  521. * Calling this method will retain only the rows that are present in both result sets and eliminate duplicates.
  522. *
  523. * See docs: {@link https://orm.drizzle.team/docs/set-operations#intersect}
  524. *
  525. * @example
  526. *
  527. * ```ts
  528. * // Select course names that are offered in both departments A and B
  529. * import { intersect } from 'drizzle-orm/sqlite-core'
  530. *
  531. * await intersect(
  532. * db.select({ courseName: depA.courseName }).from(depA),
  533. * db.select({ courseName: depB.courseName }).from(depB)
  534. * );
  535. * // or
  536. * await db.select({ courseName: depA.courseName })
  537. * .from(depA)
  538. * .intersect(
  539. * db.select({ courseName: depB.courseName }).from(depB)
  540. * );
  541. * ```
  542. */
  543. export declare const intersect: SQLiteCreateSetOperatorFn;
  544. /**
  545. * Adds `except` set operator to the query.
  546. *
  547. * Calling this method will retrieve all unique rows from the left query, except for the rows that are present in the result set of the right query.
  548. *
  549. * See docs: {@link https://orm.drizzle.team/docs/set-operations#except}
  550. *
  551. * @example
  552. *
  553. * ```ts
  554. * // Select all courses offered in department A but not in department B
  555. * import { except } from 'drizzle-orm/sqlite-core'
  556. *
  557. * await except(
  558. * db.select({ courseName: depA.courseName }).from(depA),
  559. * db.select({ courseName: depB.courseName }).from(depB)
  560. * );
  561. * // or
  562. * await db.select({ courseName: depA.courseName })
  563. * .from(depA)
  564. * .except(
  565. * db.select({ courseName: depB.courseName }).from(depB)
  566. * );
  567. * ```
  568. */
  569. export declare const except: SQLiteCreateSetOperatorFn;