matador

matador is an object relational mapping framework written in C++. It aims to encapsulate all database backend communication. You don't have to deal with database backends or sql statements neither with mapping of data types or serialization of objects. It comes with relation handling out of the box, brings a unique container for all kind of objects and a fluent sql query interface. On top all features are combined into an ORM layer.

Learn more »

Unique Container

matador comes with a unique kind of container where you can store all your objects in. Once the hierarchy of your entities is set up you can perform all CRUD operations on the container plus filtering and using views.

View details »

1
2
3
4
5
6
7
8
9
10
object_store store;

store.attach<person>("person");
store.attach<employee, person>("employee");
store.attach<department>("department");

auto george = store.insert(new employee("george"));
auto jane = store.insert(new employee("jane"));

auto dep = store.insert(new department("insurance"));

Fluent Query

The sql query module provides simple fluent interface to build sql queries. A query can be typed or just work on a anonymous row object. Once a query is setup it can be executed directly or be captured in a prepared statement.

View details »

1
2
3
4
5
6
7
8
9
10
connection conn("sqlite://db.sqlite");
query<person> q("person", conn);

column name("name");
column age("age");
auto res = q.select().where(name != "george" && age > 35);

for (auto p in res) {
  std::cout << "name: " p->name << "\n";
}

Real Relations

matador comes with real relation handling (one to one, one to many and many to many). Once one relation side changes the other side of the relation is updated automatically. This works with plain object store as well as with all supported database backends.

View details »

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
object_store store;
// prepare store ...

auto george = store.insert(new employee("george"));
auto jane = store.insert(new employee("jane"));
auto dep = store.insert(new department("insurance"));

dep->employees.push_back(jane);

// janes department name is insurance
std::cout << jane->department->name << "\n"

george->department = dep;

// second employee in department is george
std::cout << dep->employees.size() << "\n"

ORM Layer

The ORM layer finally combines the unique container, the fluent query interface and the relation handling. It hides all the database work, takes care of transaction handling and object serialization, handles all types of relationships and provides the usera simple interface.

View details »

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
persistence p("sqlite://db.sqlite");

p.attach<author>("author");
p.attach<post>("post");

// create schema
p.create();

session s(p);

transaction tr = s.begin();
try {
  p.insert(new author("john irwing"));
  p.insert(new author("charles darwin"));
  tr.commit();
} catch (std::exception &ex) {
  tr.rollback();
}