objection
Version:
An SQL-friendly ORM for Node.js
26 lines (21 loc) • 649 B
JavaScript
;
function assertHasId(model) {
if (!model.$hasId()) {
const modelClass = model.constructor;
const ids = modelClass.getIdColumnArray().join(', ');
throw new Error(
`one of the identifier columns [${ids}] is null or undefined. Have you specified the correct identifier column for the model '${modelClass.name}' using the 'idColumn' property?`,
);
}
}
function assertIdNotUndefined(id, message) {
if (Array.isArray(id)) {
id.forEach((id) => assertIdNotUndefined(id, message));
} else if (id === undefined) {
throw Error(message);
}
}
module.exports = {
assertHasId,
assertIdNotUndefined,
};