Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alternative iterator interface #126

Merged
merged 11 commits into from
Feb 5, 2018
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,26 @@ int main() {

cout << "The new record got assigned id " << db.last_insert_rowid() << endl;

// slects from user table on a condition ( age > 18 ) and executes
// selects from user table on a condition ( age > 18 ) and executes
// the lambda for each row returned .
db << "select age,name,weight from user where age > ? ;"
<< 18
>> [&](int age, string name, double weight) {
cout << age << ' ' << name << ' ' << weight << endl;
};

// a for loop can be used too:
// with named variables
for(auto &&row : db << "select age,name,weight from user where age > ? ;" << 18) {
int age; string name; double weight;
row >> age >> name >> weight;
cout << age << ' ' << name << ' ' << weight << endl;
}
// or with a tuple
for(tuple<int, string, double> row : db << "select age,name,weight from user where age > ? ;" << 18) {
cout << get<0>(row) << ' ' << get<1>(row) << ' ' << get<2>(row) << endl;
}

// selects the count(*) from user table
// note that you can extract a single culumn single row result only to : int,long,long,float,double,string,u16string
int count = 0;
Expand Down
Loading