import type { WithCacheConfig } from "../../cache/core/types.js"; import { entityKind } from "../../entity.js"; import type { MySqlDialect } from "../dialect.js"; import type { AnyMySqlQueryResultHKT, MySqlPreparedQueryConfig, MySqlQueryResultHKT, MySqlQueryResultKind, MySqlSession, PreparedQueryHKTBase, PreparedQueryKind } from "../session.js"; import type { MySqlTable } from "../table.js"; import type { TypedQueryBuilder } from "../../query-builders/query-builder.js"; import { QueryPromise } from "../../query-promise.js"; import type { RunnableQuery } from "../../runnable-query.js"; import type { Placeholder, Query, SQLWrapper } from "../../sql/sql.js"; import { Param, SQL } from "../../sql/sql.js"; import type { InferModelFromColumns } from "../../table.js"; import type { AnyMySqlColumn } from "../columns/common.js"; import { QueryBuilder } from "./query-builder.js"; import type { SelectedFieldsOrdered } from "./select.types.js"; import type { MySqlUpdateSetSource } from "./update.js"; export interface MySqlInsertConfig { table: TTable; values: Record[] | MySqlInsertSelectQueryBuilder | SQL; ignore: boolean; onConflict?: SQL; returning?: SelectedFieldsOrdered; select?: boolean; } export type AnyMySqlInsertConfig = MySqlInsertConfig; export type MySqlInsertValue = { [Key in keyof TTable['$inferInsert']]: TTable['$inferInsert'][Key] | SQL | Placeholder; } & {}; export type MySqlInsertSelectQueryBuilder = TypedQueryBuilder<{ [K in keyof TTable['$inferInsert']]: AnyMySqlColumn | SQL | SQL.Aliased | TTable['$inferInsert'][K]; }>; export declare class MySqlInsertBuilder { private table; private session; private dialect; static readonly [entityKind]: string; private shouldIgnore; constructor(table: TTable, session: MySqlSession, dialect: MySqlDialect); ignore(): this; values(value: MySqlInsertValue): MySqlInsertBase; values(values: MySqlInsertValue[]): MySqlInsertBase; select(selectQuery: (qb: QueryBuilder) => MySqlInsertSelectQueryBuilder): MySqlInsertBase; select(selectQuery: (qb: QueryBuilder) => SQL): MySqlInsertBase; select(selectQuery: SQL): MySqlInsertBase; select(selectQuery: MySqlInsertSelectQueryBuilder): MySqlInsertBase; } export type MySqlInsertWithout = TDynamic extends true ? T : Omit, T['_']['excludedMethods'] | K>; export type MySqlInsertDynamic = MySqlInsert; export type MySqlInsertPrepare | undefined = undefined> = PreparedQueryKind : TReturning[]; iterator: never; }, true>; export type MySqlInsertOnDuplicateKeyUpdateConfig = { set: MySqlUpdateSetSource; }; export type MySqlInsert | undefined = Record | undefined> = MySqlInsertBase; export type MySqlInsertReturning = MySqlInsertBase>, TDynamic, T['_']['excludedMethods'] | '$returning'>; export type AnyMySqlInsert = MySqlInsertBase; export interface MySqlInsertBase | undefined = undefined, TDynamic extends boolean = false, TExcludedMethods extends string = never> extends QueryPromise : TReturning[]>, RunnableQuery : TReturning[], 'mysql'>, SQLWrapper { readonly _: { readonly dialect: 'mysql'; readonly table: TTable; readonly queryResult: TQueryResult; readonly preparedQueryHKT: TPreparedQueryHKT; readonly dynamic: TDynamic; readonly excludedMethods: TExcludedMethods; readonly returning: TReturning; readonly result: TReturning extends undefined ? MySqlQueryResultKind : TReturning[]; }; } export type PrimaryKeyKeys> = { [K in keyof T]: T[K]['_']['isPrimaryKey'] extends true ? T[K]['_']['isAutoincrement'] extends true ? K : T[K]['_']['hasRuntimeDefault'] extends true ? T[K]['_']['isPrimaryKey'] extends true ? K : never : never : T[K]['_']['hasRuntimeDefault'] extends true ? T[K]['_']['isPrimaryKey'] extends true ? K : never : never; }[keyof T]; export type GetPrimarySerialOrDefaultKeys> = { [K in PrimaryKeyKeys]: T[K]; }; export declare class MySqlInsertBase | undefined = undefined, TDynamic extends boolean = false, TExcludedMethods extends string = never> extends QueryPromise : TReturning[]> implements RunnableQuery : TReturning[], 'mysql'>, SQLWrapper { private session; private dialect; static readonly [entityKind]: string; protected $table: TTable; private config; protected cacheConfig?: WithCacheConfig; constructor(table: TTable, values: MySqlInsertConfig['values'], ignore: boolean, session: MySqlSession, dialect: MySqlDialect, select?: boolean); /** * Adds an `on duplicate key update` clause to the query. * * Calling this method will 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: MySqlInsertOnDuplicateKeyUpdateConfig): MySqlInsertWithout; $returningId(): MySqlInsertWithout, TDynamic, '$returningId'>; toSQL(): Query; prepare(): MySqlInsertPrepare; execute: ReturnType['execute']; private createIterator; iterator: ReturnType["iterator"]; $dynamic(): MySqlInsertDynamic; }