Services

The first thing we need to create is the database service that connects to PouchDB and provides different methods to work with the employees database. We can create a service provider using ionic g provider

Make sure you are inside the project's root folder then run the following:

ionic g provider employee

You should have an EmployeeProvider provider generated inside src/providers/employee folder.
Now replace the code in employee.ts with :

 import cordovaSqlitePlugin from 'pouchdb-adapter-cordova-sqlite';
 import { Injectable } from '@angular/core';
 import 'rxjs/add/operator/map';
 import PouchDB from 'pouchdb';

 @Injectable()
 export class EmployeeProvider {

   public pdb;
   employees;

   createPouchDB() {
     PouchDB.plugin(cordovaSqlitePlugin);
     this.pdb = new PouchDB('employee.db', {
       adapter: 'cordova-sqlite',
       iosDatabaseLocation: 'Library',
       androidDatabaseImplementation: 2
     });
   }
 }

This creates a SQLite database file named employees.db and initializes the PouchDB database by setting the adapter to cordova-sqlite which instructs PouchDB to use SQLite for storage instead of browser's storage. Make sure to import the provider into src/app/app.module.ts and add it to the providers array if it's not added automatically. Also make sure to import the service provider and inject it in the constructor of any component before you can use it.
Now create the CRUD methods in EmployeeProvider.
First the create method :

 create(employee) {
   return this.pdb.post(employee);
 }

post() is a PouchDB API that allows you to create new objects in the PouchDB database.
Now the update method :

 update(employee) {
   return this.pdb.put(employee);
 }

Next the delete method :

 delete(employee) {
   return this.pdb.remove(employee);
 }

And finally the read method :

 read() {
   let pdb = this.pdb;

   function allDocs() {

     let _employees = pdb.allDocs({ include_docs: true })
       .then(docs => {
         return docs.rows;
       });

     return Promise.resolve(_employees);
   };
   return allDocs();
 }

This gets all employees from the database by invoking the allDocs() method which returns a promise that resolves to an array of all employees in the database. The map() function then maps the array to rows which contain the documents itself (and not other PouchDB specific data). The code also converts row.doc.Date (stored as JSON ) to JavaScript Date().