Skip to content

Commit 4a60818

Browse files
authored
Add CBL-C Code Snippet for query-access-json tag (#537)
* Added CBL-C Code Snippet for query-access-json tag * Removed the placeholder for query-index[] and fts-index[] as the code snippet has already been provided.
1 parent 4293bc3 commit 4a60818

File tree

1 file changed

+29
-13
lines changed
  • modules/c/examples/code_snippets

1 file changed

+29
-13
lines changed

modules/c/examples/code_snippets/main.c

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -863,6 +863,31 @@ static void test_explain_statement() {
863863
// DOCS NOTE: Others omitted for now
864864
}
865865

866+
static void query_result_json() {
867+
CBLDatabase* db = kDatabase;
868+
869+
CBLError err;
870+
CBLQuery* query = CBLDatabase_CreateQuery(db, kCBLN1QLLanguage,
871+
FLSTR("SELECT meta().id as id, name, city, type FROM _ LIMIT 10"),
872+
NULL, &err);
873+
874+
// tag::query-access-json[]
875+
// NOTE: No error handling, for brevity (see getting started)
876+
877+
CBLResultSet* results = CBLQuery_Execute(query, &err);
878+
while(CBLResultSet_Next(results)) {
879+
FLDict result = CBLResultSet_ResultDict(results);
880+
FLStringResult json = FLValue_ToJSON((FLValue)result);
881+
printf("JSON Result :: %.*s\n", (int)json.size, (const char *)json.buf);
882+
FLSliceResult_Release(json);
883+
}
884+
CBLResultSet_Release(results);
885+
886+
// end::query-access-json[]
887+
888+
CBLQuery_Release(query);
889+
}
890+
866891
static void create_full_text_index() {
867892
CBLDatabase* db = kDatabase;
868893

@@ -1040,6 +1065,7 @@ int main(int argc, char** argv) {
10401065
select_join();
10411066
group_by();
10421067
order_by();
1068+
query_result_json();
10431069

10441070
create_full_text_index();
10451071
full_text_search();
@@ -1058,23 +1084,13 @@ int main(int argc, char** argv) {
10581084

10591085

10601086
// tag::console-logging-db[]
1061-
Placeholder for code to increase level of console logging for kCBLLogDomainDatabase domain
1087+
// Placeholder for code to increase level of console logging for kCBLLogDomainDatabase domain
10621088
// end::console-logging-db[]
10631089

10641090
// tag::console-logging[]
1065-
Placeholder for code to increase level of console logging for all domains
1091+
// Placeholder for code to increase level of console logging for all domains
10661092
// end::console-logging[]
10671093

10681094
// tag::date-getter[]
1069-
Placeholder for Date accessors.
1070-
1095+
// Placeholder for Date accessors.
10711096
// end::date-getter[]
1072-
1073-
1074-
// tag::query-index[]
1075-
// placeholder
1076-
// end::query-index[]
1077-
1078-
// tag::fts-index[]
1079-
// placeholder
1080-
// end::fts-index[]

0 commit comments

Comments
 (0)