C++20 ❤ SQL
summary
Claim: C++20 lets SQL queries be embedded as constexpr SQL strings and annotated with tiny C‑style comments to generate compile‑time parameter and row bindings. Implementation uses C++20 non‑type template params, a metastruct reflection helper and sqlite as the backend. Result is a small library — about ~500 lines plus metastruct ~250, under 1000 total — that prevents SQL injection, produces compile‑time errors for missing parameters or wrong types, and returns optionals for nullable columns, and it works.
AI-written summary · about
chapters (16)
- 0:00Start
- 1:22Overview
- 3:08Example Database
- 3:35Create the customers table
- 6:24Avoiding SQL Injection Attacks
- 7:40Traditional Library with Strings
- 9:24Domain Specific Language
- 10:28Object Relational Model
- 16:23Lookup a customer by name
- 20:05Key Design Insight
- 21:06Annotations
- 22:41Implementation
- 27:18Parsing the type specs
- 28:26combined type specs and type specs
- 33:06Turn type specs into meta struct
- 37:43Binding SQL Parameters
related talks
01h 07mSqlpp11, An EDSL For Type-Safe SQL In C++11
59msqlpp11, An SQL Library Worthy Of Modern C++
45mMore Than a Query Language: SQL in the 21st Century
01h 05m“A modern database interface for C++"
15mWhat If Writing SQL Became Cool Again?
36mCompile-time reflection, Serialization and ORM
32mBecause SQL is everywhere but you don't want to use it
50mDemystifying Database Performance Issues with SQL Commenter
