UNPKG

kysely-mapper

Version:

Flexible Kysely-based utility for mapping between tables and objects

39 lines 1.89 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.SubsettingMappingInsertQuery = void 0; const insert_query_js_1 = require("./insert-query.js"); const compiling_insert_query_js_1 = require("./compiling-insert-query.js"); const restrict_values_js_1 = require("../lib/restrict-values.js"); /** * Mapping query for inserting rows into a database table, * inserting a specified subset of the insertable columns. */ class SubsettingMappingInsertQuery extends insert_query_js_1.MappingInsertQuery { constructor(db, qb, columnsToInsert, transforms, returnColumns) { super(db, qb, transforms, returnColumns); this.columnsToInsert = columnsToInsert; } /** * 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 insert query. */ compile() { return new compiling_insert_query_js_1.CompilingMappingInsertQuery(this.db, this.qb, this.columnsToInsert, this.transforms, this.returnColumns); } getInsertColumns() { return this.columnsToInsert; } setColumnValues(qb, objOrObjs) { if (Array.isArray(objOrObjs)) { return qb.values(objOrObjs.map((obj) => (0, restrict_values_js_1.restrictValues)(obj, this.columnsToInsert))); } return qb.values((0, restrict_values_js_1.restrictValues)(objOrObjs, this.columnsToInsert)); } } exports.SubsettingMappingInsertQuery = SubsettingMappingInsertQuery; //# sourceMappingURL=subsetting-insert-query.js.map