libsql-client-ts icon indicating copy to clipboard operation
libsql-client-ts copied to clipboard

Make ResultSet generic for typed row access

Open Pulkit7070 opened this issue 6 months ago • 0 comments

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

Pulkit7070 avatar May 07 '26 10:05 Pulkit7070