$ show seancorfield/honeysql
HoneySQL is a Clojure(Script) library for generating parameterized SQL strings from Clojure data structures. It provides a clean, extensible DSL for building SQL queries programmatically, supporting multiple dialects including ANSI, MySQL, SQL Server, Oracle, PostgreSQL, and NRQL. The core API is `honey.sql/format`, which converts a hash map (e.g., `{:select [:a :b] :from [:table] :where [:= :id 1]}`) into a vector of SQL string and parameters. It also offers a helper namespace (`honey.sql.helpers`) for thread-first query construction and a registration system (`register-op!`, `register-clause!`, `register-fn!`, `register-dialect!`) for extending the DSL with custom operators, clauses, functions, and dialects. The library is designed for performance, safety (parameterized queries, limited SQL injection risks), and cross-platform compatibility (Clojure, ClojureScript, Babashka, Jolt, let-go). It is not an application or data research project; it is a pure library used as a dependency in Clojure applications that need dynamic SQL generation. The codebase is well-structured, with careful attention to edge cases (e.g., quoting, null handling, caching) and a comprehensive test suite. The extensibility mechanisms are a standout feature, allowing users to add custom SQL syntax and dialects without modifying the library's source.
The LLM identified 2 files worth highlighting for reuse:
Defines the `InlineValue` protocol, which allows custom types to be rendered inline in SQL (e.g., for literals, function calls). This is a clean, minimal interface that can be extended by users to integrate their own types. It is self-contained and reusable in any SQL-related library that needs to control how values are serialized into SQL strings.
Implements variadic helper functions for building SQL clauses (e.g., `select`, `where`, `join`) using a generic macro pattern (`generic-helper-variadic`, `generic-helper-unary`). These helpers support thread-first (`->`) composition and are designed to be consistent and composable. The pattern demonstrates how to create a fluent DSL with minimal boilerplate, and the generic helper functions themselves could be extracted and adapted for other DSL-building tasks.