Typescript repository for PouchDB. This library includes type definitions for PouchDB including strong type repository class.
npm install pouchdb-repository --save
This library is designed to use with Typescript. For example, you have a model called Foo
.
interface Foo {
_id: string;
name: string;
}
You can create FooRepository
by overriding Repository
class FooRepository extends Repository<Foo> {
constructor() {
super('foo');
}
}
let repo = new FooRepository();
You can insert of update by save
method.
repo.save({ _id: 'foo1', name: 'bar' });
If id is found in database, record will be updated, otherwise it will be inserted.
You can get item by passing the id.
let foo = await repo.get('foo1');
Type you get from this repo will always be Foo
.
repo.remove(foo);
An object will be removed from db.
repo.saveAll([foo1, foo2]);
All objects will perform upsert operation.
repo.removeAll([foo1, foo2]);
All specified objects will be removed from db.
Query
options is from pouchdb-find. This library also includes typing definition.
let results = await repo.query({
selector: { name: 'Mario' }
});