Home / Class/ SingleStoreInsertBase Class — drizzle-orm Architecture

SingleStoreInsertBase Class — drizzle-orm Architecture

Architecture documentation for the SingleStoreInsertBase class in insert.ts from the drizzle-orm codebase.

Entity Profile

Dependency Diagram

graph TD
  789024c2_65e9_4316_d78e_e80becf0d8aa["SingleStoreInsertBase"]
  442ef410_0a6c_ba64_9e82_83d5b7e37c62["insert.ts"]
  789024c2_65e9_4316_d78e_e80becf0d8aa -->|defined in| 442ef410_0a6c_ba64_9e82_83d5b7e37c62
  c7bfccb4_d0d7_8db8_5908_df10e6975405["constructor()"]
  789024c2_65e9_4316_d78e_e80becf0d8aa -->|method| c7bfccb4_d0d7_8db8_5908_df10e6975405
  0d2b38e3_d926_0d3b_54dc_720ce923201b["onDuplicateKeyUpdate()"]
  789024c2_65e9_4316_d78e_e80becf0d8aa -->|method| 0d2b38e3_d926_0d3b_54dc_720ce923201b
  f0f4a455_c455_c51e_6622_b8e005325298["$returningId()"]
  789024c2_65e9_4316_d78e_e80becf0d8aa -->|method| f0f4a455_c455_c51e_6622_b8e005325298
  5c866b37_edf3_5952_e8d7_2d62f23e90d7["getSQL()"]
  789024c2_65e9_4316_d78e_e80becf0d8aa -->|method| 5c866b37_edf3_5952_e8d7_2d62f23e90d7
  0b967fef_1e6e_baff_38c4_7f097999ec0b["toSQL()"]
  789024c2_65e9_4316_d78e_e80becf0d8aa -->|method| 0b967fef_1e6e_baff_38c4_7f097999ec0b
  938c392a_5148_c49b_97be_0fbd6270560a["prepare()"]
  789024c2_65e9_4316_d78e_e80becf0d8aa -->|method| 938c392a_5148_c49b_97be_0fbd6270560a
  981812c6_4e7e_7ed5_e902_2f5e8ff1a111["$dynamic()"]
  789024c2_65e9_4316_d78e_e80becf0d8aa -->|method| 981812c6_4e7e_7ed5_e902_2f5e8ff1a111

Relationship Graph

Source Code

drizzle-orm/src/singlestore-core/query-builders/insert.ts lines 184–310

export class SingleStoreInsertBase<
	TTable extends SingleStoreTable,
	TQueryResult extends SingleStoreQueryResultHKT,
	// eslint-disable-next-line @typescript-eslint/no-unused-vars
	TPreparedQueryHKT extends PreparedQueryHKTBase,
	// eslint-disable-next-line @typescript-eslint/no-unused-vars
	TReturning extends Record<string, unknown> | undefined = undefined,
	// 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<TReturning extends undefined ? SingleStoreQueryResultKind<TQueryResult, never> : TReturning[]>
	implements
		RunnableQuery<
			TReturning extends undefined ? SingleStoreQueryResultKind<TQueryResult, never> : TReturning[],
			'singlestore'
		>,
		SQLWrapper
{
	static override readonly [entityKind]: string = 'SingleStoreInsert';

	declare protected $table: TTable;

	private config: SingleStoreInsertConfig<TTable>;

	constructor(
		table: TTable,
		values: SingleStoreInsertConfig['values'],
		ignore: boolean,
		private session: SingleStoreSession,
		private dialect: SingleStoreDialect,
	) {
		super();
		this.config = { table, values, ignore };
	}

	/**
	 * Adds an `on duplicate key update` clause to the query.
	 *
	 * Calling this method will update update the row if any unique index conflicts. MySQL will automatically determine the conflict target based on the primary key and unique indexes.
	 *
	 * See docs: {@link https://orm.drizzle.team/docs/insert#on-duplicate-key-update}
	 *
	 * @param config The `set` clause
	 *
	 * @example
	 * ```ts
	 * await db.insert(cars)
	 *   .values({ id: 1, brand: 'BMW'})
	 *   .onDuplicateKeyUpdate({ set: { brand: 'Porsche' }});
	 * ```
	 *
	 * While MySQL does not directly support doing nothing on conflict, you can perform a no-op by setting any column's value to itself and achieve the same effect:
	 *
	 * ```ts
	 * import { sql } from 'drizzle-orm';
	 *
	 * await db.insert(cars)
	 *   .values({ id: 1, brand: 'BMW' })
	 *   .onDuplicateKeyUpdate({ set: { id: sql`id` } });
	 * ```
	 */
	onDuplicateKeyUpdate(
		config: SingleStoreInsertOnDuplicateKeyUpdateConfig<this>,
	): SingleStoreInsertWithout<this, TDynamic, 'onDuplicateKeyUpdate'> {
		const setSql = this.dialect.buildUpdateSet(this.config.table, mapUpdateSet(this.config.table, config.set));
		this.config.onConflict = sql`update ${setSql}`;
		return this as any;
	}

	$returningId(): SingleStoreInsertWithout<
		SingleStoreInsertReturning<this, TDynamic>,
		TDynamic,
		'$returningId'
	> {
		const returning: SelectedFieldsOrdered = [];
		for (const [key, value] of Object.entries(this.config.table[Table.Symbol.Columns])) {
			if (value.primary) {
				returning.push({ field: value, path: [key] });
			}
		}

Domain

Frequently Asked Questions

What is the SingleStoreInsertBase class?
SingleStoreInsertBase is a class in the drizzle-orm codebase, defined in drizzle-orm/src/singlestore-core/query-builders/insert.ts.
Where is SingleStoreInsertBase defined?
SingleStoreInsertBase is defined in drizzle-orm/src/singlestore-core/query-builders/insert.ts at line 184.

Analyze Your Own Codebase

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

Try Supermodel Free