为什么C++要ORM

As good object-oriented developers got tired of this repetitive work,
their typical tendency towards enlightened laziness started
to manifest itself in the creation of tools to help automate
the process.

When working with relational databases,
the culmination of such efforts were object/relational mapping tools.

  • 一般的C++数据库接口,都需要手动生成SQL语句;

  • 手动生成的查询字符串,常常会因为模型改动而失效;

  • 查询语句/结果和C++原生数据之间的转换,每次都要手动解析;

我为什么要写ORM

C++大作业需要实现一个在线的对战游戏,其中的游戏信息需要保存到数据库里;

而我最初始的里没有使用 ORM 导致生成 SQL 语句的代码占了好大一个部分;
并且这一大堆代码里的小错误往往很难被发现;

每次修改游戏里怪物的模型都需要同步修改这些代码;
然而在修改的过程中经常因为疏漏而出现小错误;

网友评论