Implementing DatabaseService

Our DatabaseService needs to provide several things:

  • A persistent store to save and retrieve any data our app needs.
  • It should allow any type of data to be stored; however, we will specifically want it to handle JSON serialization.
  • Static keys of all the data we will want to store. 
  • A static reference to a saved user? Well, yes it could. However, this brings up a point that we will address in a moment.

Regarding the first item, we can use NativeScript's application-settings module. Under the hood, this module provides a consistent API to work with two native mobile APIs:

Get NativeScript for Angular Mobile Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.