import type { GetColumnData } from "../../column.cjs"; import { entityKind } from "../../entity.cjs"; import type { PgDialect } from "../dialect.cjs"; import type { PgPreparedQuery, PgQueryResultHKT, PgQueryResultKind, PgSession, PreparedQueryConfig } from "../session.cjs"; import { PgTable } from "../table.cjs"; import { TypedQueryBuilder } from "../../query-builders/query-builder.cjs"; import type { AppendToNullabilityMap, AppendToResult, GetSelectTableName, GetSelectTableSelection, JoinNullability, JoinType, SelectMode, SelectResult } from "../../query-builders/select.types.cjs"; import { QueryPromise } from "../../query-promise.cjs"; import type { RunnableQuery } from "../../runnable-query.cjs"; import { type ColumnsSelection, type Query, SQL, type SQLWrapper } from "../../sql/sql.cjs"; import { Subquery } from "../../subquery.cjs"; import { Table } from "../../table.cjs"; import { type Assume, DrizzleTypeError, Equal, type NeonAuthToken, Simplify, type UpdateSet } from "../../utils.cjs"; import type { PgColumn } from "../columns/common.cjs"; import type { PgViewBase } from "../view-base.cjs"; import type { PgSelectJoinConfig, SelectedFields, SelectedFieldsOrdered, TableLikeHasEmptySelection } from "./select.types.cjs"; export interface PgUpdateConfig { where?: SQL | undefined; set: UpdateSet; table: PgTable; from?: PgTable | Subquery | PgViewBase | SQL; joins: PgSelectJoinConfig[]; returningFields?: SelectedFields; returning?: SelectedFieldsOrdered; withList?: Subquery[]; } export type PgUpdateSetSource = { [Key in keyof TTable['$inferInsert']]?: GetColumnData | SQL | PgColumn | undefined; } & {}; export declare class PgUpdateBuilder { private table; private session; private dialect; private withList?; static readonly [entityKind]: string; readonly _: { readonly table: TTable; }; constructor(table: TTable, session: PgSession, dialect: PgDialect, withList?: Subquery[] | undefined); private authToken?; setToken(token: NeonAuthToken): this; set(values: PgUpdateSetSource): PgUpdateWithout, false, 'leftJoin' | 'rightJoin' | 'innerJoin' | 'fullJoin'>; } export type PgUpdateWithout = TDynamic extends true ? T : Omit, T['_']['excludedMethods'] | K>; export type PgUpdateWithJoins = TDynamic extends true ? T : Omit, 'inner'>, [ ...T['_']['joins'], { name: GetSelectTableName; joinType: 'inner'; table: TFrom; } ], TDynamic, Exclude>, Exclude>; export type PgUpdateJoinFn = (table: TableLikeHasEmptySelection extends true ? DrizzleTypeError<"Cannot reference a data-modifying statement subquery if it doesn't contain a `returning` clause"> : TJoinedTable, on: ((updateTable: T['_']['table']['_']['columns'], from: T['_']['from'] extends PgTable ? T['_']['from']['_']['columns'] : T['_']['from'] extends Subquery | PgViewBase ? T['_']['from']['_']['selectedFields'] : never) => SQL | undefined) | SQL | undefined) => PgUpdateJoin; export type PgUpdateJoin = TDynamic extends true ? T : PgUpdateBase, TJoinType>, [ ...T['_']['joins'], { name: GetSelectTableName; joinType: TJoinType; table: TJoinedTable; } ], TDynamic, T['_']['excludedMethods']>; type Join = { name: string | undefined; joinType: JoinType; table: PgTable | Subquery | PgViewBase | SQL; }; type AccumulateToResult = TJoins extends [infer TJoin extends Join, ...infer TRest extends Join[]] ? AccumulateToResult : never, TSelectMode extends 'partial' ? TSelectMode : 'multiple'>> : TSelectedFields; export type PgUpdateReturningAll = PgUpdateWithout extends true ? T['_']['table']['_']['columns'] : Simplify & { [K in keyof T['_']['joins'] as T['_']['joins'][K]['table']['_']['name']]: T['_']['joins'][K]['table']['_']['columns']; }>, SelectResult>, 'partial', T['_']['nullabilityMap']>, T['_']['nullabilityMap'], T['_']['joins'], TDynamic, T['_']['excludedMethods']>, TDynamic, 'returning'>; export type PgUpdateReturning = PgUpdateWithout, 'partial', T['_']['nullabilityMap']>, T['_']['nullabilityMap'], T['_']['joins'], TDynamic, T['_']['excludedMethods']>, TDynamic, 'returning'>; export type PgUpdatePrepare = PgPreparedQuery : T['_']['returning'][]; }>; export type PgUpdateDynamic = PgUpdate; export type PgUpdate | undefined = Record | undefined, TNullabilityMap extends Record = Record, TJoins extends Join[] = []> = PgUpdateBase; export type AnyPgUpdate = PgUpdateBase; export interface PgUpdateBase | undefined = undefined, TNullabilityMap extends Record = Record, TJoins extends Join[] = [], TDynamic extends boolean = false, TExcludedMethods extends string = never> extends TypedQueryBuilder : TReturning[]>, QueryPromise : TReturning[]>, RunnableQuery : TReturning[], 'pg'>, SQLWrapper { readonly _: { readonly dialect: 'pg'; readonly table: TTable; readonly joins: TJoins; readonly nullabilityMap: TNullabilityMap; readonly queryResult: TQueryResult; readonly from: TFrom; readonly selectedFields: TSelectedFields; readonly returning: TReturning; readonly dynamic: TDynamic; readonly excludedMethods: TExcludedMethods; readonly result: TReturning extends undefined ? PgQueryResultKind : TReturning[]; }; } export declare class PgUpdateBase | undefined = undefined, TNullabilityMap extends Record = Record, TJoins extends Join[] = [], TDynamic extends boolean = false, TExcludedMethods extends string = never> extends QueryPromise : TReturning[]> implements RunnableQuery : TReturning[], 'pg'>, SQLWrapper { private session; private dialect; static readonly [entityKind]: string; private config; private tableName; private joinsNotNullableMap; constructor(table: TTable, set: UpdateSet, session: PgSession, dialect: PgDialect, withList?: Subquery[]); from(source: TableLikeHasEmptySelection extends true ? DrizzleTypeError<"Cannot reference a data-modifying statement subquery if it doesn't contain a `returning` clause"> : TFrom): PgUpdateWithJoins; private getTableLikeFields; private createJoin; leftJoin: PgUpdateJoinFn; rightJoin: PgUpdateJoinFn; innerJoin: PgUpdateJoinFn; fullJoin: PgUpdateJoinFn; /** * 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 * await db.update(cars).set({ color: 'red' }) * .where(eq(cars.color, 'green')); * // or * await 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 * await 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 * await db.update(cars).set({ color: 'red' }) * .where(or(eq(cars.color, 'green'), eq(cars.color, 'blue'))); * ``` */ where(where: SQL | undefined): PgUpdateWithout; /** * 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(): PgUpdateReturningAll; returning(fields: TSelectedFields): PgUpdateReturning; toSQL(): Query; prepare(name: string): PgUpdatePrepare; private authToken?; execute: ReturnType['execute']; $dynamic(): PgUpdateDynamic; } export {};