0.6.1 • Published 7 years ago

pouchdb-repository v0.6.1

Weekly downloads
4
License
MIT
Repository
github
Last release
7 years ago

pouchdb-repository

Typescript repository for PouchDB. This library includes type definitions for PouchDB including strong type repository class.

Install

npm install pouchdb-repository --save

Getting started

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();

Operations

Insert or update (Upsert)

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.

Get one

You can get item by passing the id.

let foo = await repo.get('foo1');

Type you get from this repo will always be Foo.

Remove

repo.remove(foo);

An object will be removed from db.

Save all

repo.saveAll([foo1, foo2]);

All objects will perform upsert operation.

Remove all

repo.removeAll([foo1, foo2]);

All specified objects will be removed from db.

Query

Query options is from pouchdb-find. This library also includes typing definition.

let results = await repo.query({
  selector: { name: 'Mario' }
});
0.6.1

7 years ago

0.6.0

7 years ago

0.5.1

7 years ago

0.5.0

7 years ago

0.4.1

7 years ago

0.4.0

7 years ago

0.3.2

7 years ago

0.3.1

8 years ago

0.3.0

8 years ago

0.2.0

8 years ago

0.1.1

8 years ago

0.1.0

8 years ago