kysely-mapper
Version:
Flexible Kysely-based utility for mapping between tables and objects
71 lines • 4.2 kB
JavaScript
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
if (kind === "m") throw new TypeError("Private method is not writable");
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
};
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
};
var _CompilingMappingDeleteQuery_parameterizedQuery;
import { ParameterizedQuery } from 'kysely-params';
/**
* Compiling mapping query for deleting rows from a database table.
*/
export class CompilingMappingDeleteQuery {
constructor(db, qb, transforms) {
this.db = db;
this.qb = qb;
this.transforms = transforms;
_CompilingMappingDeleteQuery_parameterizedQuery.set(this, void 0);
__classPrivateFieldSet(this, _CompilingMappingDeleteQuery_parameterizedQuery, new ParameterizedQuery(qb), "f");
}
/**
* Runs the query, returning the number of rows deleted, converted to
* 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 params Record characterizing the parameter names and types.
* Pass in `{}` if the query has no parameters.
* @returns Number of rows deleted, in client-requested representation.
*/
returnCount(params) {
return __awaiter(this, void 0, void 0, function* () {
const result = yield __classPrivateFieldGet(this, _CompilingMappingDeleteQuery_parameterizedQuery, "f").execute(this.db, params);
return this.transforms.countTransform === undefined
? result.numAffectedRows
: this.transforms.countTransform(result.numAffectedRows);
});
}
/**
* Runs the query, deleting the indicated rows, returning nothing.
* 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 params Record characterizing the parameter names and types.
* Pass in `{}` if the query has no parameters.
* @returns `true` if any rows were deleted, `false` otherwise.
*/
run(params) {
return __awaiter(this, void 0, void 0, function* () {
const results = yield __classPrivateFieldGet(this, _CompilingMappingDeleteQuery_parameterizedQuery, "f").execute(this.db, params);
return results.numAffectedRows !== BigInt(0);
});
}
}
_CompilingMappingDeleteQuery_parameterizedQuery = new WeakMap();
//# sourceMappingURL=compiling-delete-query.js.map