Skip to content

Commit 0f44e37

Browse files
committed
DOC-12533: Feedback on Language Constructs (#297)
* Update Analytics function name and example * Let AsciiDoc generate link text where possible * Prevent awkward line break in the page ToC * Updates after review * Beautify JavaScript example
1 parent 1ede88d commit 0f44e37

File tree

1 file changed

+38
-49
lines changed

1 file changed

+38
-49
lines changed

modules/eventing/pages/eventing-language-constructs.adoc

Lines changed: 38 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ Certain capabilities have been removed and are not supported in order to handle
1515

1616
Eventing Functions support the following features:
1717

18-
* <<basic_bucket_accessors,Basic Keyspace Accessors>>
19-
* <<advanced_bucket_accessors,Advanced Keyspace Accessors>>
20-
* <<logging,Logging>>
21-
* <<n1ql_statements,{sqlpp} Statements>>
18+
* <<basic_bucket_accessors>>
19+
* <<advanced_bucket_accessors>>
20+
* <<logging>>
21+
* <<n1ql_statements>>
2222
2323
[#basic_bucket_accessors]
2424
=== Basic Keyspace Accessors
@@ -77,7 +77,7 @@ function OnUpdate(doc, meta) {
7777
Advanced Keyspace Accessors expose a larger set of options and operators than <<basic_bucket_accessors,Basic Keyspace Accessors>>.
7878
They have non-trivial argument sets and return values.
7979

80-
See xref:eventing-advanced-keyspace-accessors.adoc[Advanced Keyspace Accessors] for more details.
80+
See xref:eventing-advanced-keyspace-accessors.adoc[] for more details.
8181

8282
[#logging]
8383
=== Logging
@@ -198,10 +198,10 @@ To include comments in multiline statements, use `/* this format */` instead.
198198

199199
The following features are not supported by Eventing Functions:
200200

201-
* <<global-state,Global State>>
202-
* <<asynchrony,Asynchrony>>
203-
* <<browser_extensions,Browser and Other Extensions>>
204-
* <<library_imports,Library Imports>>
201+
* <<global-state>>
202+
* <<asynchrony>>
203+
* <<browser_extensions>>
204+
* <<library_imports>>
205205

206206
[#global-state]
207207
=== Global State
@@ -266,13 +266,13 @@ The Eventing Service does not support importing libraries into Eventing Function
266266

267267
Eventing Functions support the following built-in functions:
268268

269-
* <<n1ql_call,`N1QL()`>>
270-
* <<analytics_call,`ANALYTICS()`>>
271-
* <<crc64_call,`crc64()`>>
272-
* <<crc_64_go_iso_call, `crc_64_go_iso()`>>
273-
* <<base64_call,`base64()`>>
274-
* <<timers_general,`createTimer()` and `cancelTimer()`>>
275-
* <<curl_call,`curl()`>>
269+
* <<n1ql_call>>
270+
* <<analytics_call>>
271+
* <<crc64_call>>
272+
* <<crc_64_go_iso_call>>
273+
* <<base64_call>>
274+
* <<timers_general>>
275+
* <<curl_call>>
276276

277277
[#n1ql_call]
278278
=== `N1QL()`
@@ -378,53 +378,42 @@ The `close()` method on the iterable handle can throw an exception if the underl
378378
|===
379379

380380
[#analytics_call]
381-
=== `ANALYTICS()`
381+
=== `couchbase.{zwsp}analyticsQuery({wj})`
382382

383383
ifeval::['{page-component-version}' == '7.6']
384-
385384
[.status]#Introduced in Couchbase Server 7.6#
386385
endif::[]
387386

388-
The `ANALYTICS()` function provides integration with {sqlpp} Analytics directly from the Eventing Service.
387+
The `couchbase.analyticsQuery()` function provides integration with {sqlpp} Analytics directly from the Eventing Service.
389388

390389
Integrating Eventing with Analytics:
391390

392391
* Allows Eventing to benefit from the high availability and load balancing of Analytics, where requests can take turns being submitted across nodes
393392
* Simplifies Eventing code logic and improves code readability
394393
* Eliminates security and network latency issues with the `curl()` function
395394

395+
The following example assumes that the Analytics collection (dataset) called `default` already exists.
396+
396397
[source,javascript]
397398
----
398399
function OnUpdate(doc, meta) {
399-
// Ignore information we don't care about
400-
if (doc.type !== 'airline') return;
401-
402-
// Get the total routes per IATA
403-
var route_cnt = 0;
404-
// Uses a true variable as a SQL++ parameter
405-
var airline = doc.iata;
406-
407-
var results = ANALYTICS(
408-
"SELECT COUNT(*) AS cnt
409-
FROM `travel-sample`.`inventory`.`route`
410-
WHERE type = \"route\"
411-
AND airline = $1", [doc.iata]
412-
);
413-
414-
// Stream results using the 'for' iterator
415-
for (var item of results) {
416-
route_cnt = item.cnt;
400+
var count = 0;
401+
const limit = 4;
402+
403+
let query = couchbase.analyticsQuery('SELECT * FROM default LIMIT $limit;', {
404+
"limit": limit
405+
});
406+
for (let row of query) {
407+
++count;
417408
}
418409
419-
// End the query and free the resources held
420-
results.close();
421-
422-
// Log the KEY, AIRLINE and ROUTE_CNT
423-
log("key: " + meta.id + ", airline: " + doc.iata + ", route_cnt: " + route_cnt);
410+
if (count === limit) {
411+
dst_bucket[meta.id] = 'yes';
412+
}
424413
}
425414
----
426415

427-
For more information about {sqlpp} Analytics, see xref:server:analytics:1_intro.adoc[What’s SQL++ for Analytics?].
416+
For more information about {sqlpp} Analytics, see xref:server:analytics:1_intro.adoc[].
428417

429418
[#crc64_call]
430419
=== `crc64()`
@@ -558,24 +547,24 @@ To cancel a Timer, you can do one of the following:
558547
* Call the `createTimer()` function again using a reference from the existing Timer you want to cancel.
559548
* Call the `cancelTimer()` function using `cancelTimer(callback, reference)`.
560549

561-
For more information about Timers, see xref:eventing-timers.adoc[Timers].
550+
For more information about Timers, see xref:eventing-timers.adoc[].
562551

563552
[#curl_call]
564553
=== `curl()`
565554

566555
The `curl()` function lets you interact with external entities through a REST endpoint from Eventing Functions, using either HTTP or HTTPS.
567556

568-
For more information about the `curl()` function, see xref:eventing-curl-spec.adoc[cURL].
557+
For more information about the `curl()` function, see xref:eventing-curl-spec.adoc[].
569558

570559

571560
[#handler-signatures]
572561
== Handler Signatures
573562

574563
The Eventing Service calls the following JavaScript functions on events like mutations and fired Timers:
575564

576-
* <<onupdate_handler,OnUpdate Handler>>
577-
* <<ondelete_handler,OnDelete Handler>>
578-
* <<timer_callback_handler,Timer Callback Handler>>
565+
* <<onupdate_handler>>
566+
* <<ondelete_handler>>
567+
* <<timer_callback_handler>>
579568

580569
[#onupdate_handler]
581570
=== OnUpdate Handler
@@ -664,7 +653,7 @@ function OnUpdate(doc, meta) {
664653
}
665654
----
666655

667-
For more information about Timers, see xref:eventing-timers.adoc[Timers].
656+
For more information about Timers, see xref:eventing-timers.adoc[].
668657

669658

670659
== Reserved Words

0 commit comments

Comments
 (0)