Skip to content

Generic ResultSet for better typing #218

@asyncmacro

Description

@asyncmacro

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions