A syntax extension for writing type-safe SQL queries in OCaml with named parameters and PostgreSQL syntax checking.
ppx_rapper is a syntax extension for OCaml that allows developers to write SQL queries directly in their code with named parameters and compile-time type checking. It integrates with the Caqti database library to provide type-safe database interactions, catching SQL syntax errors during preprocessing and reducing runtime bugs.
OCaml developers working with databases who want type-safe SQL queries without manual string concatenation or error-prone parameter binding. It's particularly useful for projects using PostgreSQL, MariaDB, or SQLite via Caqti.
Developers choose ppx_rapper because it combines the flexibility of raw SQL with OCaml's type system, offering compile-time syntax validation, automatic parameter type inference, and support for custom types—all while maintaining minimal runtime overhead.
Syntax extension for writing SQL in OCaml
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Uses PostgreSQL grammar to validate SQL syntax during preprocessing, catching errors before runtime, as highlighted in the key features.
Implements %type{name} for inputs and @type{name} for outputs with automatic type inference from OCaml's system, reducing manual binding errors.
Supports user-defined types via the Rapper.CUSTOM signature, allowing seamless use of custom OCaml types in queries, as shown in the custom types section.
Offers record_out and function_out options to return results as OCaml records or with custom functions, enhancing type safety and readability.
SQL syntax checking is tied to PostgreSQL; for other databases like MariaDB or SQLite, it must be disabled with syntax_off, limiting compile-time safety.
Only one list input parameter is supported per query, and generated queries are dynamically assembled as 'oneshot', which may impact performance and flexibility.
Implementing custom types requires creating modules with encode/decode functions, adding overhead compared to built-in types, and is not suited for composite output types.