import { pool } from '@/backend/utils/db';
import { RowDataPacket, FieldPacket } from 'mysql2';

/**
 * Typed query helper for MySQL that ensures safe casting and full result access
 */
export async function typedQuery<T>(sql: string, params: any[] = []): Promise<[T[], FieldPacket[]]> {
  const [rows, fields] = await pool.query<RowDataPacket[]>(sql, params);
  return [rows as T[], fields];
}
