<commit_before>import { Injectable } from '@angular/core';

import PouchDB from 'pouchdb';
import PouchFind from 'pouchdb-find';
PouchDB.plugin(PouchFind);
PouchDB.debug.enable('*');

import { DirectoryItemI } from './directory.service';
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/observable/fromPromise';

interface DbTableMethods {
  create?: Function;
  read?: Function;
  update?: Function;
  delete?: Function;
}

@Injectable()
export class StorageService {
    private _db;

    constructor() {
        this._db = new PouchDB('webphone');
    }

    /**
     * Get table object form local storage
     * @param name Name of the table
     */
    table(name: string): DbTableMethods {
        return {
            create: (data) =>
                Observable.fromPromise(
                    this._db
                        .post( Object.assign({}, data, { type: name} ) )
                )
            ,
            read: () =>
                Observable.fromPromise(
                    this._db
                        .find({
                            selector: { type: name }
                        })
                )
                .map( (x: any) => x.docs )
            ,
            update: (data) =>
                Observable.fromPromise(
                    this._db
                        .get(data._id)
                        .then((doc) =>
                            this._db<commit_msg>The create method returns the original promise of PouchDb, not wrapped in an Observable.<commit_after>import { Injectable } from '@angular/core';

import PouchDB from 'pouchdb';
import PouchFind from 'pouchdb-find';

import { DirectoryItemI } from './directory.service';
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/observable/fromPromise';

PouchDB.plugin(PouchFind);
PouchDB.debug.enable('*');

interface DbTableMethods {
  create?: Function;
  read?: Function;
  update?: Function;
  delete?: Function;
}

@Injectable()
export class StorageService {
    private _db;

    constructor() {
        this._db = new PouchDB('webphone');
    }

    /**
     * Get table object form local storage
     * @param name Name of the table
     */
    table(name: string): DbTableMethods {
        return {
            create: (data) =>
                this._db
                    .post( Object.assign({}, data, { type: name} ) )
            ,
            read: () =>
                Observable.fromPromise(
                    this._db
                        .find({
                            selector: { type: name }
                        })
                )
                .map( (x: any) => x.docs )
            ,
            update: (data) =>
                Observable.fromPromise(
                    this._db
                        .get(data._id)
                        .then((doc) =>
                            this._db
{'fraction_non_alphanumeric': 0.11276891047883414, 'fraction_numerical': 0.0, 'mean_word_length': 1.424726661059714, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6314151', 'n_tokens_mistral': 778, 'n_tokens_neox': 748, 'n_words': 185}