const PouchDB = require('pouchdb')
const PouchDBfind = require('pouchdb-find')

/**
 *  PouchdbHandler, for create
 *
 *  @author Björn Hase
 *  @license https://www.gnu.org/licenses/gpl-3.0.en.html GPL-3
 *  @link https://gitea.node001.net/HerrHase/potato-launcher.git
 *
 */

class PouchdbHandler {

    /**
     *
     *
     */
    constructor() {
        PouchDB.plugin(PouchDBfind)

        this.db = new PouchDB('.storage/pouchdb/apps', {
            revs_limit: 0
        })
    }

    /**
     *  adding index for current class
     *
     *  @param  {array} fields
     *
     */
    createIndex(fields) {

        // adding index
        try {
            this.db.createIndex({
                index: {
                    fields: fields
                }
            }).then(() => {

            })
        } catch (error) {
            console.log(error)
        }
    }
}

module.exports.PouchdbHandler = PouchdbHandler