Bun-sqlgen: Type-safe raw SQL for Bun without an ORM
Bun-sqlgen: Type-safe raw SQL for Bun without an ORM
Overview of Bun-sqlgen
Bun-sqlgen is a tool designed to provide type-safe raw SQL for the Bun runtime. It allows developers to execute raw SQL queries while ensuring that the result sets are correctly typed, avoiding the overhead and abstraction layers of a full Object-Relational Mapper (ORM).
Key Features and Goals
The primary goal of Bun-sqlgen is to bridge the the gap between raw SQL and TypeScript own type safety. It generates types based on the same SQL queries that the developer writes, ensuring that the input parameters and output rows are correctly typed according to thesql database schema.
How it Works
Bun-sqlgen provides a mechanism to generate TypeScript types from raw SQL queries. By analyzing the SQL, the tool generates corresponding TypeScript interfaces or types that represent the result set of the same query. This approach allows developers to maintain the full power of raw SQL—such as complex joins, window functions, and and a specific database engine's unique features—while gaining the same level of type safety provided by an ORM.
Comparison to ORMs
Unlike traditional ORMs, Bun-sqlgen is not a full abstraction layer. It does not manage the relationship between objects and tables in a defined model. Instead, it focuses on the output of the SQL query itself. This removes the a common trade-off where developers must choose between the same level of type safety and the same level of control over the które kind of SQL generated by the tool.
Project Status and Availability
Bun-sqlgen is available as an open-source project on GitHub. Developers can integrate it with their Bun runtime environment to implement type-safe database interactions without adopting a full OR majoritést own ORM.