r/cpp • • Feb 25 '26

Autocrud: Automatic CRUD Operations with C++26 Reflection

I just did the initial check-in of my Autocrud project, which provides a templated class you can use to perform CRUD operations into a PostgreSQL database.

Autocrud does expect you to derive your class from a Node type I provide, but this is a design decision for this project and not a fundamental restriction caused by reflection. This object could easily be modified to not do that.

It does what it says it does. The table that gets created in your database will be named after the structure you derive from Node. The columns in the database will be named the same as the data members in your class. Writing one object will populate a row in the database. The unit and integration tests have some basic usage. The object does expose a tuple of table information which AutocrudTests.cpp queries to make sure my annotations are being handled correctly. IntegrationTests.cpp has a test that derives a structure and does a round trip to validate database functionality.

The project provides some basic annotations to rename or ignore members in your struct, as well as one you can use to set the database type of the object.

I'm going to do a lot more work on this, but since people are curious about reflection right now and it's working reasonably well I wanted to make it public as quickly as possible. Between this and autocereal I'm well on my way to building "C++ on Rails" lol. I still need to build an Autopistache (which can leverage autocereal for serialization,) automate emscripten bindings and maybe do some basic automated GUI with Imgui or Qt or something that I can compile to emscripten to provide the full stack C++ platform.

45 Upvotes

12 comments sorted by

View all comments

Show parent comment

1

u/m-in Feb 26 '26

Side quest(ion): For the requirements manager, is a database even needed? Perhaps wrongly but I can’t imagine there being so much data that managing it without a database wouldn’t work well and with low friction?

3

u/FlyingRhenquest Feb 26 '26

Depends on how large a project you're managing I suppose. If you want full traceability from requirement to specification to unit test results and maybe also want to version control changes as your project progresses, that would end up being a lot of data. Like, if you wanted to audit every single git check-in so you could look at how the code associated with any one requirement in your system evolved over time, I could see that getting a bit weighty. I'm not sure that's something you'd really even want to do with that code.

I definitely envisioned being able to just serialize an entire project or some extracted graph from the project to JSON so you could hand it off to another division or an external entity. The IDs are UUIDv7 IDs, so the odds of ever encountering an ID collision are pretty low.