Home / Class/ MySqlUpdateBase Class — drizzle-orm Architecture

MySqlUpdateBase Class — drizzle-orm Architecture

Architecture documentation for the MySqlUpdateBase class in update.ts from the drizzle-orm codebase.

Entity Profile

Dependency Diagram

graph TD
  ce2e790a_b4fb_fe3b_0e1e_b49965e041b1["MySqlUpdateBase"]
  87ec4c19_e662_b455_8a6b_c6b8ac85ec0e["update.ts"]
  ce2e790a_b4fb_fe3b_0e1e_b49965e041b1 -->|defined in| 87ec4c19_e662_b455_8a6b_c6b8ac85ec0e
  e53171da_9529_1f6b_7827_fc6ea8cbe7c6["constructor()"]
  ce2e790a_b4fb_fe3b_0e1e_b49965e041b1 -->|method| e53171da_9529_1f6b_7827_fc6ea8cbe7c6
  32f6db90_c7c3_e7ea_86fb_ba4a3f49db00["where()"]
  ce2e790a_b4fb_fe3b_0e1e_b49965e041b1 -->|method| 32f6db90_c7c3_e7ea_86fb_ba4a3f49db00
  8d2025a2_91fd_8c71_65ee_c3d9c29e0946["orderBy()"]
  ce2e790a_b4fb_fe3b_0e1e_b49965e041b1 -->|method| 8d2025a2_91fd_8c71_65ee_c3d9c29e0946
  d882c9db_e0c2_502d_d6c7_ec66eb50b070["limit()"]
  ce2e790a_b4fb_fe3b_0e1e_b49965e041b1 -->|method| d882c9db_e0c2_502d_d6c7_ec66eb50b070
  a36e5060_2daa_db6e_ec01_add82b598440["getSQL()"]
  ce2e790a_b4fb_fe3b_0e1e_b49965e041b1 -->|method| a36e5060_2daa_db6e_ec01_add82b598440
  f7f98834_d144_dace_526d_6198a6a34229["toSQL()"]
  ce2e790a_b4fb_fe3b_0e1e_b49965e041b1 -->|method| f7f98834_d144_dace_526d_6198a6a34229
  57312a91_d537_77ec_f688_72761a0b8d77["prepare()"]
  ce2e790a_b4fb_fe3b_0e1e_b49965e041b1 -->|method| 57312a91_d537_77ec_f688_72761a0b8d77
  0025c0a7_3f06_5d78_598e_db356fb27f9e["$dynamic()"]
  ce2e790a_b4fb_fe3b_0e1e_b49965e041b1 -->|method| 0025c0a7_3f06_5d78_598e_db356fb27f9e

Relationship Graph

Source Code

drizzle-orm/src/mysql-core/query-builders/update.ts lines 121–257

export class MySqlUpdateBase<
	TTable extends MySqlTable,
	TQueryResult extends MySqlQueryResultHKT,
	// eslint-disable-next-line @typescript-eslint/no-unused-vars
	TPreparedQueryHKT extends PreparedQueryHKTBase,
	// eslint-disable-next-line @typescript-eslint/no-unused-vars
	TDynamic extends boolean = false,
	// eslint-disable-next-line @typescript-eslint/no-unused-vars
	TExcludedMethods extends string = never,
> extends QueryPromise<MySqlQueryResultKind<TQueryResult, never>> implements SQLWrapper {
	static override readonly [entityKind]: string = 'MySqlUpdate';

	private config: MySqlUpdateConfig;
	protected cacheConfig?: WithCacheConfig;

	constructor(
		table: TTable,
		set: UpdateSet,
		private session: MySqlSession,
		private dialect: MySqlDialect,
		withList?: Subquery[],
	) {
		super();
		this.config = { set, table, withList };
	}

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

	orderBy(
		builder: (updateTable: TTable) => ValueOrArray<MySqlColumn | SQL | SQL.Aliased>,
	): MySqlUpdateWithout<this, TDynamic, 'orderBy'>;
	orderBy(...columns: (MySqlColumn | SQL | SQL.Aliased)[]): MySqlUpdateWithout<this, TDynamic, 'orderBy'>;
	orderBy(
		...columns:
			| [(updateTable: TTable) => ValueOrArray<MySqlColumn | SQL | SQL.Aliased>]
			| (MySqlColumn | SQL | SQL.Aliased)[]
	): MySqlUpdateWithout<this, TDynamic, 'orderBy'> {
		if (typeof columns[0] === 'function') {
			const orderBy = columns[0](
				new Proxy(
					this.config.table[Table.Symbol.Columns],
					new SelectionProxyHandler({ sqlAliasedBehavior: 'alias', sqlBehavior: 'sql' }),
				) as any,
			);

Domain

Frequently Asked Questions

What is the MySqlUpdateBase class?
MySqlUpdateBase is a class in the drizzle-orm codebase, defined in drizzle-orm/src/mysql-core/query-builders/update.ts.
Where is MySqlUpdateBase defined?
MySqlUpdateBase is defined in drizzle-orm/src/mysql-core/query-builders/update.ts at line 121.

Analyze Your Own Codebase

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

Try Supermodel Free