C++的ORM框架:ODB

jopen 13年前發布 | 32K 次閱讀 ORM 持久層框架

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.


項目主頁:http://www.baiduhome.net/lib/view/home/1357657155074

 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!