April 6, 2022
  • All
  • Product
  • couchbase lite
  • Ionic Native

Couchbase Lite v3.0 Provides Enhanced Offline Capabilities for Ionic Apps

Conner Simmons

Product Team

Our recent integration with Couchbase Lite aims to provide offline storage capabilities with minimal effort.

Ionic developers want to build critical apps that work offline and are highly performant. Yet there’s a knowledge gap when it comes to syncing offline data with the cloud and advanced local data management.

Updates for Couchbase Lite v3.0 Integration

Earlier this year, we released an updated integration for Couchbase Lite v3.0. This brings support for N1QL (Nickel) to mobile. N1QL for Mobile is a Couchbase implementation of an emerging SQL-for-JSON query language spec called SQL++. The Couchbase Lite API has been enhanced to support N1QL formatted query strings.

In previous versions, developers would use QueryBuilder (QB), which is described as a “comprehensive fluent interface that allows users to construct queries with SQL-like semantics.” QB is far more robust to write and clunky. Nickel, on the other hand, is more cross-platform compatible and given its SQL-like syntax is very recognizable to developers.

Below is an example of the syntax differences between QueryBuilder and N1QL for Mobile:

QueryBuilder

let query = QueryBuilder
    .select(SelectResult.all())
    .from(DataSource.database(database))
    .where(Expression.property("type")
        .equalTo(Expression.string("account"))
        .and(Expression.property("owner").equalTo("Max")
    )
    .orderBy(Ordering.property("accountSize").ascending())

N1QL for Mobile

let queryStr = `
  SELECT * 
  FROM _ 
  WHERE type="account" 
  AND owner="Max" 
  ORDER BY accountSize ASC
`
let query = database.createQuery(query: queryStr)

The biggest advantage Nickel brings developers is the ability to reuse queries across platforms. This drastically reduces development, testing, and maintenance costs. To ensure web developers have access to these advantages, Ionic’s Couchbase Lite integration has been updated to adopt these improvements. It provides access to the entirety of Couchbase Lite’s functionality, without the need for any native experience.

It’s imperative that mission-critical applications work offline and remain highly performant. However, the knowledge required to implement syncing and advanced local data management can be very high and disrupt product roadmaps. Much like Couchbase Lite (CBL) provides these capabilities so developers can focus on the remaining features of their app, Ionic provides the JavaScript API around CBL to make these capabilities feel great for web developers. With Ionic’s CBL plugin, it’s never been easier to build secure, high-performance, offline-enabled apps.

Want to dive in today? We’ve put together a tutorial that allows you to search and bookmark from a Couchbase Lite database.

Not ready to get started just yet? Watch our recent LinkedIn Live event with Couchbase and Ionic where we talk about solving the 5 biggest challenges in mobile app development.


Conner Simmons

Product Team