开发者

Map SQL table rows to C++ structures

I'm trying to implement some kind of persistent storage of C++ structures into an SQLite database. It looks nice in the beginning but then it becomes complicated with all those SQL requests, data binds and manual getting field values one after another.

Ideally I'd like to have some kind of mapping from a table row in SQLite to a C++ structure, with a possibility of running SQL requests on that. On the other hand, I'd still like to keep it general enough to be able to run more complex requests with joins etc.

I even thought that an external utility that would auto-generate the corresponding C++/SQL glue code could be helpful.

What would be the right way to do this kind of mapping? I've heard people suggesting boost::serialization or Google's protocol buffers, would this be a much better option for what I want, or maybe 开发者_JAVA百科there are some other good options?


Sounds like you want an Object Relational Mapper (ORM). Try reading through this stack overflow thread: https://stackoverflow.com/questions/74141/good-orm-for-c-solutions

The selected answer there talks about Database Template Library; I'd look into there as well.


Soci is a good start. If it doesn't meet all your needs, it will help you figure out where you want to go.

I used it for a while with sqlite, and found it better than the others I could find. I did end up writing my own, though ...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜