From 3ecf937e74b98823a98a86b17d331a34d4da6d91 Mon Sep 17 00:00:00 2001 From: Dhiraj Kumar Azad Date: Wed, 29 May 2024 13:20:02 +0530 Subject: [PATCH] worked on comments --- docs/Queries/live-queries.md | 30 ++++++++++++------------------ docs/Queries/query-result-set.md | 2 ++ docs/Queries/sqlplusplus.md | 2 -- docs/blobs.md | 2 +- docs/databases.md | 4 ++-- docs/full-text-search.md | 5 +++-- docs/scopes-collections.md | 3 +++ 7 files changed, 23 insertions(+), 25 deletions(-) diff --git a/docs/Queries/live-queries.md b/docs/Queries/live-queries.md index af70cdf..5b4c76e 100644 --- a/docs/Queries/live-queries.md +++ b/docs/Queries/live-queries.md @@ -20,24 +20,21 @@ With Couchbase Lite for Ionic, live queries can be watched through: Each time you start watching a live query, the query is executed and an initial change notification is dispatched. The query is then kept active and further change notifications are dispatched whenever a change occurs. -## Watching with Change Listeners - -In the case of the synchronous API, all changes are delivered to the listeners as soon as they are registered. - -With the asynchronous API, changes are only guaranteed to be delivered once the `Promise` returned from the registration call is completed: - #### Example 1. Starting a Live Query - Change Listener ```typescript // Register a change listener and await the Promise returned from the registration call. -await query.addChangeListener(async (change) => { - // Await the results of the change. - const results = await change.results; - - results.forEach(result => { - // Do something with the result... - }); -}); +const token = await query.addChangeListener((change) => { + if (change.error !== null && change.error !== undefined) { + // deal with error... + } else { + const results = change.results; + //loop through ResultSet + for (const doc of results) { + //do something with doc + } + } +}); ``` To stop receiving notifications, call `Query.removeChangeListener` with the token that was returned from the registration call. Regardless of the whether the API is synchronous or asynchronous, listeners will stop receiving notifications immediately: @@ -45,9 +42,6 @@ To stop receiving notifications, call `Query.removeChangeListener` with the toke #### Example 2. Stopping a Live Query - Change Listener ```typescript -final token = await query.addChangeListener((change) async { ... }); - -// Some time goes by... - +const token = await query.addChangeListener((change) => { ... }); await query.removeChangeListener(token); ``` \ No newline at end of file diff --git a/docs/Queries/query-result-set.md b/docs/Queries/query-result-set.md index 7c49e9e..b328650 100644 --- a/docs/Queries/query-result-set.md +++ b/docs/Queries/query-result-set.md @@ -19,3 +19,5 @@ for (const result of resultSet) { ``` In this example, `hotelItems` is the alias used for the collection in the query, and it serves as the key in the `Result` objects within the `ResultSet`. + + diff --git a/docs/Queries/sqlplusplus.md b/docs/Queries/sqlplusplus.md index eb72e96..d8a70ff 100644 --- a/docs/Queries/sqlplusplus.md +++ b/docs/Queries/sqlplusplus.md @@ -27,8 +27,6 @@ const query = database.createQuery('SELECT META().id AS thisId FROM inventory.ho const resultSet = await query.execute(); ``` -Here we are accessing the default collection using the shorthand notation (`_`) — see the FROM clause for more on data source selection and Query Parameters for more on parameterized queries. - ## Query Format The API uses query statements of the form shown in [Example 2](#example-2-query-format). diff --git a/docs/blobs.md b/docs/blobs.md index 994e282..90f97fd 100644 --- a/docs/blobs.md +++ b/docs/blobs.md @@ -50,7 +50,7 @@ const imageData = await fetchAvatarImageData(); const avatarBlob = new Blob('image/jpeg', imageData); // Retrieve an existing document -let document = await collection.document(documentId); +const document = await collection.document(documentId); // Assign the Blob to the document under the 'avatar' key document.setBlob('avatar', avatarBlob); diff --git a/docs/databases.md b/docs/databases.md index 10f7087..841f583 100644 --- a/docs/databases.md +++ b/docs/databases.md @@ -66,12 +66,12 @@ This configuration ensures seamless interaction between your Ionic app and the u ### Create or Open a Database -To create or open a database, use the Database class from the cbl-cblite package, specifying the database name and optionally, a DatabaseConfiguration for custom settings like the database directory or encryption. +To create or open a database, use the Database class from the cblite package, specifying the database name and optionally, a DatabaseConfiguration for custom settings like the database directory or encryption. **Example 1. Creating/Opening a Database** ```javascript -import { Database, DatabaseConfiguration } from 'cbl-cblite'; //import the package +import { Database, DatabaseConfiguration } from 'cblite'; //import the package ``` ```javascript diff --git a/docs/full-text-search.md b/docs/full-text-search.md index 527239d..d10e9ba 100644 --- a/docs/full-text-search.md +++ b/docs/full-text-search.md @@ -50,9 +50,10 @@ const ftsQueryString = ` const ftsQuery = database.createQuery(ftsQueryString); const results = await ftsQuery.execute(); -results.forEach(result => { + +for(const result of results) { console.log(result.getString('_id') + ": " + result.getString('overview')); -}); +} ``` ## Operation diff --git a/docs/scopes-collections.md b/docs/scopes-collections.md index 2707a2a..604a125 100644 --- a/docs/scopes-collections.md +++ b/docs/scopes-collections.md @@ -50,8 +50,11 @@ Scope and collection names are case sensitive. **Example 1. Create a scope and collection** ```typescript +const scopeName = "myScopeName"; +const collectionName = "myCollectionName"; const collection = await database.createCollection(collectionName, scopeName); ``` + In the example above, you can see that `Database.createCollection` can take two parameters. The second is the scope assigned to the created collection, if this parameter is omitted then a collection of the given name will be assigned to the `_default` scope. The first parameter is the name of the collection you want to create, in this case `myCollectionName`.