Library for saving c++ objects to database

2020-07-27 02:58发布

问题:

I am currently saving my object graph in xml file with boost serialization. The library is great, it automatically restores the objects and all member pointers and references.

Problem : I need to have random access to the data ( read just one object, or delete just one object ). With boost serialization the scenario is like this :

--load all objects from file

-- use and modify objects

-- write all objects to archive again

The drawback with this is if only one object changed , I want to write to the archive only that object, and not the entire object graph which is huge.

So I am looking for library which support storing all objects to database, and which also supports boost and stl types. Currently I am using these boost types:

  • boost multi-index

  • Smart Ptr ( shared_ptr,weak_ptr,scoped_ptr)

  • optional,variant

Anyone knows such library or something close to it, or have idea how to go for resolving this problem?

回答1:

Have you tried ODB? http://www.codesynthesis.com/products/odb/



回答2:

It is very complicate to do such a thing. Since C++ (the runtime environment) does not know anything about itself you have to code it on your own. My advice is to split the graph onto different files and to update only the files that are needed (this means that you have to control serialization on your own, not using boost lib).



回答3:

Maybe Wt::Dbo? By adding a single template function to your classes, Dbo maps them to an SQL database.