YB.ORM tool is developed to simplify for C++ developers creation of applications that work with relational databases. An Object-Relational Mapper (ORM) works by mapping database tables to classes and table records to objects in some programming language. This approach may be not optimal for each and every database application, but it proved to be reasonable in applications that require complex logic and transaction handling. The goals of YB.ORM project are: provide a convenient API for C++ developers, retain high performance of C++, keep the source code easily portable across different platforms, support most major relational DataBase Management Systems (DBMS).
Typical usage scenario is the following:
- Describe your database schema i.e. tables with their columns and relationships between tables in simple XML-based format.
- Use the code generation tool provided to produce C++ domain classes for your tables (see Tutorial1).
- Add your application-specific logic to the classes.
- Should you make changes to the database schema, you then use the code generation tool to synchronize previously generated C++ classes with the schema.
- Optionally, use the code generation tool to issue SQL statements to populate your empty database schema with tables.
- Now you can use the domain classes in cooperation with Session object to automate the following tasks:
- create new objects or delete existing objects;
- query objects from database, using object-based queries (see Tutorial3);
- modify existing objects by just assignment to objects' fields;
- link and unlink objects to/from each other using relations (see Tutorial2);
- serialize your objects into XML and JSON.
This tool employs many ideas explained in the book "Patterns of Enterprise Application Architecture" by Martin Fowler. Such patterns as "Lazy Load", "Identity Map", "Unit of Work", etc. Also, the project development was inspired by the power of Hibernate framework for Java, and especially by the design of SQLAlchemy for Python. Some details of how it works are here: Internals.
At the moment, YB.ORM tool works in Linux, Mac OS X and Windows. It can be built using the following compilers: GCC, CLang, MinGW, MSVC 2008/2010, also Borland C++ Builder, see Building Instructions.
You can build YB.ORM library against your toolkit of choice: Boost, Qt, or wxWidgets; their native data types will be used for strings, date and time, threads, XML parsing, etc.
The tool was tested to work with the following SQL databases: MySQL, Oracle, SQLite, Firebird, Postgres. To connect to a database you have these options:
- ODBC drivers
- popular database connectivity C++ library SOCI
- database drivers for Qt library: QtSql
- there is native driver for SQLite. Optionally, use connection pooling the library provides. Look here for details: Connecting to database.
The basic functionality of YB.ORM was tested on several little projects, and proved to be usable. Keep in mind, that the tool is under development and its API may change between releases. Some interesting features are still to be implemented (see ToDo list).
Project has started in late 2006 as a part of billing system for on-line ads at Yandex company (http://www.yandex.com/) by Viacheslav Naydenov (me) and Sergey Chmelev. "YB" used to stand for Yandex.Balance, the name for the billing system. Today YB.ORM project is not affiliated with Yandex company. The source code was released in early 2011 under open source license, since then the code has been mostly rewritten. Thanks to the author of tiny odbc wrapper, whose code is used as a base for the first usable SQL driver (OdbcDriver
class). Also, I would like to mention the feedback and contribution from several students of Moscow State Open University (MSOU), where I was using this piece of software as a case study. The list of contributors:
- Viacheslav Naydenov, vaclav at yandex dot ru - main developer
- Sergey Chmelev, halty at yandex dash team dot ru - early contributor
- SqUe, squarious at gmail dot com - tiodbc code
- Nikita Buyvich, buyvich at gmail dot com - MSOU
- Viacheslav Fedorov, funny dash story at yandex dot ru - MSOU
- Andrey Skobenkov, andrey dot skobenkov at gmail dot com - MSOU
Any feedback, patches or comments are welcome!