為什么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++數(shù)據(jù)庫接口,都需要手動生成SQL語句;

  • 手動生成的查詢字符串,常常會因為模型改動而失效;

  • 查詢語句/結(jié)果和C++原生數(shù)據(jù)之間的轉(zhuǎn)換,每次都要手動解析;

我為什么要寫ORM

C++大作業(yè)需要實現(xiàn)一個在線的對戰(zhàn)游戲,其中的游戲信息需要保存到數(shù)據(jù)庫里;

而我最初始的里沒有使用 ORM 導(dǎo)致生成 SQL 語句的代碼占了好大一個部分;
并且這一大堆代碼里的小錯誤往往很難被發(fā)現(xiàn);

每次修改游戲里怪物的模型都需要同步修改這些代碼;
然而在修改的過程中經(jīng)常因為疏漏而出現(xiàn)小錯誤;

網(wǎng)友評論