ReviewOS

stacks/bun-query-builder

Type the driver boundary (internal DriverConnection interface) to remove ~431 'as any'

#1044
Closed glennmichael123 opened this 2 months ago ·
2 months ago

Summary

The query-execution core casts the driver to any everywhere ((_sql as any).unsafe(...), (q as any).execute(), etc.) — ~431 in client.ts, ~50 in orm.ts. Because the SQLite wrapper (db.ts) and Bun's native SQL expose structurally different objects, there's no shared interface, so the dialect-dispatch hot path — where a multi-dialect builder most needs type safety — is entirely untyped.

Suggested fix

Define an internal DriverConnection/DriverQuery interface (unsafe, execute, cancel, then) that both createSQLiteSQL's return value and Bun's SQL satisfy, and type _sql/q against it. This eliminates most casts and would surface SQLite/Bun shape skew at compile time.

Severity: low/medium (type safety). Found via internal code audit.

9 days ago

Fixed in 8efb4ba. Defined DriverConnection (the shared callable + unsafe/query/close surface both the bun:sqlite wrapper and Bun's native SQL satisfy) and DriverQuery/AwaitableDriverQuery (the awaitable unsafe() result), and typed _sql against it via a single boundary cast at declaration — so the dispatch-path .unsafe(...) calls are now typed instead of (_sql as any).unsafe. DriverExecutor.conn() is typed too (was any). All 62 (_sql as any) casts in client.ts removed; type-only change, full suite green + typecheck clean + dist builds. The remaining as any in client.ts are unrelated generic-erasure / proxy-return casts, not the driver boundary this issue was about.

Sign in to comment on this issue.