Skip to content
Tech News
← Back to articles

LeanDB a strongly Typed SQL front end

read original more articles
Why This Matters

LeanDB introduces a strongly typed SQL frontend built on Lean 4, enabling schemas, queries, and migrations to be verified at compile time. This approach enhances data integrity and reduces runtime errors by leveraging dependent types and compiler checks. It signifies a shift towards more robust, type-safe database interactions in the tech industry, promising improved reliability for consumers and developers alike.

Key Takeaways

LeanDB: A strongly typed SQL Frontend

Why?

Because in Lean 4 your schema, your queries and your migrations can all be types, and the compiler checks all three.

This post has three jobs. Communicate that a strongly typed SQL frontend can exist. Explain why it might be valuable. Show the first cut so that you can tell me where it is wrong.

Every code example below compiles on Lean 4.33. The ones marked "does not compile" really do not, and I have pasted what the compiler says.

First, why Lean?

Also see my post Why am I betting on Lean 4 for agentic coding? from December last year.

You should think of Lean, and other languages with dependent types, as a class above functional programming languages.

In functional programming languages you can pass around functions, combine functions, have one function as the input of another.

In Lean, your types are first class objects. You can create abstract types, combine types, pass around types, and your types themselves can have inputs and parameters. And the compiler enforces all of that.

... continue reading