import type { GetColumnData } from "../../column.cjs"; import { entityKind } from "../../entity.cjs"; import type { SelectResultFields } from "../../query-builders/select.types.cjs"; import { QueryPromise } from "../../query-promise.cjs"; import type { RunnableQuery } from "../../runnable-query.cjs"; import type { Placeholder, Query, SQL, SQLWrapper } from "../../sql/sql.cjs"; import type { SQLiteDialect } from "../dialect.cjs"; import type { SQLitePreparedQuery, SQLiteSession } from "../session.cjs"; import { SQLiteTable } from "../table.cjs"; import { Subquery } from "../../subquery.cjs"; import { type DrizzleTypeError, type UpdateSet, type ValueOrArray } from "../../utils.cjs"; import type { SQLiteColumn } from "../columns/common.cjs"; import { SQLiteViewBase } from "../view-base.cjs"; import type { SelectedFields, SelectedFieldsOrdered, SQLiteSelectJoinConfig } from "./select.types.cjs"; export interface SQLiteUpdateConfig { where?: SQL | undefined; limit?: number | Placeholder; orderBy?: (SQLiteColumn | SQL | SQL.Aliased)[]; set: UpdateSet; table: SQLiteTable; from?: SQLiteTable | Subquery | SQLiteViewBase | SQL; joins: SQLiteSelectJoinConfig[]; returning?: SelectedFieldsOrdered; withList?: Subquery[]; } export type SQLiteUpdateSetSource = { [Key in keyof TTable['$inferInsert']]?: GetColumnData | SQL | SQLiteColumn | undefined; } & {}; export declare class SQLiteUpdateBuilder { protected table: TTable; protected session: SQLiteSession; protected dialect: SQLiteDialect; private withList?; static readonly [entityKind]: string; readonly _: { readonly table: TTable; }; constructor(table: TTable, session: SQLiteSession, dialect: SQLiteDialect, withList?: Subquery[] | undefined); set(values: SQLiteUpdateSetSource): SQLiteUpdateWithout, false, 'leftJoin' | 'rightJoin' | 'innerJoin' | 'fullJoin'>; } export type SQLiteUpdateWithout = TDynamic extends true ? T : Omit, T['_']['excludedMethods'] | K>; export type SQLiteUpdateWithJoins = TDynamic extends true ? T : Omit>, Exclude>; export type SQLiteUpdateReturningAll = SQLiteUpdateWithout, TDynamic, 'returning'>; export type SQLiteUpdateReturning = SQLiteUpdateWithout, TDynamic, T['_']['excludedMethods']>, TDynamic, 'returning'>; export type SQLiteUpdateExecute = T['_']['returning'] extends undefined ? T['_']['runResult'] : T['_']['returning'][]; export type SQLiteUpdatePrepare = SQLitePreparedQuery<{ type: T['_']['resultType']; run: T['_']['runResult']; all: T['_']['returning'] extends undefined ? DrizzleTypeError<'.all() cannot be used without .returning()'> : T['_']['returning'][]; get: T['_']['returning'] extends undefined ? DrizzleTypeError<'.get() cannot be used without .returning()'> : T['_']['returning']; values: T['_']['returning'] extends undefined ? DrizzleTypeError<'.values() cannot be used without .returning()'> : any[][]; execute: SQLiteUpdateExecute; }>; export type SQLiteUpdateJoinFn = (table: TJoinedTable, on: ((updateTable: T['_']['table']['_']['columns'], from: T['_']['from'] extends SQLiteTable ? T['_']['from']['_']['columns'] : T['_']['from'] extends Subquery | SQLiteViewBase ? T['_']['from']['_']['selectedFields'] : never) => SQL | undefined) | SQL | undefined) => T; export type SQLiteUpdateDynamic = SQLiteUpdate; export type SQLiteUpdate | undefined = Record | undefined> = SQLiteUpdateBase; export type AnySQLiteUpdate = SQLiteUpdateBase; export interface SQLiteUpdateBase extends SQLWrapper, QueryPromise { readonly _: { readonly dialect: 'sqlite'; readonly table: TTable; readonly resultType: TResultType; readonly runResult: TRunResult; readonly from: TFrom; readonly returning: TReturning; readonly dynamic: TDynamic; readonly excludedMethods: TExcludedMethods; readonly result: TReturning extends undefined ? TRunResult : TReturning[]; }; } export declare class SQLiteUpdateBase extends QueryPromise implements RunnableQuery, SQLWrapper { private session; private dialect; static readonly [entityKind]: string; constructor(table: TTable, set: UpdateSet, session: SQLiteSession, dialect: SQLiteDialect, withList?: Subquery[]); from(source: TFrom): SQLiteUpdateWithJoins; private createJoin; leftJoin: SQLiteUpdateJoinFn; rightJoin: SQLiteUpdateJoinFn; innerJoin: SQLiteUpdateJoinFn; fullJoin: SQLiteUpdateJoinFn; /** * 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): SQLiteUpdateWithout; orderBy(builder: (updateTable: TTable) => ValueOrArray): SQLiteUpdateWithout; orderBy(...columns: (SQLiteColumn | SQL | SQL.Aliased)[]): SQLiteUpdateWithout; limit(limit: number | Placeholder): SQLiteUpdateWithout; /** * Adds a `returning` clause to the query. * * Calling this method will return the specified fields of the updated rows. If no fields are specified, all fields will be returned. * * See docs: {@link https://orm.drizzle.team/docs/update#update-with-returning} * * @example * ```ts * // Update all cars with the green color and return all fields * const updatedCars: Car[] = await db.update(cars) * .set({ color: 'red' }) * .where(eq(cars.color, 'green')) * .returning(); * * // Update all cars with the green color and return only their id and brand fields * const updatedCarsIdsAndBrands: { id: number, brand: string }[] = await db.update(cars) * .set({ color: 'red' }) * .where(eq(cars.color, 'green')) * .returning({ id: cars.id, brand: cars.brand }); * ``` */ returning(): SQLiteUpdateReturningAll; returning(fields: TSelectedFields): SQLiteUpdateReturning; toSQL(): Query; prepare(): SQLiteUpdatePrepare; run: ReturnType['run']; all: ReturnType['all']; get: ReturnType['get']; values: ReturnType['values']; execute(): Promise>; $dynamic(): SQLiteUpdateDynamic; }