Home / Function/ onConflictDoUpdate() — drizzle-orm Function Reference

onConflictDoUpdate() — drizzle-orm Function Reference

Architecture documentation for the onConflictDoUpdate() function in insert.ts from the drizzle-orm codebase.

Entity Profile

Dependency Diagram

graph TD
  8397b2ec_5b63_5b3f_bbac_b94f8833e83e["onConflictDoUpdate()"]
  fd9d3b22_d4f5_65bb_f267_7230f9181031["SQLiteInsertBase"]
  8397b2ec_5b63_5b3f_bbac_b94f8833e83e -->|defined in| fd9d3b22_d4f5_65bb_f267_7230f9181031
  style 8397b2ec_5b63_5b3f_bbac_b94f8833e83e fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

drizzle-orm/src/sqlite-core/query-builders/insert.ts lines 348–366

	onConflictDoUpdate(config: SQLiteInsertOnConflictDoUpdateConfig<this>): this {
		if (config.where && (config.targetWhere || config.setWhere)) {
			throw new Error(
				'You cannot use both "where" and "targetWhere"/"setWhere" at the same time - "where" is deprecated, use "targetWhere" or "setWhere" instead.',
			);
		}

		if (!this.config.onConflict) this.config.onConflict = [];

		const whereSql = config.where ? sql` where ${config.where}` : undefined;
		const targetWhereSql = config.targetWhere ? sql` where ${config.targetWhere}` : undefined;
		const setWhereSql = config.setWhere ? sql` where ${config.setWhere}` : undefined;
		const targetSql = Array.isArray(config.target) ? sql`${config.target}` : sql`${[config.target]}`;
		const setSql = this.dialect.buildUpdateSet(this.config.table, mapUpdateSet(this.config.table, config.set));
		this.config.onConflict.push(
			sql` on conflict ${targetSql}${targetWhereSql} do update set ${setSql}${whereSql}${setWhereSql}`,
		);
		return this;
	}

Domain

Subdomains

Frequently Asked Questions

What does onConflictDoUpdate() do?
onConflictDoUpdate() is a function in the drizzle-orm codebase, defined in drizzle-orm/src/sqlite-core/query-builders/insert.ts.
Where is onConflictDoUpdate() defined?
onConflictDoUpdate() is defined in drizzle-orm/src/sqlite-core/query-builders/insert.ts at line 348.

Analyze Your Own Codebase

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

Try Supermodel Free