UNPKG

kysely-mapper

Version:

Flexible Kysely-based utility for mapping between tables and objects

81 lines 4.73 kB
import { Kysely, UpdateQueryBuilder, UpdateResult, Updateable } from 'kysely'; import { SelectionColumn } from '../lib/type-utils.js'; import { CountTransform, UpdateTransforms } from '../mappers/table-mapper-transforms.js'; /** * Mapping query for updating rows from a database table. */ export declare class MappingUpdateQuery<DB, TB extends keyof DB & string, QB extends UpdateQueryBuilder<DB, TB, TB, UpdateResult>, UpdatingObject, UpdateReturnColumns extends Readonly<SelectionColumn<DB, TB>[]> | ['*'], ReturnCount, UpdateReturn> { #private; readonly db: Kysely<DB>; readonly qb: QB; protected readonly transforms: Readonly<CountTransform<ReturnCount> & UpdateTransforms<DB, TB, UpdatingObject, UpdateReturnColumns, UpdateReturn>>; protected readonly returnColumns: Readonly<UpdateReturnColumns>; constructor(db: Kysely<DB>, qb: QB, transforms: Readonly<CountTransform<ReturnCount> & UpdateTransforms<DB, TB, UpdatingObject, UpdateReturnColumns, UpdateReturn>>, returnColumns: Readonly<UpdateReturnColumns>); /** * Modifies the underlying Kysely query builder. * @param factory A function that takes the current query builder and * returns a new query builder. */ modify<NextQB extends UpdateQueryBuilder<DB, TB, TB, any>>(factory: (qb: QB) => NextQB): MappingUpdateQuery<DB, TB, NextQB, UpdatingObject, UpdateReturnColumns, ReturnCount, UpdateReturn>; /** * Runs the query, returning the number of rows updated, in * the required client representation. * @param obj The object which which to update the rows. * @returns Number of rows updated, in client-requested representation. */ returnCount(obj: UpdatingObject): Promise<ReturnCount>; /** * Updates rows with the values that result from transforming the object via * `updateTransform` (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`. * @returns If `returnColumns` is not empty, returns an array containing one * object for each row updated; otherwise returns `undefined`. */ returnAll(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`. * @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(obj: UpdatingObject): Promise<UpdateReturnColumns extends [] ? void : UpdateReturn | null>; /** * Runs the query, updating rows, without returning any columns. * @param obj The object which which to update the rows. * @returns `true` if any rows were updated, `false` otherwise. */ run(obj: UpdatingObject): Promise<boolean>; /** * Returns an array of the columns to be updated, with * `['*']` indicating that all columns will be updated. * @returns An array of the columns to be updated. */ protected getUpdateColumns(): Readonly<(keyof Updateable<DB[TB]> & string)[]> | ['*']; /** * Returns a query builder for updating rows in the table and * returning values, caching the query builder for future use. * @returns A query builder for updating rows in the table and * returning values. */ protected getReturningQB(): UpdateQueryBuilder<DB, TB, TB, any>; /** * Loads the object with which to update rows. * @param qb The query builder to load the objects into. * @param obj The object with which to update rows. * @returns The query builder with the object loaded. */ protected loadUpdatingObject(qb: UpdateQueryBuilder<DB, TB, TB, UpdateResult>, obj: UpdatingObject): UpdateQueryBuilder<DB, TB, TB, UpdateResult>; /** * Sets the values of the updated columns. * @param qb The query builder to set the values into. * @param obj The object of column-value pairs to be updated. */ protected setColumnValues(qb: UpdateQueryBuilder<DB, TB, TB, UpdateResult>, obj: Updateable<DB[TB]>): UpdateQueryBuilder<DB, TB, TB, UpdateResult>; } //# sourceMappingURL=update-query.d.ts.map