You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
56 lines
992 B
56 lines
992 B
import PouchDB from 'pouchdb'
|
|
import PouchDBfind from '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 DatabaseHandler {
|
|
|
|
/**
|
|
*
|
|
*
|
|
*/
|
|
constructor(name) {
|
|
PouchDB.plugin(PouchDBfind)
|
|
|
|
this.db = new PouchDB(name, {
|
|
revs_limit: 0
|
|
})
|
|
}
|
|
|
|
/**
|
|
* adding index for current class
|
|
*
|
|
* @param {array} fields
|
|
*
|
|
*/
|
|
createIndex(fields, name = null) {
|
|
|
|
// adding index
|
|
try {
|
|
|
|
const query = {
|
|
index: {
|
|
fields: fields
|
|
}
|
|
}
|
|
|
|
if (name) {
|
|
query.index.ddoc = name
|
|
}
|
|
|
|
this.db.createIndex(query)
|
|
} catch (error) {
|
|
console.log(error)
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
export default DatabaseHandler |