Skip to content

Commit db58f61

Browse files
committed
inital commit
0 parents  commit db58f61

File tree

5 files changed

+155453
-0
lines changed

5 files changed

+155453
-0
lines changed

README.md

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
sqlite modern cpp wrapper
2+
====
3+
4+
This library is lightweight wrapper around sqlite C api .
5+
6+
```c++
7+
#include<iostream>
8+
#include "sqlite_modern_cpp.h"
9+
using namespace sqlite;
10+
using namespace std;
11+
12+
int main(){
13+
try {
14+
// creates a database file 'dbfile.db' if not exists
15+
database db("dbfile.db");
16+
17+
// executes the query and creates a 'user' table
18+
db <<
19+
"create table user ("
20+
" age int,"
21+
" name text,"
22+
" weight real"
23+
");";
24+
25+
// inserts a new user and binds the values to ?
26+
// note that only types allowed for bindings are
27+
// 1 - numeric types( int ,long ,long long, float, double , ... )
28+
// 2 - string , wstring
29+
db << "insert into user (age,name,weight) values (?,?,?);"
30+
<< 20
31+
<< "bob"
32+
<< 83.0;
33+
34+
db << "insert into user (age,name,weight) values (?,?,?);"
35+
<< 21
36+
<< L"jak"
37+
<< 68.5;
38+
39+
// slects from table user on a condition ( age > 18 ) and executes
40+
// the body of magid_mapper for every row returned .
41+
// node : magic_mapper is just a simple macro , the next sample is
42+
// equivalent to this one without the use of magic_mapper macro
43+
db << "select age,name,weight from user where age > ? ;"
44+
<< 18
45+
>> magic_mapper(int age, string name, double weight) {
46+
cout << age << ' ' << name << ' ' << weight << endl;
47+
};
48+
49+
db << "select age,name,weight from user where age > ? ;"
50+
<< 18
51+
>> function<void(int,string,double)>([&](int age, string name, double weight) {
52+
cout << age << ' ' << name << ' ' << weight << endl;
53+
});
54+
55+
// i am currently working on a solution to avoid magic mapper
56+
// i future i want to this syntax also work
57+
/*
58+
db << "select age,name,weight from user where age > ? ;"
59+
<< 18
60+
>> [&](int age, string name, double weight) {
61+
cout << age << ' ' << name << ' ' << weight << endl;
62+
};
63+
*/
64+
65+
}
66+
catch (exception& e){
67+
cout << e.what() << endl;
68+
}
69+
}
70+
```

example.cpp

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#include<iostream>
2+
#include "sqlite_modern_cpp.h"
3+
using namespace sqlite;
4+
using namespace std;
5+
6+
int main(){
7+
try {
8+
// creates a database file 'dbfile.db' if not exists
9+
database db("dbfile.db");
10+
11+
// executes the query and creates a 'user' table
12+
db <<
13+
"create table user ("
14+
" age int,"
15+
" name text,"
16+
" weight real"
17+
");";
18+
19+
// inserts a new user and binds the values to ?
20+
// note that only types allowed for bindings are
21+
// 1 - numeric types( int ,long ,long long, float, double , ... )
22+
// 2 - string , wstring
23+
db << "insert into user (age,name,weight) values (?,?,?);"
24+
<< 20
25+
<< "bob"
26+
<< 83.0;
27+
28+
db << "insert into user (age,name,weight) values (?,?,?);"
29+
<< 21
30+
<< L"jak"
31+
<< 68.5;
32+
33+
// slects from table user on a condition ( age > 18 ) and executes
34+
// the body of magid_mapper for every row returned .
35+
// node : magic_mapper is just a simple macro , the next sample is
36+
// equivalent to this one without the use of magic_mapper macro
37+
db << "select age,name,weight from user where age > ? ;"
38+
<< 18
39+
>> magic_mapper(int age, string name, double weight) {
40+
cout << age << ' ' << name << ' ' << weight << endl;
41+
};
42+
43+
db << "select age,name,weight from user where age > ? ;"
44+
<< 18
45+
>> function<void(int,string,double)>([&](int age, string name, double weight) {
46+
cout << age << ' ' << name << ' ' << weight << endl;
47+
});
48+
49+
// i am currently working on a solution to avoid magic mapper
50+
// i future i want to this syntax also work
51+
/*
52+
db << "select age,name,weight from user where age > ? ;"
53+
<< 18
54+
>> [&](int age, string name, double weight) {
55+
cout << age << ' ' << name << ' ' << weight << endl;
56+
};
57+
*/
58+
59+
}
60+
catch (exception& e){
61+
cout << e.what() << endl;
62+
}
63+
}

0 commit comments

Comments
 (0)