with() — drizzle-orm Function Reference
Architecture documentation for the with() function in db.ts from the drizzle-orm codebase.
Entity Profile
Dependency Diagram
graph TD 92708577_0446_8fcc_a6d6_c05d0c9005b0["with()"] 9f85cd22_fd1d_a3c9_2e3f_f17ef323455e["BaseSQLiteDatabase"] 92708577_0446_8fcc_a6d6_c05d0c9005b0 -->|defined in| 9f85cd22_fd1d_a3c9_2e3f_f17ef323455e b0a10589_f90f_2f86_cfda_0887e40c5f4f["select()"] 92708577_0446_8fcc_a6d6_c05d0c9005b0 -->|calls| b0a10589_f90f_2f86_cfda_0887e40c5f4f 4ad96ef6_a777_f318_7f1e_4f43a66fcf91["selectDistinct()"] 92708577_0446_8fcc_a6d6_c05d0c9005b0 -->|calls| 4ad96ef6_a777_f318_7f1e_4f43a66fcf91 fc16af3e_3100_a7f6_55e0_a4f8b741a096["update()"] 92708577_0446_8fcc_a6d6_c05d0c9005b0 -->|calls| fc16af3e_3100_a7f6_55e0_a4f8b741a096 00f24df6_58eb_5e6d_d5b6_f743143ee711["values()"] 92708577_0446_8fcc_a6d6_c05d0c9005b0 -->|calls| 00f24df6_58eb_5e6d_d5b6_f743143ee711 ef603885_d0e2_bb44_930e_01cdc05b63df["insert()"] 92708577_0446_8fcc_a6d6_c05d0c9005b0 -->|calls| ef603885_d0e2_bb44_930e_01cdc05b63df style 92708577_0446_8fcc_a6d6_c05d0c9005b0 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
drizzle-orm/src/sqlite-core/db.ts lines 175–358
with(...queries: WithSubquery[]) {
const self = this;
/**
* Creates a select query.
*
* Calling this method with no arguments will select all columns from the table. Pass a selection object to specify the columns you want to select.
*
* Use `.from()` method to specify which table to select from.
*
* See docs: {@link https://orm.drizzle.team/docs/select}
*
* @param fields The selection object.
*
* @example
*
* ```ts
* // Select all columns and all rows from the 'cars' table
* const allCars: Car[] = await db.select().from(cars);
*
* // Select specific columns and all rows from the 'cars' table
* const carsIdsAndBrands: { id: number; brand: string }[] = await db.select({
* id: cars.id,
* brand: cars.brand
* })
* .from(cars);
* ```
*
* Like in SQL, you can use arbitrary expressions as selection fields, not just table columns:
*
* ```ts
* // Select specific columns along with expression and all rows from the 'cars' table
* const carsIdsAndLowerNames: { id: number; lowerBrand: string }[] = await db.select({
* id: cars.id,
* lowerBrand: sql<string>`lower(${cars.brand})`,
* })
* .from(cars);
* ```
*/
function select(): SQLiteSelectBuilder<undefined, TResultKind, TRunResult>;
function select<TSelection extends SelectedFields>(
fields: TSelection,
): SQLiteSelectBuilder<TSelection, TResultKind, TRunResult>;
function select(
fields?: SelectedFields,
): SQLiteSelectBuilder<SelectedFields | undefined, TResultKind, TRunResult> {
return new SQLiteSelectBuilder({
fields: fields ?? undefined,
session: self.session,
dialect: self.dialect,
withList: queries,
});
}
/**
* Adds `distinct` expression to the select query.
*
* Calling this method will return only unique values. When multiple columns are selected, it returns rows with unique combinations of values in these columns.
*
* Use `.from()` method to specify which table to select from.
*
* See docs: {@link https://orm.drizzle.team/docs/select#distinct}
*
* @param fields The selection object.
*
* @example
*
* ```ts
* // Select all unique rows from the 'cars' table
* await db.selectDistinct()
* .from(cars)
* .orderBy(cars.id, cars.brand, cars.color);
*
* // Select all unique brands from the 'cars' table
* await db.selectDistinct({ brand: cars.brand })
* .from(cars)
* .orderBy(cars.brand);
* ```
*/
function selectDistinct(): SQLiteSelectBuilder<undefined, TResultKind, TRunResult>;
function selectDistinct<TSelection extends SelectedFields>(
Domain
Subdomains
Defined In
Source
Frequently Asked Questions
What does with() do?
with() is a function in the drizzle-orm codebase, defined in drizzle-orm/src/sqlite-core/db.ts.
Where is with() defined?
with() is defined in drizzle-orm/src/sqlite-core/db.ts at line 175.
What does with() call?
with() calls 5 function(s): insert, select, selectDistinct, update, values.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free