Skip to content

Commit a97458e

Browse files
committed
refactored for current code
1 parent 304007a commit a97458e

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed
181 KB
Loading

tutorial/markdown/c++/cxx-quickstart.md

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,10 @@ This will download and install all the dependencies required for the project to
100100
At this point, we have installed the dependencies, loaded the travel-sample data and configured the application with the credentials. The application is now ready and you can run it by executing the following command from the build directory:
101101

102102
```sh
103+
cmake --build .
103104
./cxx_quickstart
104105
```
105-
106+
> Note: Run this command from the build directory
106107
107108
### Verifying the Application
108109

@@ -229,15 +230,12 @@ auto res = Delete(col, doc_id);
229230
### Query
230231
We can use the `Query` function to execute any N1QL (SQL++) query on a scope.
231232
- Executes the N1QL query using the provided `scope.query(query, opts)`.
232-
- Returns the result of the query if successful. The result is returned as a `couchbase::query_results` object.
233+
- Returns the result of the query if successful. The result is added to a `std::vector<std::string>` object that contains the `id, country, avg_rating, title`.
233234
- We can pass `opts` parameter, which can be used to insert positonal parameters in the query.
234235
- If there is an error, it prints an error message and returns an empty result object.
235236

236237
```c++
237238
//operations.cpp
238-
auto [q_err, q_res] = scope.query(query, opts).get();
239-
240-
//main.cpp
241239
std::string query{ R"(
242240
SELECT META(h).id, h AS doc,
243241
AVG(r.ratings.Overall) AS avg_rating
@@ -248,12 +246,13 @@ std::string query{ R"(
248246
ORDER BY avg_rating DESC
249247
LIMIT 5;
250248
)" };
249+
auto [q_err, q_res] = scope.query(query, couchbase::query_options{}.positional_parameters(std::vector<std::string>{"United States", "United Kingdom"})).get();
251250

252-
auto query_res = Query(scope, query, couchbase::query_options{}.positional_parameters(std::vector<std::string>{"United States", "United Kingdom"}));
253-
for (auto& row : query_res.rows_as()) {
254-
std::cout << row["id"].as<std::string>() << " " << row["doc"]["country"].as<std::string>() << std::endl;
255-
std::cout << row["avg_rating"].as<double>() << " " << row["doc"]["title"].as<std::string>() << std::endl;
251+
//main.cpp
252+
for (auto& row : query_res) {
253+
std::cout << row << std::endl;
256254
}
255+
257256
```
258257

259258
### Create Search Index
@@ -309,9 +308,13 @@ auto query = couchbase::conjunction_query{
309308
...
310309
auto [err,res] = scope.search(index_name, couchbase::search_request(query), opts).get();
311310

312-
//main.cpp
313311
for(auto &row:res.rows()){
314-
rows_res.push_back(row.id());
312+
auto fields = row.fields_as<couchbase::codec::tao_json_serializer>();
313+
rows_res.push_back(fields["name"].as<std::string>());
315314
}
316315
return rows_res;
316+
317+
//main.cpp
318+
auto filter_res = Filter(scope, index_name, 50, 1);
319+
std::cout << "Filter result contains:\t" << filter_res.size() << std::endl;
317320
```

0 commit comments

Comments
 (0)