Skip to content

Commit fde544f

Browse files
committed
Added example to README
1 parent e761452 commit fde544f

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

README.md

+13-1
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,26 @@ int main() {
4848

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

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

59+
// a for loop can be used too:
60+
// with named variables
61+
for(auto &&row : db << "select age,name,weight from user where age > ? ;" << 18) {
62+
int age; string name; double weight;
63+
row >> age >> name >> weight;
64+
cout << age << ' ' << name << ' ' << weight << endl;
65+
}
66+
// or with a tuple
67+
for(tuple<int, string, double> row : db << "select age,name,weight from user where age > ? ;" << 18) {
68+
cout << get<0>(row) << ' ' << get<1>(row) << ' ' << get<2>(row) << endl;
69+
}
70+
5971
// selects the count(*) from user table
6072
// note that you can extract a single culumn single row result only to : int,long,long,float,double,string,u16string
6173
int count = 0;

0 commit comments

Comments
 (0)