Selecting an Offline Storage Provider

Selecting an Offline Storage Provider

When offline support is enabled, the Backend Services JavaScript SDK needs to store data locally on the device. The options of the Everlive initialization object allow you to select a storage provider as well as specific preferences for each provider.

You can choose between the following storage options:

The following table lists the storage options that are available for each development platform. Check the API Reference for the full list of file system provider options.

Cordova NativeScript Web Node.js
Local Storage
File System
SQLite

Using Local Storage

The Local Storage storage option persists offline data using the standard Local Storage (also Web storage, DOM storage). Note that Local Storage has a size limit that depends on what container runs your app. Most browsers have a limit of 10MB for Local Storage; for Cordova, the limit is 5MB. If you need more than that, consider using another storage mechanism.

The Local Storage option is the default storage option in Cordova and Web.

To configure offline support to use Local Storage:

var el = new Everlive({
    appId: 'your-app-id',
    offline: {
        storage: {
            provider: Everlive.Constants.StorageProvider.LocalStorage
        }
    }
});

Using File System

The File System storage option persists offline data in the device's file system. It is the default storage option in NativeScript and Node.js.

To use the File System storage option in Cordova, enable the File (FileSystem) plugin.

To configure offline support to use File System storage:

var el = new Everlive({
    appId: 'your-app-id',
    offline: {
        storage: {
            provider: Everlive.Constants.StorageProvider.FileSystem
        }
    }
});

Check the API Reference for the full list of file system provider options.

Using SQLite

First introduced in Backend Services JavaScript SDK version 1.9.0

The SQLIte storage option is tailored towards Cordova and NativeScript apps and relies on utilizing a plugin which exposes the SQLite library and engine. More about the SQLite library can be read here.

To use the SQLite storage option in Cordova-based app enable the Cordova-SQLite-storage plugin.

To use the SQLite storage option in a NativeScript-based app enable the NativeScript SQLIte bindings.

Other compatible plugins may be available including plugins that implement data encryption. However, the SQLite offline storage provider has only been tested with the above SQLite bindings.

Initialization Settings

To configure offline support to use SQLite storage you need to add a few settings at the time of initializing the Everlive instance.

  • offline.storage.provider—Specifies the name of the storage provider to be used. Set this to Everlive.Constants.StorageProvider.SQLite to use the SQLite provider.
  • offline.storage.storagePath—Specifies the name which will be used to initialize the database file.
  • offline.typeSettings—Specifies a mapping of attributes that will be used to initialize a local SQLIte table for the desired content types. Define the mapping by constructing a JSON object where the key is the name of the content type and the value is another object where the key Scheme holds an array of the field names and their SQLite storage class mapping.

The following example shows how to enable the provider and then uses the content type structure from the Deliveries sample app to demonstrate type mapping. See the table below for full Telerik Platform to SQL type mapping information.

var el = new Everlive({
    appId: 'your-app-id',
    offline: {
        storage: {
                provider: 'sqlite',
                storagePath: 'deliveries'
            },
            typeSettings: {
                'DeliveryOrder': {
                    'Scheme': [
                        {
                            'Name': 'Status',
                            'Type': 'INT'
                        },
                        {
                            'Name': 'Comments',
                            'Type': 'TEXT'
                        },
                        {
                            'Name': 'DeliveryItem',
                            'Type': 'TEXT'
                        },
                        {
                            'Name': 'DeliveryItemType',
                            'Type': 'TEXT'
                        },
                        {
                            'Name': 'DeliveryName',
                            'Type': 'TEXT'
                        },
                        {
                            'Name': 'DeliveryAddressCity',
                            'Type': 'TEXT'
                        },
                        {
                            'Name': 'DeliveryAddressLine1',
                            'Type': 'TEXT'
                        },
                        {
                            'Name': 'DeliveryAddressPostcode',
                            'Type': 'TEXT'
                        },
                        {
                            'Name': 'DeliveryAddressLine2',
                            'Type': 'TEXT'
                        }
                    ]
                }
            }
    }
});

Type Mappings

The following table gives the recommended Telerik Platform to SQL type mappings. All system values such as Id, CreatedAt, Owner, and so on are mapped automatically and need to be left out of the Scheme description.

Telerik Platform Data Type SQL Data Type
Text TEXT
Number INT, FLOAT
Date and Time DATE
Yes/No BOOLEAN
Geo Point Not supported
File TEXT
Relation TEXT
Object OBJECT*
Array ARRAY*
Relation: multiple ARRAY*

* In stringified form which may hinder searching.

Limitations

The following limitations apply to the SQLite storage provider.

  • The NULL SQL value is not supported.
  • Caching is not supported when using the SQLite storage provider. Ensure you have caching: false set in your Everlive instance.

See Also

Start a free trial Request a demo
Contact us: +1-888-365-2779
sales@telerik.com
Copyright © 2016-2017, Progress Software Corporation and/or its subsidiaries or affiliates. All rights reserved.