Petrol: embedding a type-safe SQL API in OCaml using GADTs

This page summarizes the projects mentioned and recommended in the original post on /r/ocaml

Our great sponsors
  • InfluxDB - Power Real-Time Data Analytics at Scale
  • WorkOS - The modern identity platform for B2B SaaS
  • SaaSHub - Software Alternatives and Reviews
  • macaque

    An old library of mine, Macaque, is relevant previous work here. Macaque used a mix of camlp4 metaprogramming and phantom types to provide static guarantees for SQL queries. The camlp4 part was used to provide a "comprehension" syntax to SQL queries (in retrospect I think that sticking to the usual SQL syntax would in fact have been better for adoption), but also sometimes help with enforcing certain static discipline. Still most of the static discipline comes from phantom types in the two main interfaces, sql.mli and query.mli. This work was done in 2012, before the introduction of GADTs in OCaml, so it purely relies on phantom types (the types are enforced by the interface, but cannot be introspected at runtime in the implementation, which uses Obj and is justified by the interface guarantees).

  • InfluxDB

    Power Real-Time Data Analytics at Scale. Get real-time insights from all types of time series data with InfluxDB. Ingest, query, and analyze billions of data points in real-time with unbounded cardinality.

NOTE: The number of mentions on this list indicates mentions on common posts plus user suggested alternatives. Hence, a higher number means a more popular project.

Suggest a related project

Related posts