C++的ORM 开源框架

      YB.ORM库的目标是简化编写C++代码中处理SQL数据库。我们的目标是提供一个方便的接口,如SQLAlchemy的(蟒蛇)或休眠(JAVA)。库本身是跨平台的,支持各种SQL方言:sqlite3的,MySQL和Postgres的,甲骨文,和火鸟。集成升压,Qt4的,和wxWidgets
是内置的。在一个典型的使用场景中,你会形容你的数据库架构和表关系中的一个简单的基于XML的格式,生成SQL代码,以填充数据库架构的表,生成C +
+类,添加特定于应用程序的逻辑类,使用这些类合作与会话对象从数据库中查询对象,创建新的或修改/删除现有对象,或链接和取消链接对象的关系。简单的序列化到XML的支持连接池。 项目下载地址:http://sourceforge.net/projects/yborm/ 

      ODB 是一个开源的,支持多平台,支持多数据库的 C++ 的 ORM 框架,可将 C++ 对象数据库表映射,进行轻松的数据库查询和操作。
使用ODB进行对象持久化具有以下优点:   

    Ease of use. ODB automatically generates database conversion  code from your C++ classes and allows you to manipulate persistent  objects using a simple, object-oriented database API. Concise code. With ODB hiding the details of the underlying  database, the application logic is written using the natural object  vocabulary making it simpler and thus easier to read and understand. Safety. The ODB object persistence and query APIs are  statically typed. You use C++ identifiers instead of strings  to refer to object members and the generated code makes sure  database and C++ types are compatible. All this helps catch programming errors at compile-time rather than at runtime. Database portability. Because the database conversion code  is automatically generated, it is easy to switch from one database  vendor to another. Optimal performance. ODB has been designed for high performance   and low memory overhead. All the available optimization techniques, such as prepared statements and extensive connection, statement,  and buffer caching, are used to provide the most efficient  implementation for each database operation. Persistent classes have zero per-object memory overhead. There are no hidden "database"  members that each class must have nor are there per-object data   structures allocated by ODB.
 Maintainability. Automatic code generation minimizes the  effort needed to adapt the application to changes in persistent   classes. The database conversion code is kept separately from   the class declarations and application logic. This makes the   application easier to debug and maintain.
ODB 2.1.0 发布,该版本包含很多新特性,包括:

  • 支持通过访问符、修饰符、函数和表达式来访问数据成员
  • 支持虚拟数据成员
  • 可在数据成员上直接定义数据库索引
  • 支持映射扩展数据库类型,例如空间数据、用户自定义类型和集合
  • 更新了 profile 库
  • 通过 Boost profile 库提供对 Uuid 和多索引容器哭的持久化支持
  • 支持 Visual Studio 2012 和 Clang 3.1

示例代码:

01 odb::sqlite::database db ("people.db");
02  
03 person john ("john@doe.org", "John Doe", 31);
04 person jane ("jane@doe.org", "Jane Doe", 29);
05  
06 odb::transaction t (db.begin ());
07  
08 db.persist (john);
09 db.persist (jane);
10  
11 typedef odb::query<person> person_query;
12  
13 for (person& p: db.query<person> (person_query::age < 30));
14   cerr << p << endl;
15  
16 jane.age (jane.age () + 1);
17 db.update (jane);
18  
19 t.commit ();

 

 项目下载地址:http://www.codesynthesis.com/products/odb/

 

posted on 2013-09-30 17:29  荣锋亮  阅读(3256)  评论(0编辑  收藏  举报

导航