libsql-client-ts
libsql-client-ts copied to clipboard
Generic `ResultSet` for better typing
The db.execute method currently returns a non-generic ResultSet type. However, in some cases, the column and row types are known beforehand. By making ResultSet generic, developers could provide these types, enhancing the developer experience (DX).
For instance, a table with columns imageId, filename, and data only provides a length property when using the standard db.execute return type. To return the data column in a Response object (new Response(result.data)), a workaround like this is needed:
type ExtendedResultSet<T> = ResultSet & {
rows: T[];
};
This allows functions to return an ExtendedResultSet<ImageRow>, where the rows property is typed based on the specific row type.
This approach saves time and reduces debugging when table modifications occur. I'm Happy to contribute to this improvement if the team approves.