mirror of
https://github.com/darksaid98/oxmysql.git
synced 2026-12-01 14:38:50 +00:00
Use disposable symbol to ensure connection cleanup. Improvements to internal types. Code splitting and removal of redundant variables.
23 lines
627 B
TypeScript
23 lines
627 B
TypeScript
import { ResultSetHeader, RowDataPacket } from 'mysql2';
|
|
import type { QueryResponse, QueryType } from '../types';
|
|
|
|
export const parseResponse = (type: QueryType, result: QueryResponse): any => {
|
|
switch (type) {
|
|
case 'insert':
|
|
return (result as ResultSetHeader)?.insertId || null;
|
|
|
|
case 'update':
|
|
return (result as ResultSetHeader)?.affectedRows || null;
|
|
|
|
case 'single':
|
|
return (result as RowDataPacket[])?.[0] || null;
|
|
|
|
case 'scalar':
|
|
const row = (result as RowDataPacket[])?.[0];
|
|
return (row && Object.values(row)[0]) || null;
|
|
|
|
default:
|
|
return result || null;
|
|
}
|
|
};
|