kysely-mapper
Version:
Flexible Kysely-based utility for mapping between tables and objects
32 lines • 1.44 kB
JavaScript
import { MappingUpdateQuery } from './update-query.js';
import { CompilingMappingUpdateQuery } from './compiling-update-query.js';
import { restrictValues } from '../lib/restrict-values.js';
/**
* Mapping query for updating rows into a database table,
* updating a specified subset of the updateable columns.
*/
export class SubsettingMappingUpdateQuery extends MappingUpdateQuery {
constructor(db, qb, columnsToUpdate, transforms, returnColumns) {
super(db, qb, transforms, returnColumns);
this.columnsToUpdate = columnsToUpdate;
}
/**
* Returns a compiling query that can be executed multiple times with
* different parameters (if any parameters were provided), but which only
* compiles the underlying Kysely query builder on the first execution.
* Frees the query builder on the first execution to reduce memory usage.
* @typeParam Parameters Record characterizing the parameter names and
* types that were previously embedded in the query, if any.
* @returns A compiling update query.
*/
compile() {
return new CompilingMappingUpdateQuery(this.db, this.qb, this.columnsToUpdate, this.transforms, this.returnColumns);
}
getUpdateColumns() {
return this.columnsToUpdate;
}
setColumnValues(qb, obj) {
return qb.set(restrictValues(obj, this.columnsToUpdate));
}
}
//# sourceMappingURL=subsetting-update-query.js.map