UNPKG

kysely-mapper

Version:

Flexible Kysely-based utility for mapping between tables and objects

66 lines 4.44 kB
import { Kysely, UpdateQueryBuilder, UpdateResult, Updateable } from 'kysely'; import { ParametersObject } from 'kysely-params'; import { SelectionColumn } from '../lib/type-utils.js'; import { CompilingValuesQuery } from './compiling-values-query.js'; import { CountTransform, UpdateTransforms } from '../mappers/table-mapper-transforms.js'; /** * Compiling mapping query for updating rows in a database table. */ export declare class CompilingMappingUpdateQuery<DB, TB extends keyof DB & string, QB extends UpdateQueryBuilder<DB, TB, TB, UpdateResult>, UpdatingObject, UpdateReturnColumns extends Readonly<SelectionColumn<DB, TB>[]> | ['*'], ReturnCount, UpdateReturn, Parameters extends ParametersObject<Parameters>> extends CompilingValuesQuery<DB, TB, QB, UpdateReturnColumns, Parameters, Updateable<DB[TB]>> { protected readonly columnsToUpdate: Readonly<(keyof Updateable<DB[TB]> & string)[]>; protected readonly transforms: Readonly<CountTransform<ReturnCount> & UpdateTransforms<DB, TB, UpdatingObject, UpdateReturnColumns, UpdateReturn>>; constructor(db: Kysely<DB>, qb: QB, columnsToUpdate: Readonly<(keyof Updateable<DB[TB]> & string)[]>, transforms: Readonly<CountTransform<ReturnCount> & UpdateTransforms<DB, TB, UpdatingObject, UpdateReturnColumns, UpdateReturn>>, returnColumns: Readonly<UpdateReturnColumns>); /** * Runs the query, returning the number of rows updated, in the required * client representation. Accepts values for any parameters embedded in * the query. * * On the first execution, compiles and discards the underlying Kysely * query builder. Subsequent executions reuse the compiled query. * @param obj The object which which to update the rows. * @returns Number of rows updated, in client-requested representation. */ returnCount(params: Parameters, obj: UpdatingObject): Promise<ReturnCount>; /** * Updates rows with the values that result from transforming the object via * `insertTransform` (if defined). For each row updated, retrieves the * columns specified in `returnColumns` (if defined), returning them to the * caller as an `UpdateReturn`, after transformation by any provided * `updateReturnTransform`. If `returnColumns` is empty, returns `undefined`. * Accepts values for any parameters embedded in the query. * * On the first execution, compiles and discards the underlying Kysely * query builder. Subsequent executions reuse the compiled query. * @returns If `returnColumns` is not empty, returns an array containing one * object for each row updated; otherwise returns `undefined`. */ returnAll(params: Parameters, obj: UpdatingObject): Promise<UpdateReturnColumns extends [] ? void : UpdateReturn[]>; /** * Updates rows with the values that result from transforming the object via * `updateTransform` (if defined). For the first row updated, retrieves the * columns specified in `returnColumns` (if defined), returning them to the * caller as an `UpdateReturn`, after transformation by any provided * `updateReturnTransform`. If `returnColumns` is empty, returns `undefined`. * Accepts values for any parameters embedded in the query. * * On the first execution, compiles and discards the underlying Kysely * query builder. Subsequent executions reuse the compiled query. * @returns If `returnColumns` is empty, returns `undefined`. Otherwise, * returns the first object if at least one row was updated, or `null` if * no rows were updated. */ returnOne(params: Parameters, obj: UpdatingObject): Promise<UpdateReturnColumns extends [] ? void : UpdateReturn | null>; /** * Runs the query, updating rows, without returning any columns. Accepts * values for any parameters embedded in the query. * * On the first execution, compiles and discards the underlying Kysely * query builder. Subsequent executions reuse the compiled query. * @param obj The object which which to update the rows. * @returns `true` if any rows were updated, `false` otherwise. */ run(params: Parameters, obj: UpdatingObject): Promise<boolean>; protected applyUpdateTransform(obj: UpdatingObject): Updateable<DB[TB]>; protected applyUpdateReturnTransform(source: UpdatingObject, returns: any): any; } //# sourceMappingURL=compiling-update-query.d.ts.map