PouchDB simplified by TypeScript Decorators
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(() => {});
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
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 });
![Image of Entity] (https://raw.githubusercontent.com/sudzy-group/pouchable/master/resources/pouchable_entity.png)
Contribution by pull requetsts is more than welcome, feel free to contact us [email protected]
npm install npm test
- 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