Skip to content

Commit

Permalink
fix(utils/parseResponse): use nullish coalescing operator
Browse files Browse the repository at this point in the history
  • Loading branch information
thelindat committed Aug 9, 2024
1 parent 22be4b1 commit bb6fea7
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/utils/parseResponse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ import type { QueryResponse, QueryType } from '../types';
export const parseResponse = (type: QueryType, result: QueryResponse): any => {
switch (type) {
case 'insert':
return (result as ResultSetHeader)?.insertId || null;
return (result as ResultSetHeader)?.insertId ?? null;

case 'update':
return (result as ResultSetHeader)?.affectedRows || null;
return (result as ResultSetHeader)?.affectedRows ?? null;

case 'single':
return (result as RowDataPacket[])?.[0] || null;
return (result as RowDataPacket[])?.[0] ?? null;

case 'scalar':
const row = (result as RowDataPacket[])?.[0];
return (row && Object.values(row)[0]) || null;
return (row && Object.values(row)[0]) ?? null;

default:
return result || null;
return result ?? null;
}
};

0 comments on commit bb6fea7

Please sign in to comment.