explaingit

swordfatih/reflect

22C++Audience · developerComplexity · 4/5ActiveSetup · hard

TLDR

Pre-1.0 C++ ORM that uses C++26 static reflection to derive schema, CRUD, filters, and migrations from annotated structs for SQLite and PostgreSQL backends.

Mindmap

mindmap
  root((reflect))
    Inputs
      Annotated structs
      SQLite or Postgres URL
    Outputs
      Schema
      CRUD calls
      Migrations
      Drift report
    Use Cases
      C++ database apps
      Schema-from-code
      Local dev migrations
    Tech Stack
      C++26
      CMake
      SQLite
      PostgreSQL
      static reflection

Things people build with this

USE CASE 1

Define database tables as annotated C++ structs and let the ORM generate schema

USE CASE 2

Run typed CRUD queries with compile-time checked where clauses

USE CASE 3

Detect drift between a live database and your C++ model and report mismatches

USE CASE 4

Drive additive or versioned migrations from a C++ project without external tools

Tech stack

C++CMakeSQLitePostgreSQL

Getting it running

Difficulty · hard Time to first run · 1day+

Requires a bleeding edge compiler with C++26 static reflection enabled via -freflection and CMake 3.30 or newer.

In plain English

reflect is a C++ library that acts as an ORM, which stands for object relational mapper. An ORM lets a programmer work with database rows as if they were normal objects in their language, instead of writing SQL by hand. What sets this project apart is that it is built around C++26 static reflection, a brand new feature in the C++ language that lets code inspect the structure of types at compile time. You define a normal C++ struct, add a few small annotations to fields, and the library figures out the rest: table layout, schema creation, type-safe filters, CRUD statements, migrations, validation, and turning database rows back into structs. A short example in the README shows how this looks. The user defines a User struct with id, email, and name fields, decorated with attributes such as reflect::id, reflect::auto_increment, reflect::unique, reflect::not_null, and reflect::varchar with a size. The main function opens a SQLite database, runs db.migrate to create the table, inserts a row using brace initialization, and then runs a query with a typed where clause that checks if the email ends with a given string. The C++ model is treated as the source of truth. Features listed include support for SQLite and PostgreSQL backends, a full set of column annotations covering primary keys, indexes, defaults, foreign keys, varchar, decimal, text, JSON, UUID, blob, date, time, and timestamp. There are CRUD helpers such as insert, find_one, find_many, update, delete_many, count, and exists. Relationships are declared with has_many, has_one, and belongs_to. Transactions support nested savepoints. The library can also validate the live database against the C++ model and report drift such as missing columns, type mismatches, or nullability differences. Migrations come in two styles. Additive sync creates tables and adds missing columns, but never drops or renames anything. Versioned manual migrations are recorded in a reflect_schema_migrations table and skipped when already applied. There is also a destructive development mode that drops and recreates tables when drift is found, intended for local iteration only. The project is pre-1.0. The README has a frank section titled What Is Still Missing For A Complete V1, listing items such as generated up/down migration files, eager loading, many-to-many helpers, connection pooling, async APIs, query logging, and a migration CLI. Build requires CMake 3.30 or newer and a compiler with C++26 static reflection support enabled via -freflection.

Copy-paste prompts

Prompt 1
Set up a CMake project that links reflect and connects to SQLite
Prompt 2
Define a Users and Posts model with has_many and belongs_to using reflect annotations
Prompt 3
Run db.migrate in additive mode and inspect the reflect_schema_migrations table
Prompt 4
Compile a sample with a C++26 reflection-capable toolchain using -freflection
Prompt 5
Write a destructive dev-mode test that drops and recreates tables when drift is detected
Open on GitHub → Explain another repo

Generated 2026-05-22 · Model: sonnet-4-6 · Verify against the repo before relying on details.