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

withUpdate() — drizzle-orm Function Reference

Architecture documentation for the withUpdate() function in index.ts from the drizzle-orm codebase.

Entity Profile

Dependency Diagram

graph TD
  eccbec85_b166_40d6_e736_884802e96754["withUpdate()"]
  34f01008_7c45_3804_1fad_b8b59cd8a413["MyDurableObject"]
  eccbec85_b166_40d6_e736_884802e96754 -->|defined in| 34f01008_7c45_3804_1fad_b8b59cd8a413
  7c7acbfe_6328_c8df_feba_552ee62a84d9["default.fetch()"]
  7c7acbfe_6328_c8df_feba_552ee62a84d9 -->|calls| eccbec85_b166_40d6_e736_884802e96754
  b19b108f_def7_3a32_99a3_c8be51ce2fbf["beforeEach()"]
  eccbec85_b166_40d6_e736_884802e96754 -->|calls| b19b108f_def7_3a32_99a3_c8be51ce2fbf
  style eccbec85_b166_40d6_e736_884802e96754 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

integration-tests/tests/sqlite/durable-objects/index.ts lines 1580–1626

	async withUpdate(): Promise<void> {
		try {
			await this.beforeEach();
			const products = sqliteTable('products', {
				id: integer('id').primaryKey(),
				price: numeric('price').notNull(),
				cheap: integer('cheap', { mode: 'boolean' }).notNull().default(false),
			});

			this.db.run(sql`drop table if exists ${products}`);
			this.db.run(sql`
				create table ${products} (
					id integer primary key,
					price numeric not null,
					cheap integer not null default 0
				)
			`);

			await this.db
				.insert(products)
				.values([{ price: '10.99' }, { price: '25.85' }, { price: '32.99' }, { price: '2.50' }, { price: '4.59' }]);

			const averagePrice = this.db.$with('average_price').as(
				this.db
					.select({
						value: sql`avg(${products.price})`.as('value'),
					})
					.from(products),
			);

			const result = await this.db
				.with(averagePrice)
				.update(products)
				.set({
					cheap: true,
				})
				.where(lt(products.price, sql`(select * from ${averagePrice})`))
				.returning({
					id: products.id,
				});

			expect(result).deep.equal([{ id: 1 }, { id: 4 }, { id: 5 }]);
		} catch (error: any) {
			console.error(error);
			throw new Error(`withUpdate error`);
		}
	}

Domain

Subdomains

Calls

Called By

Frequently Asked Questions

What does withUpdate() do?
withUpdate() is a function in the drizzle-orm codebase, defined in integration-tests/tests/sqlite/durable-objects/index.ts.
Where is withUpdate() defined?
withUpdate() is defined in integration-tests/tests/sqlite/durable-objects/index.ts at line 1580.
What does withUpdate() call?
withUpdate() calls 1 function(s): beforeEach.
What calls withUpdate()?
withUpdate() is called by 1 function(s): default.fetch.

Analyze Your Own Codebase

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

Try Supermodel Free