Skip to content

Commit

Permalink
worked on comments
Browse files Browse the repository at this point in the history
  • Loading branch information
azaddhirajkumar committed May 29, 2024
1 parent 0bae128 commit 3ecf937
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 25 deletions.
30 changes: 12 additions & 18 deletions docs/Queries/live-queries.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,34 +20,28 @@ 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:

#### 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);
```
2 changes: 2 additions & 0 deletions docs/Queries/query-result-set.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.


2 changes: 0 additions & 2 deletions docs/Queries/sqlplusplus.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
2 changes: 1 addition & 1 deletion docs/blobs.md
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions docs/databases.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions docs/full-text-search.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions docs/scopes-collections.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down

0 comments on commit 3ecf937

Please sign in to comment.