Skip to content

DatabaseInterface.query() return type doesn't expose .rows — forces as-any in all consumers #883

@willgriffin

Description

@willgriffin

Problem

DatabaseInterface.query() returns a type that does not expose the .rows property, even though the PostgreSQL driver returns { rows: T[] } at runtime. Every downstream consumer must cast through any to access row data:

const result = await db.query(`SELECT ... FROM ...`, arg);
const rows = (result as any).rows ?? result;  // forced cast

This pattern appears in 5+ files across blindmanpress.com (and likely other consumers), completely defeating TypeScript safety on all raw query results.

Expected Behavior

query() return type should either:

  1. Expose .rows directly (e.g., { rows: T[] })
  2. Return rows as the top-level array (so no .rows access is needed)
  3. Provide a typed queryRows<T>() convenience method

Consumer Impact

Every file using db.query() with raw SQL currently has zero type safety on the result shape. Column renames or schema changes will not produce compile-time errors — only runtime failures.

Affected Consumer Files

  • billing/events/+page.server.ts
  • referrals/links/+server.ts
  • referrals/click/+server.ts
  • affiliates/events/+server.ts
  • Any file doing const rows = (result as any).rows ?? result

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions