A type-safe query builder for OCaml that enforces SQL correctness at compile time using the OCaml type system.
Sequoia is a type-safe query builder for OCaml that leverages the OCaml type system to ensure SQL query correctness at compile time. It prevents common errors by only allowing fields from tables referenced in FROM or JOIN clauses, enforcing joins via declared foreign keys, and ensuring expression type compatibility. It provides a composable, functional API for building SELECT, INSERT, UPDATE, and DELETE queries with drivers for MySQL/MariaDB and SQLite.
OCaml developers building database-backed applications who prioritize compile-time safety and want to avoid runtime SQL errors. It is particularly suited for teams requiring strict validation of database schemas and query logic.
Developers choose Sequoia for its deep integration with OCaml's type system, which catches SQL errors at compile time rather than runtime. Its unique selling point is the referrer validation mechanism (via Skip/There or an optional PPX syntax extension) that ensures fields are only accessed from tables already joined in the query, enforcing correct join relationships through foreign keys.
OCaml type-safe query builder with syntax tree extension
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Leverages OCaml's type system to catch errors like referencing tables not in FROM/JOIN or type mismatches at compile time, as demonstrated in the README's query examples.
Enforces joins only via declared foreign keys, preventing invalid relationships and ensuring schema integrity, as shown in the table definitions with Field.foreign_key.
Provides a composable query builder using the |> operator for building SELECT, INSERT, UPDATE, and DELETE queries in a functional style, supporting complex SQL constructs.
Offers drivers for MySQL/MariaDB and SQLite with a uniform API, simplifying switching between databases while maintaining type safety.
Includes a PPX syntax extension that automatically generates referrer arguments, eliminating verbose Skip/There annotations and improving code readability, as described in the syntax extension section.
Without the PPX extension, developers must manually manage Skip/There annotations, which are error-prone and verbose, as seen in the complex query example with nested Skips.
Does not support arbitrary expressions in join conditions, limiting use cases to foreign key-based joins only, which is admitted as a limitation in the README.
Requires all table definitions to be in the same file, hindering organization in larger projects, and queries in separate files rely on hackish Marshal dump files.
INSERT queries do not enforce missing non-NULL fields, potentially leading to runtime errors despite type safety, as noted in the issues and limitations.