SapphireDb logo SapphireDb

Offline support

SapphireDb support offline usage and can store and load data from a local storage.
Changes made offline and online will be synced and automatically merged.

Basic setup

To enable offline support just activate the option offlineSupport in your client application.
\f:(typescript:JS) var sapphiredb = require('sapphiredb');\n\n var db = new sapphiredb.SapphireDb({\n \tofflineSupport: true\n });

Setup storage

To store data locally and benefit from offline support you have to provide a storage. For normal browsers you can use SapphireLocalStorage. For other environments you should implement a custom storage provider.
\f:(typescript:JS) var sapphiredb = require('sapphiredb');\n\n var db = new sapphiredb.SapphireDb({\n \tofflineSupport: true,\n }, new sapphiredb.SapphireLocalStorage());
In angular you can provide the custom storage as SapphireStorage in providers of your module

Prepare models

Without configuring anything SapphireDb can already store collection state and local operations. But it will not be possible to create new values in a collection and update them without going online again.
To use that you have to generate some sort of id on client side when creating new values. (UUIDs/GUIDs are ideal for that)
Use the class SapphireOfflineEntity in every model that should work offline. It has an auto generated id property and a timestamp for concurrency conflict detection.
\f:(csharp:Entry.cs) // Server side usage\n public class DemoEntry : SapphireOfflineEntity\n {\n \tpublic string Content { get; set; }\n } \f:(typescript:entry.ts) // Client side usage\n class Entry extends SapphireOfflineEntity {\n\n }

Conflict handling

SapphireDb can handle a lot of conflicts automatically. Check out Conflict handling to learn more.

Note

  • Server side model validation will only get executed on server side. It is possible to insert invalid values on client side that are rejected later.
    Add additional client side validation to avoid that
  • Some prefilters like First, Last, Count etc. will online work limited offline. The state before going offline will get stored but operations on the collection will first take effect when going online again.
  • The prefilters Skip and Take will have no effect when offline. If you add new values they are always displayed by the prefilter.
  • Every collection value with different prefilters is stored in a different storage. That can result in sometimes different values when using different prefilters. To avoid that only use one combination of prefilters in one scope of the application.

This website uses Google Analytics. If you want to disable it just unselect the option: