slonik
Version:
A Node.js PostgreSQL client with strict types, detailed logging and assertions.
29 lines • 1.05 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.manyFirst = void 0;
const many_1 = require("./many");
const errors_1 = require("@slonik/errors");
const utilities_1 = require("@slonik/utilities");
const manyFirst = async (log, connection, clientConfigurationType, query, inheritedQueryId) => {
const queryId = inheritedQueryId ?? (0, utilities_1.generateUid)();
const rows = await (0, many_1.many)(log, connection, clientConfigurationType, query, queryId);
if (rows.length === 0) {
log.error({
queryId,
}, 'DataIntegrityError');
throw new errors_1.DataIntegrityError(query);
}
const keys = Object.keys(rows[0]);
if (keys.length !== 1) {
log.error({
queryId,
}, 'DataIntegrityError');
throw new errors_1.DataIntegrityError(query);
}
const firstColumnName = keys[0];
return rows.map((row) => {
return row[firstColumnName];
});
};
exports.manyFirst = manyFirst;
//# sourceMappingURL=manyFirst.js.map
;