Details
-
New Feature
-
Status: Closed (View Workflow)
-
Major
-
Resolution: Fixed
-
None
-
None
Description
from PR : https://github.com/mariadb-corporation/mariadb-connector-nodejs/pull/334
Previously, TypeScript generics were only available for result sets (T), not for input values:
// Before: values typed as `any`, no type safety on inputs
|
const result = await conn.query<UserRow>('SELECT * FROM users WHERE id = ?', [id]); |
This change adds a generic type parameter V to values on query, execute, batch, prepare, queryStream, and executeStream, enabling type safety for both inputs and outputs:
// After: both result type T and values type V are available
|
type UserRow = { id: number; email: string };
|
type UserInsert = [string, Buffer, Buffer];
|
|
const rows = await conn.query<UserRow[], [number]>('SELECT * FROM users WHERE id = ?', [id]); |
const stmt = await conn.prepare<UserInsert>(sql);
|
await stmt.execute([email, hash, salt]); // enforces UserInsert type |
All generic parameters default to any, so existing code is fully backward compatible.