import { DataIntegrityError, } from '../errors'; import { type InternalQueryMethod, } from '../types'; import { createQueryId, } from '../utilities'; import { many, } from './many'; export const manyFirst: InternalQueryMethod = async (log, connection, clientConfigurationType, slonikSql, inheritedQueryId) => { const queryId = inheritedQueryId ?? createQueryId(); const rows = await many(log, connection, clientConfigurationType, slonikSql, queryId); if (rows.length === 0) { log.error({ queryId, }, 'DataIntegrityError'); throw new DataIntegrityError(); } const keys = Object.keys(rows[0] as Record); if (keys.length !== 1) { log.error({ queryId, }, 'DataIntegrityError'); throw new DataIntegrityError(); } const firstColumnName = keys[0]; return (rows as Array>).map((row) => { return row[firstColumnName]; }); };