UNPKG

kysely-mapper

Version:

Flexible Kysely-based utility for mapping between tables and objects

49 lines 2.56 kB
import { AbstractTableMapper } from './abstract-table-mapper.js'; /** * Table mapper that defaults to passing through all query inputs and output * unchanged, allowing the selective overloading of transforms. * @typeParam DB Interface whose fields are table names defining tables. * @typeParam TB Name of the table. * @typeParam KeyColumns Tuple of the names of the table's key columns. * Defaults to `[]`, indicating no key columns. Supports up to 4 columns. * @typeParam SelectedColumns Columns to return from selection queries. * Defaults to `['*']`, returning all columns. May specify aliases. * @typeParam SelectedObject Type of objects returned by select queries. * @typeParam InsertedObject Type of objects inserted into the table. * @typeParam UpdatingObject Type of objects used to update rows of the table. * @typeParam Type of the count of the number of affected rows. * @typeParam InsertReturnColumns Columns to return from the table on insert * queries that return columns. `['*']` returns all columns; `[]` returns * none. May specify aliases. Defaults to `KeyColumns`. * @typeParam UpdateReturnColumns Columns to return from the table on update * queries that return columns. `['*']` returns all columns; `[]` returns * none and is the default. May specify aliases. * @typeParam InsertReturn Type returned from inserts. Defaults to an object * whose properties are the columns of `InsertReturnColumns`. * @typeParam UpdateReturn Type returned from updates. Defaults to an object * whose properties are the columns of `UpdateReturnColumns`. */ export class TableMapper extends AbstractTableMapper { /** * Returns a new table mapper that uses the provided transformations, along * with the settings of the current table mapper. * @param transforms The transforms to use. * @returns A new table mapper that uses the provided transforms. */ withTransforms(transforms) { const transformingTableMapper = new TableMapper(this.db, this.tableName, this.settings); transformingTableMapper.transforms = transforms; return transformingTableMapper; } /** * Returns a new table mapper that issues queries in the provided * transaction, using the present table mapper's configuration. * @param transaction The transaction to use. * @returns A new table mapper that issues queries in the provided * transaction. */ forTransaction(trx) { return new TableMapper(trx, this); } } //# sourceMappingURL=table-mapper.js.map