libsql-client-ts
libsql-client-ts copied to clipboard
Make ResultSet generic for typed row access
Currently callers have to cast query results to use a concrete type, which loses type safety when schemas change:
const book = rs.rows[0] as unknown as Book;
This PR makes ResultSet accept an optional type parameter with a default of Row, so existing code is completely unaffected. Callers who know the row shape can now pass it directly:
const { rows } = await client.execute<Book>("SELECT * FROM books");
const title: string = rows[0].title;
The same generic is threaded through Client.batch, Transaction.execute, and Transaction.batch. No runtime behavior changes — the type parameter is a TypeScript overlay only.
Fixes #218