C++的ORM框架:ODB
ODB 是一个开源的,支持多平台,支持多数据库的 C++ 的 ORM 框架,可将 C++ 对象数据库表映射,进行轻松的数据库查询和操作。
示例代码:
odb::sqlite::database db ("people.db"); person john ("john@doe.org", "John Doe", 31); person jane ("jane@doe.org", "Jane Doe", 29); odb::transaction t (db.begin ()); db.persist (john); db.persist (jane); typedef odb::query<person> person_query; for (person& p: db.query<person> (person_query::age < 30)); cerr << p << endl; jane.age (jane.age () + 1); db.update (jane); t.commit ();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.
本文由用户 jopen 自行上传分享,仅供网友学习交流。所有权归原作者,若您的权利被侵害,请联系管理员。
转载本站原创文章,请注明出处,并保留原始链接、图片水印。
本站是一个以用户分享为主的开源技术平台,欢迎各类分享!