Home / Class/ PgDeleteBase Class — drizzle-orm Architecture

PgDeleteBase Class — drizzle-orm Architecture

Architecture documentation for the PgDeleteBase class in delete.ts from the drizzle-orm codebase.

Entity Profile

Dependency Diagram

graph TD
  05d108b6_b51f_ac46_de61_e5660edaf3b0["PgDeleteBase"]
  bfd682c7_d1a3_f5aa_2d43_7e0859755bb8["delete.ts"]
  05d108b6_b51f_ac46_de61_e5660edaf3b0 -->|defined in| bfd682c7_d1a3_f5aa_2d43_7e0859755bb8
  a6fed255_ca18_a93f_4bb5_715d40fd728f["constructor()"]
  05d108b6_b51f_ac46_de61_e5660edaf3b0 -->|method| a6fed255_ca18_a93f_4bb5_715d40fd728f
  9d20ecf3_00a0_09df_a3da_dd9a84895823["where()"]
  05d108b6_b51f_ac46_de61_e5660edaf3b0 -->|method| 9d20ecf3_00a0_09df_a3da_dd9a84895823
  3b5074d2_470d_1e88_4e63_c222f0a61656["returning()"]
  05d108b6_b51f_ac46_de61_e5660edaf3b0 -->|method| 3b5074d2_470d_1e88_4e63_c222f0a61656
  8f6f92a7_8111_49ac_f1c3_dd8abac67719["getSQL()"]
  05d108b6_b51f_ac46_de61_e5660edaf3b0 -->|method| 8f6f92a7_8111_49ac_f1c3_dd8abac67719
  132ea2ec_3ea6_0ed0_b043_b9c40fc01992["toSQL()"]
  05d108b6_b51f_ac46_de61_e5660edaf3b0 -->|method| 132ea2ec_3ea6_0ed0_b043_b9c40fc01992
  b6a77973_57ea_cd48_67a3_59bcdf2fd900["_prepare()"]
  05d108b6_b51f_ac46_de61_e5660edaf3b0 -->|method| b6a77973_57ea_cd48_67a3_59bcdf2fd900
  2cfef40d_f402_fbf5_d838_f77a41227cd4["prepare()"]
  05d108b6_b51f_ac46_de61_e5660edaf3b0 -->|method| 2cfef40d_f402_fbf5_d838_f77a41227cd4
  6ef0bcc8_0f05_c746_f8fc_157ba98af19a["setToken()"]
  05d108b6_b51f_ac46_de61_e5660edaf3b0 -->|method| 6ef0bcc8_0f05_c746_f8fc_157ba98af19a
  ef3a578c_0fb3_c6cd_0aec_10afdd7c0440["getSelectedFields()"]
  05d108b6_b51f_ac46_de61_e5660edaf3b0 -->|method| ef3a578c_0fb3_c6cd_0aec_10afdd7c0440
  4bc8ed66_bbd2_9591_f23e_69c241e28036["$dynamic()"]
  05d108b6_b51f_ac46_de61_e5660edaf3b0 -->|method| 4bc8ed66_bbd2_9591_f23e_69c241e28036

Relationship Graph

Source Code

drizzle-orm/src/pg-core/query-builders/delete.ts lines 135–293

export class PgDeleteBase<
	TTable extends PgTable,
	TQueryResult extends PgQueryResultHKT,
	TSelectedFields extends ColumnsSelection | undefined = undefined,
	TReturning extends Record<string, unknown> | undefined = undefined,
	TDynamic extends boolean = false,
	// eslint-disable-next-line @typescript-eslint/no-unused-vars
	TExcludedMethods extends string = never,
> extends QueryPromise<TReturning extends undefined ? PgQueryResultKind<TQueryResult, never> : TReturning[]>
	implements
		TypedQueryBuilder<
			TSelectedFields,
			TReturning extends undefined ? PgQueryResultKind<TQueryResult, never> : TReturning[]
		>,
		RunnableQuery<TReturning extends undefined ? PgQueryResultKind<TQueryResult, never> : TReturning[], 'pg'>,
		SQLWrapper
{
	static override readonly [entityKind]: string = 'PgDelete';

	private config: PgDeleteConfig;
	protected cacheConfig?: WithCacheConfig;

	constructor(
		table: TTable,
		private session: PgSession,
		private dialect: PgDialect,
		withList?: Subquery[],
	) {
		super();
		this.config = { table, withList };
	}

	/**
	 * Adds a `where` clause to the query.
	 *
	 * Calling this method will delete only those rows that fulfill a specified condition.
	 *
	 * See docs: {@link https://orm.drizzle.team/docs/delete}
	 *
	 * @param where the `where` clause.
	 *
	 * @example
	 * You can use conditional operators and `sql function` to filter the rows to be deleted.
	 *
	 * ```ts
	 * // Delete all cars with green color
	 * await db.delete(cars).where(eq(cars.color, 'green'));
	 * // or
	 * await db.delete(cars).where(sql`${cars.color} = 'green'`)
	 * ```
	 *
	 * You can logically combine conditional operators with `and()` and `or()` operators:
	 *
	 * ```ts
	 * // Delete all BMW cars with a green color
	 * await db.delete(cars).where(and(eq(cars.color, 'green'), eq(cars.brand, 'BMW')));
	 *
	 * // Delete all cars with the green or blue color
	 * await db.delete(cars).where(or(eq(cars.color, 'green'), eq(cars.color, 'blue')));
	 * ```
	 */
	where(where: SQL | undefined): PgDeleteWithout<this, TDynamic, 'where'> {
		this.config.where = where;
		return this as any;
	}

	/**
	 * Adds a `returning` clause to the query.
	 *
	 * Calling this method will return the specified fields of the deleted rows. If no fields are specified, all fields will be returned.
	 *
	 * See docs: {@link https://orm.drizzle.team/docs/delete#delete-with-return}
	 *
	 * @example
	 * ```ts
	 * // Delete all cars with the green color and return all fields
	 * const deletedCars: Car[] = await db.delete(cars)
	 *   .where(eq(cars.color, 'green'))
	 *   .returning();
	 *
	 * // Delete all cars with the green color and return only their id and brand fields

Domain

Frequently Asked Questions

What is the PgDeleteBase class?
PgDeleteBase is a class in the drizzle-orm codebase, defined in drizzle-orm/src/pg-core/query-builders/delete.ts.
Where is PgDeleteBase defined?
PgDeleteBase is defined in drizzle-orm/src/pg-core/query-builders/delete.ts at line 135.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free