import type { GetColumnData } from "../../column.cjs"; import { entityKind } from "../../entity.cjs"; import type { GelDialect } from "../dialect.cjs"; import type { GelPreparedQuery, GelQueryResultHKT, GelQueryResultKind, GelSession, PreparedQueryConfig } from "../session.cjs"; import { GelTable } from "../table.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, type NeonAuthToken, type UpdateSet } from "../../utils.cjs"; import type { GelColumn } from "../columns/common.cjs"; import type { GelViewBase } from "../view-base.cjs"; import type { GelSelectJoinConfig, SelectedFields, SelectedFieldsOrdered } from "./select.types.cjs"; export interface GelUpdateConfig { where?: SQL | undefined; set: UpdateSet; table: GelTable; from?: GelTable | Subquery | GelViewBase | SQL; joins: GelSelectJoinConfig[]; returning?: SelectedFieldsOrdered; withList?: Subquery[]; } export type GelUpdateSetSource = { [Key in keyof TTable['$inferInsert']]?: GetColumnData | SQL | GelColumn; } & {}; export declare class GelUpdateBuilder { private table; private session; private dialect; private withList?; static readonly [entityKind]: string; readonly _: { readonly table: TTable; }; constructor(table: TTable, session: GelSession, dialect: GelDialect, withList?: Subquery[] | undefined); private authToken?; setToken(token: NeonAuthToken): this; set(values: GelUpdateSetSource): GelUpdateWithout, false, 'leftJoin' | 'rightJoin' | 'innerJoin' | 'fullJoin'>; } export type GelUpdateWithout = TDynamic extends true ? T : Omit, T['_']['excludedMethods'] | K>; export type GelUpdateWithJoins = TDynamic extends true ? T : Omit, 'inner'>, [ ...T['_']['joins'], { name: GetSelectTableName; joinType: 'inner'; table: TFrom; } ], TDynamic, Exclude>, Exclude>; export type GelUpdateJoinFn = (table: TJoinedTable, on: ((updateTable: T['_']['table']['_']['columns'], from: T['_']['from'] extends GelTable ? T['_']['from']['_']['columns'] : T['_']['from'] extends Subquery | GelViewBase ? T['_']['from']['_']['selectedFields'] : never) => SQL | undefined) | SQL | undefined) => GelUpdateJoin; export type GelUpdateJoin = TDynamic extends true ? T : GelUpdateBase, TJoinType>, [ ...T['_']['joins'], { name: GetSelectTableName; joinType: TJoinType; table: TJoinedTable; } ], TDynamic, T['_']['excludedMethods']>; type Join = { name: string | undefined; joinType: JoinType; table: GelTable | Subquery | GelViewBase | SQL; }; type AccumulateToResult = TJoins extends [infer TJoin extends Join, ...infer TRest extends Join[]] ? AccumulateToResult : never, TSelectMode extends 'partial' ? TSelectMode : 'multiple'>> : TSelectedFields; export type GelUpdateReturningAll = GelUpdateWithout>, 'partial', T['_']['nullabilityMap']>, T['_']['nullabilityMap'], T['_']['joins'], TDynamic, T['_']['excludedMethods']>, TDynamic, 'returning'>; export type GelUpdateReturning = GelUpdateWithout, 'partial', T['_']['nullabilityMap']>, T['_']['nullabilityMap'], T['_']['joins'], TDynamic, T['_']['excludedMethods']>, TDynamic, 'returning'>; export type GelUpdatePrepare = GelPreparedQuery : T['_']['returning'][]; }>; export type GelUpdateDynamic = GelUpdate; export type GelUpdate | undefined = Record | undefined, TNullabilityMap extends Record = Record, TJoins extends Join[] = []> = GelUpdateBase; export type AnyGelUpdate = GelUpdateBase; export interface GelUpdateBase | undefined = undefined, TNullabilityMap extends Record = Record, TJoins extends Join[] = [], TDynamic extends boolean = false, TExcludedMethods extends string = never> extends QueryPromise : TReturning[]>, RunnableQuery : TReturning[], 'gel'>, SQLWrapper { readonly _: { readonly dialect: 'gel'; readonly table: TTable; readonly joins: TJoins; readonly nullabilityMap: TNullabilityMap; readonly queryResult: TQueryResult; readonly from: TFrom; readonly returning: TReturning; readonly dynamic: TDynamic; readonly excludedMethods: TExcludedMethods; readonly result: TReturning extends undefined ? GelQueryResultKind : TReturning[]; }; } export declare class GelUpdateBase | undefined = undefined, TNullabilityMap extends Record = Record, TJoins extends Join[] = [], TDynamic extends boolean = false, TExcludedMethods extends string = never> extends QueryPromise : TReturning[]> implements RunnableQuery : TReturning[], 'gel'>, SQLWrapper { private session; private dialect; static readonly [entityKind]: string; private config; private tableName; private joinsNotNullableMap; constructor(table: TTable, set: UpdateSet, session: GelSession, dialect: GelDialect, withList?: Subquery[]); from(source: TFrom): GelUpdateWithJoins; private getTableLikeFields; private createJoin; leftJoin: GelUpdateJoinFn; rightJoin: GelUpdateJoinFn; innerJoin: GelUpdateJoinFn; fullJoin: GelUpdateJoinFn; /** * 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): GelUpdateWithout; /** * 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(): GelUpdateReturningAll; returning(fields: TSelectedFields): GelUpdateReturning; toSQL(): Query; prepare(name: string): GelUpdatePrepare; execute: ReturnType['execute']; $dynamic(): GelUpdateDynamic; } export {};