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