Use sqlc-gen-typescript-native for TypeScript support - #4611
Closed
touzoku wants to merge 2 commits into
Closed
Conversation
Point the language links to the native plugin and mark SQLite support as beta. Remove the old plugin name from historical changelog entries while keeping their original meaning. Enable TypeScript CI against v0.3.0, pinned by commit. Build sqlc from the current checkout and run the plugin's generation, type and runtime tests, then check the generated Deno SQLite example with sqlc diff.
Author
|
@yshrsmz @kyleconroy @shinshin86 @woowenjun99 tagging for visibility |
Collaborator
|
I'm happy to add sqlc-gen-typescript-native to the community plugins section, but I'm not going to be replacing the existing TypeScript support. |
Author
|
@kyleconroy The plugin hasn’t seen any updates in two years, and its current functionality is significantly more limited than what I’ve implemented here. In practice, the existing TypeScript support is very minimal, which is exactly why I opened this PR. I’d suggest reconsidering this. I don’t mind if this work eventually gets moved or merged upstream into the plugin, but at the moment it doesn’t appear that anyone is actively working on TypeScript codegen there. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This switches the TypeScript links in the README and language support table to sqlc-gen-typescript-native, marks SQLite support as Beta, and re-enables TypeScript CI. The job pins v0.4.0 by commit and tests it with the sqlc built from this checkout.
The current plugin builds TypeScript syntax trees and prints them through the TypeScript compiler inside Javy. The replacement implements generation directly in WebAssembly text. It uses the same sqlc plugin protocol, without an embedded JavaScript runtime or TypeScript compiler. This PR changes the plugin integration and docs; it requires no changes to sqlc's compiler or plugin API. See the existing build and new implementation.
The published WASM file drops from 72,685,305 bytes to 86,712 bytes: 99.88% smaller. These are the files from sqlc-gen-typescript v0.1.3 and sqlc-gen-typescript-native v0.4.0, verified against their published SHA-256 checksums.
I measured complete
sqlc generateruns for both releases using the same PostgreSQL fixtures. The releases were measured in separate runs:These are medians on an Apple M1 Max running macOS 26.6.2, using sqlc commit
23e357a414310aa8846e64624da8b8a626b3a610, built with Go 1.26.5. Both plugins received the same schemas, queries, andruntime: node/driver: pgoptions. Cold results use three runs with freshSQLCCACHEdirectories; warm results use seven runs after one untimed warmup. Downloads sit outside the timer; SQL analysis, plugin loading, generation, and file writes sit inside it. Every run must emit all expected query functions with the same output as that plugin's other runs. These numbers measure generation, not database query speed.The feature gains also matter:
@bonakodo/sqlitesupport and an opt-in native mode for both SQLite drivers, withbigintintegers, boolean/date conversions, and synchronous calls that work inside transaction callbacks. Upstream main already hasbetter-sqlite3; the new Deno driver and native value handling extend that support.:execrowsand:execresult, and adds:execlastidforbetter-sqlite3. The existing plugin's dispatch handles only:one,:many,:exec, and:execlastid; its SQLite driver rejects the last one. See dispatch and SQLite output.pg/postgres.jsand MySQLmysql2remain supported. The plugin README documents the options and driver behavior.Generated TypeScript size depends on the workload. Native v0.4.0 shares query types, encoders, decoders, and field metadata across SQL files. It splits runtime helpers into a common file and one file per engine, and emits only the helpers the queries use. Running the same PostgreSQL fixtures gives:
The small fixture remains larger than the old plugin; the large fixture is now 16.8% smaller. These totals include all generated files before bundling.
Migration starts with changing the WASM URL and checksum, keeping the shared runtime, driver, and mysql2 options, then regenerating and type-checking the application. Output is not byte-compatible: it adds files and corrects some field types and names. The module also uses fixed 64 MiB memory, with 16 MiB limits on the request and combined generated file contents, and a 1,024-file limit. The migration notes cover these differences and the other capacity limits.
Local validation passed: the sqlc build, the pinned plugin's full integration task, generated TypeScript and Deno checks, the 100-table/800-query/202-override test, 42 Deno runtime tests, 11 Node tests, 11 Bun tests, the example's
sqlc diff, and actionlint. SQLite tests execute real queries; server-driver adapter tests use test doubles. Live PostgreSQL/MySQL tests remain unverified. The TypeScript CI job passed on the updated PR commit.