A fast, memory-efficient SQL query builder for Go that helps construct SQL statements dynamically with safe placeholder conversion and struct binding.
sqlf is a fast SQL query builder library for Go that enables developers to construct SQL statements dynamically at runtime. It solves the problem of safely building complex queries with variable conditions, placeholders, and result binding without introducing ORM overhead. The library focuses on performance and memory efficiency, reusing allocated memory to minimize footprint under load.
Go developers working directly with SQL databases who need to build dynamic queries safely and efficiently, particularly those in performance-sensitive applications or avoiding full ORMs.
Developers choose sqlf for its balance of raw SQL control and builder convenience, offering safe placeholder conversion, struct binding, and performance optimizations without the complexity and overhead of a full ORM.
Fast SQL query builder for Go
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
sqlf reuses allocated memory during query construction, reducing memory footprint and improving performance under high load, as highlighted in the benchmarks linked in the README.
Automatically converts `?` placeholders to PostgreSQL-style `$1, $2...` numbering when needed, ensuring cross-dialect compatibility without manual intervention, as described in the features.
Supports binding query results directly to Go structs using `.Bind()` or to individual variables with `.To()`, including private fields, as demonstrated in the examples with the Offer struct.
Enables construction of advanced queries with CTEs, JOINs, subqueries, and UNIONs through a fluent interface, shown in the examples with WITH clauses and subquery integration.
Lacks compile-time type checks for query arguments, column names, and table names, which can lead to runtime errors that are harder to catch early, as admitted in the README.
Does not provide a wrapper for OR conditions, forcing developers to use workarounds like UNION or query splitting, which can complicate logic for queries requiring frequent OR operations.
Offers no built-in tools to help pinpoint the cause of SQL statement issues, leaving debugging entirely to the developer, as stated in the README's limitations.