@@ -51,15 +51,16 @@ In this mode, a table is created with just 2 columns, `key` and `value` as shown
5151
5252``` c++
5353#include " sqlite_index_blaster.h"
54+ #include < string>
55+ #include < vector>
5456
5557int main () {
5658
57- // Use new and delete to have control of when the database is closed
58- sqlite_index_blaster *sqib = new sqlite_index_blaster(2, 1,
59- (const char *[]) {"key", "value"}, "kv_index", 4096, 40, "kv_idx.db");
60- sqib->put("hello", 5, "world", 5);
61- delete sqib; // Close kv_kdx.db
59+ std::vector<std::string> col_names = {"key", "value"}; // -std >= c++11
60+ sqlite_index_blaster sqib(2, 1, col_names, "kv_index", 4096, 40, "kv_idx.db");
61+ sqib.put_string("hello", "world");
6262 return 0;
63+ // db file is flushed and closed when sqib is destroyed
6364
6465}
6566```
@@ -84,18 +85,14 @@ To retrieve the inserted values, use `get` method as shown below
8485
8586``` c++
8687#include " sqlite_index_blaster.h"
88+ #include < string>
89+ #include < vector>
8790
8891int main () {
89- sqlite_index_blaster *sqib = new sqlite_index_blaster(2, 1,
90- (const char *[]) {"key", "value"}, "kv_index", 4096, 40, "kv_idx.db");
91- sqib->put("hello", 5, "world", 5);
92- char out_val[10];
93- int out_val_len = 10;
94- if (sqib->get("hello", 5, &out_val_len, out_val)) {
95- out_val[out_val_len] = '\0';
96- cout << "Value of hello is " << out_val << endl;
97- }
98- delete sqib;
92+ std::vector<std::string> col_names = {"key", "value"}; // -std >= c++11
93+ sqlite_index_blaster sqib(2, 1, col_names, "kv_index", 4096, 40, "kv_idx.db");
94+ sqib.put_string("hello", "world");
95+ cout << "Value of hello is " << sqib.get_string("hello", "not_found") << endl;
9996 return 0;
10097}
10198```
@@ -106,16 +103,17 @@ In this mode, a table is created with just 2 columns, `key` and `doc` as shown b
106103
107104``` c++
108105#include " sqlite_index_blaster.h"
106+ #include < string>
107+ #include < vector>
109108
110109const char * json1 = " {\" name\" : \" Alice\" , \" age\" : 25, \" email\" : \" alice@example.com\" }" ;
111110const char * json2 = " {\" name\" : \" George\" , \" age\" : 32, \" email\" : \" george@example.com\" }" ;
112111
113112int main () {
114- sqlite_index_blaster *sqib = new sqlite_index_blaster(2, 1,
115- (const char *[]) {"key", "doc"}, "doc_index", 4096, 40, "doc_store.db");
116- sqib->put("primary_contact", 15, json1, strlen(json1));
117- sqib->put("secondary_contact", 17, json2, strlen(json2));
118- delete sqib;
113+ std::vector<std::string> col_names = {"key", "doc"}; // -std >= c++11
114+ sqlite_index_blaster sqib(2, 1, col_names, "doc_index", 4096, 40, "doc_store.db");
115+ sqib.put_string("primary_contact", json1);
116+ sqib.put_string("secondary_contact", json2);
119117 return 0;
120118}
121119```
@@ -134,34 +132,35 @@ This repo can be used to create regular tables with primary key(s) as shown belo
134132
135133``` c++
136134#include < cmath>
135+ #include < string>
136+ #include < vector>
137+
137138#include " sqlite_index_blaster.h"
138139
139140const uint8_t col_types[] = {SQLT_TYPE_TEXT, SQLT_TYPE_INT8, SQLT_TYPE_INT8, SQLT_TYPE_INT8, SQLT_TYPE_INT8, SQLT_TYPE_REAL};
140141
141142int main() {
142143
143- sqlite_index_blaster *sqib = new sqlite_index_blaster(6, 2,
144- (const char *[]) {"student_name", "age", "maths_marks", "physics_marks", "chemistry_marks", "average_marks"},
145- "student_marks", 4096, 40, "student_marks.db");
144+ std::vector<std::string> col_names = {"student_name", "age", "maths_marks", "physics_marks", "chemistry_marks", "average_marks"};
145+ sqlite_index_blaster sqib(6, 2, col_names, "student_marks", 4096, 40, "student_marks.db");
146146
147147 int8_t maths, physics, chemistry, age;
148148 double average;
149149 uint8_t rec_buf[500];
150150 int rec_len;
151151
152152 age = 19; maths = 80; physics = 69; chemistry = 98; average = round((maths + physics + chemistry) * 100 / 3) / 100;
153- rec_len = sqib-> make_new_rec(rec_buf, 6, (const void *[]) {"Robert", &age, &maths, &physics, &chemistry, &average}, NULL, col_types);
154- sqib-> put(rec_buf, -rec_len, NULL, 0);
153+ rec_len = sqib. make_new_rec(rec_buf, 6, (const void *[]) {"Robert", &age, &maths, &physics, &chemistry, &average}, NULL, col_types);
154+ sqib. put(rec_buf, -rec_len, NULL, 0);
155155
156156 age = 20; maths = 82; physics = 99; chemistry = 83; average = round((maths + physics + chemistry) * 100 / 3) / 100;
157- rec_len = sqib-> make_new_rec(rec_buf, 6, (const void *[]) {"Barry", &age, &maths, &physics, &chemistry, &average}, NULL, col_types);
158- sqib-> put(rec_buf, -rec_len, NULL, 0);
157+ rec_len = sqib. make_new_rec(rec_buf, 6, (const void *[]) {"Barry", &age, &maths, &physics, &chemistry, &average}, NULL, col_types);
158+ sqib. put(rec_buf, -rec_len, NULL, 0);
159159
160160 age = 23; maths = 84; physics = 89; chemistry = 74; average = round((maths + physics + chemistry) * 100 / 3) / 100;
161- rec_len = sqib-> make_new_rec(rec_buf, 6, (const void *[]) {"Elizabeth", &age, &maths, &physics, &chemistry, &average}, NULL, col_types);
162- sqib-> put(rec_buf, -rec_len, NULL, 0);
161+ rec_len = sqib. make_new_rec(rec_buf, 6, (const void *[]) {"Elizabeth", &age, &maths, &physics, &chemistry, &average}, NULL, col_types);
162+ sqib. put(rec_buf, -rec_len, NULL, 0);
163163
164- delete sqib;
165164 return 0;
166165}
167166```
@@ -233,7 +232,7 @@ Valentine's Day,Comedy,Warner Bros.
233232
234233This code has been tested with more than 200 million records, so it is expected to be quite stable, but bear in mind that this is so fast because there is no crash recovery.
235234
236- So this repo is best suited for one time inserts of large datasets, power backed systems such as those hosted in Cloud and battery backed systems.
235+ So this repo is best suited for one time inserts of large datasets. It may be suitable for power backed systems such as those hosted in Cloud and battery backed systems.
237236
238237# License
239238
0 commit comments