node package manager
Orgs are free. Discover, share, and reuse code in your team. Create a free org »

pouchable

@Pouchable

PouchDB simplified by TypeScript Decorators

npm version Build Status Coverage Status Join the chat at https://gitter.im/pouchable

npm install pouchdb pouchable --save

Include the followings in your project

import * as PouchDB from 'pouchdb';
import { Entity, EntityField, Collection } from 'pouchable'

Declare your Entity

/**
 * Posts 
 */
class Post extends Entity {
 
    @EntityField({
        group: "default",
        name: "title",   
        mandatory: true,
        search_by: [ _.identity ] // need lodash
    })
    title: string;
 
    @EntityField({
        group: "info",
        name: "author"
    })
    author: string;
 
    @EntityField({
        group: "info",
        name: "content",
        validate: (v) => { return v.length < 140 } 
    })
    content: string;
}

Declare your collection:

class Posts extends Collection<Post> {
    public getPrefix(): string {
        return "posts";
    }
}

Pouchable and PouchDB at your service:

let db = new PouchDB("default");
let posts = new Posts(db, Post);
 
posts.insert({ title: "Pouchable is here!!!", author: "Joe"}).then((p) => {
   if (p.title != "Pouchable is here!!!") {
       throw new Error("not really hapenning...");
   }
   console.log(p.title);
}).catch(() => {});

See it in action, our team example:

In this example, you will see a live, up-to-date code that is using pouchable and shows real usecases. https://github.com/sudzy-group/com.sudzy.db

What API is available?

 posts.insert({ title: "Pouchable is here!!!", author: "Joe"}).then().catch(); 
 users.update(u, { street : "23 e 47th, New York, NY"} ).then().catch(); 
 users.get("_user_id").then().catch(); 
 users.remove(u);
 users.find("title", "search title", { startsWith : true });

How Pouchable works under the hood?

Image of Entity

Contributing to Pouchable

Contribution by pull requetsts is more than welcome, feel free to contact us team@sudzy.co

npm install
npm test

Topics to enhance

  • Change build to gulp
  • A simple web-site that will gather community around us
  • Schema documentation generation - see POC at https://goo.gl/xRVl7p
  • Search keys with multiple properties
  • Default value
  • Error handling when partial update happens