Pg-typesafe – Strongly typed queries for PostgreSQL and TypeScript
Type-safe Postgres queries with zero verbosity, but competes with Prisma, Drizzle, sqlc.
Lean binding for libpq
Compile-time SQL validation using Lean's type system moves database errors from runtime to build.
Lean 4 developers and formal verification enthusiasts
sqlx · Diesel
While Lean is primarily known for theorem proving, I believe its dependent-types and formal verification features make it the ideal target for AI Agents to generate provably correct code [0].
Lean-pq uses FFI to bind to libpq, but leverages Lean’s type system to move database errors from runtime to compile-time:
- Compile-time SQL Validation: Uses Lean’s macro system to check SQL strings against your schema during the build. Misspelled columns or type mismatches cause a build failure.
- Monadic Permission Tracking: An effect-tracking monad distinguishes between Read-Only and Read-Write operations. You can statically guarantee a function won't modify the DB: def getUser (id : Int) : DB .ReadOnly User.
- Zero-Overhead FFI: Battle-tested libpq performance with Lean 4 ergonomics.
The goal is to eliminate runtime surprises—syntax errors, permission violations, and null-mismatches—at the compilation phase. I’d love to hear feedback from anyone exploring Lean 4 for systems programming.
Project: https://github.com/typednotes/lean-pq
[0] https://ngrislain.github.io/projects/2026-3-12-dont-vibe--pr...
Type-safe Postgres queries with zero verbosity, but competes with Prisma, Drizzle, sqlc.
Solid Lean tutorial, but implementing insertion sort proofs is a standard exercise in the field.
Solid walkthrough of Lean basics, but just another 'insertion sort proof' in a sea of tutorials.
Beam over DuckDB unites type safety with OLAP, but only solves Haskell teams' analytics problem.
Pure SQL introspection means zero driver hell when exporting Postgres schemas to DBML.
ORM alternative with real-time CDC, but Prisma, Drizzle, and Supabase Realtime already own this space.