Permalink
Browse files

updated examples and readme

  • Loading branch information...
bmuller committed Jan 15, 2011
1 parent b12e154 commit 25045c9b04c158f5a58f4806a95115cc9f77e437
View
1 README
View
@@ -4,55 +4,61 @@ StactiveRecord is a C++ library designed to make simple database use as simple a
# Installation
## Prerequisites
One or more of the following databases and their dev components:
-* libsqlite: SQLite C libs - [http://www.sqlite.org](http://www.sqlite.org)
-* mysql c libs: distributed with the mysql client program - [http://dev.mysql.com/downloads/mysql/](http://dev.mysql.com/downloads/mysql/)
-* postgres c libs: come with PostgreSQL core - [http://www.postgresql.org/download/](http://www.postgresql.org/download/)
+ * libsqlite: SQLite C libs - [http://www.sqlite.org](http://www.sqlite.org)
+ * mysql c libs: distributed with the mysql client program - [http://dev.mysql.com/downloads/mysql/](http://dev.mysql.com/downloads/mysql/)
+ * postgres c libs: come with PostgreSQL core - [http://www.postgresql.org/download/](http://www.postgresql.org/download/)
## Compiling
Stable releases can be found at [http://findingscience.com/StactiveRecord/releases.html](http://findingscience.com/StactiveRecord/releases.html). Development releases can be fetched using:
- git clone git://github.com/bmuller/StactiveRecord.git
+ git clone git://github.com/bmuller/StactiveRecord.git
You'll need to have the autotools installed and run ./autogen.sh if you download the development version.
To compile and install:
- ./configure && make && sudo make install
+ ./configure && make && sudo make install
Confiuration options can be found with:
- ./configure --help
+ ./configure --help
+## Testing
+ export DBCONFIG=sqlite://:memory:
+ make test
# Usage
StactiveRecord provides both typical basic ORM functionality as well as a general database agnostic interface for CRUD operations. As an example of ORM usage:
- #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;
- };
+ #include <stactivrecord/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;
+ };
+
+Then, to compile your program (assuming you saved it in *simple.cpp*):
+ g++ $(pkg-config libstactiverecord --cflags --libs) simple.cpp -o simple
# Documentation
API documentation can be created using the command:
View
@@ -1,21 +1,27 @@
noinst_PROGRAMS = dbs many_to_many one_to_many one_to_one querying simple
-HEADERDIR = ../stactiverecord
+LIBDIR = ../stactiverecord
dbs_SOURCES = dbs.cpp
-dbs_LDFLAGS = -lstactiverecord -L$(HEADERDIR)/.libs
+dbs_LDFLAGS = -lstactiverecord -L$(LIBDIR)/.libs
+dbs_CPPFLAGS = -I..
many_to_many_SOURCES = many_to_many.cpp
-many_to_many_LDFLAGS = -lstactiverecord -L$(HEADERDIR)/.libs
+many_to_many_LDFLAGS = -lstactiverecord -L$(LIBDIR)/.libs
+many_to_many_CPPFLAGS = -I..
one_to_many_SOURCES = one_to_many.cpp
-one_to_many_LDFLAGS = -lstactiverecord -L$(HEADERDIR)/.libs
+one_to_many_LDFLAGS = -lstactiverecord -L$(LIBDIR)/.libs
+one_to_many_CPPFLAGS = -I..
one_to_one_SOURCES = one_to_one.cpp
-one_to_one_LDFLAGS = -lstactiverecord -L$(HEADERDIR)/.libs
+one_to_one_LDFLAGS = -lstactiverecord -L$(LIBDIR)/.libs
+one_to_one_CPPFLAGS = -I..
querying_SOURCES = querying.cpp
-querying_LDFLAGS = -lstactiverecord -L$(HEADERDIR)/.libs
+querying_LDFLAGS = -lstactiverecord -L$(LIBDIR)/.libs
+querying_CPPFLAGS = -I..
simple_SOURCES = simple.cpp
-simple_LDFLAGS = -lstactiverecord -L$(HEADERDIR)/.libs
+simple_LDFLAGS = -lstactiverecord -L$(LIBDIR)/.libs
+simple_CPPFLAGS = -I..
View
@@ -1,4 +1,4 @@
-#include "stactive_record.h"
+#include "stactiverecord/stactive_record.h"
using namespace stactiverecord;
using namespace std;
@@ -1,4 +1,4 @@
-#include "stactive_record.h"
+#include "stactiverecord/stactive_record.h"
using namespace stactiverecord;
using namespace std;
Sar_Dbi * Sar_Dbi::dbi;
View
@@ -1,4 +1,4 @@
-#include "stactive_record.h"
+#include "stactiverecord/stactive_record.h"
using namespace stactiverecord;
using namespace std;
Sar_Dbi * Sar_Dbi::dbi;
View
@@ -1,4 +1,4 @@
-#include "stactive_record.h"
+#include "stactiverecord/stactive_record.h"
using namespace stactiverecord;
using namespace std;
Sar_Dbi * Sar_Dbi::dbi;
View
@@ -1,4 +1,4 @@
-#include "stactive_record.h"
+#include "stactiverecord/stactive_record.h"
using namespace stactiverecord;
using namespace std;
Sar_Dbi * Sar_Dbi::dbi;
View
@@ -1,4 +1,4 @@
-#include <stactive_record.h>
+#include "stactiverecord/stactive_record.h"
#include <iostream>
using namespace stactiverecord;
using namespace std;
View
@@ -52,7 +52,7 @@ namespace stactiverecord {
/** convert integer to string */
void int_to_string(int i, std::string& s) {
char c_int[100];
- sprintf(c_int, "%ld", i);
+ sprintf(c_int, "%d", i);
s = std::string(c_int);
};

0 comments on commit 25045c9

Please sign in to comment.