Introduction
StactiveRecord is a C++ library designed to make simple database use as simple as possible (in a static language). It was inspired by Ruby on Rail’s Active Record, however, no similar look, feel, or performance is guaranteed. It uses an Object-relational mapping pattern to represent records as objects. It also provides persistent object relationships (one to many, many to many, one to one).
Quick Example For Those In A Rush
See the simple example description page for a detailed description of this example.
#include <stactive_record.h>
#include <iostream>
using namespace stactiverecord;
using namespace std;
// Initialize the DB connection
Sar_Dbi * Sar_Dbi::dbi = Sar_Dbi::makeStorage("sqlite://:memory:");
class Person : public Record<Person> {
public:
SAR_INIT();
Person() : Record<Person>() {};
Person(int id) : Record<Person>(id) {};
void sayhi() { cout << "Hello\n"; };
};
SAR_SET_CLASSNAME(Person, "Person");
int main() {
Person bob;
bob.set("fullname", "Robert Somethingorother");
bob.set("age", 50);
bob.save();
ObjGroup<Person> people = Person::find(Q("age", between(40, 100)) && Q("fullname", startswith("Robert")));
people[0].sayhi();
SarVector<string> fullnames = people.get_property<string>("fullname");
cout << "Name is: " << fullnames[0] << "\n";
delete Sar_Dbi::dbi; // only cleanup necessary
return 0;
};
Installation
Prerequisites
One or more of the following databases and their dev components:
- libsqlite: SQLite C libs
- mysql c libs: distributed with the mysql client program - dev.mysql.com
- postgres c libs: come with PostgreSQL core - postgresql.org
Get The Source
Releases can be found on the releases page. You can also download the current development code using git:
git clone git://github.com/bmuller/StactiveRecord.git
Note that if you download a development release you will need current versions of the autotools installed, and you must run ./autogen.sh first before following these instructions.
Compile
Enter the StactiveRecord directory and type:
./configure
You can use the following to see additional configuration options:
./configure --help
Then:
make
su root
make install
Docs
- There is a usage page with examples and the API in brief.
- The full API is available here or by running doxygen in the root directory.