-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
215 additions
and
130 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,108 @@ | ||
# pouchdb-hoodie-api | ||
|
||
> PouchDB plugin that provides Hoodie's store API | ||
[![Build Status](https://travis-ci.org/boennemann/pouchdb-hoodie-api.svg?branch=master)](https://travis-ci.org/boennemann/pouchdb-hoodie-api) | ||
[![Coverage Status](https://coveralls.io/repos/boennemann/pouchdb-hoodie-api/badge.svg)](https://coveralls.io/r/boennemann/pouchdb-hoodie-api) | ||
[![Dependency Status](https://david-dm.org/boennemann/pouchdb-hoodie-api.svg)](https://david-dm.org/boennemann/pouchdb-hoodie-api) | ||
[![NPM](https://nodei.co/npm/pouchdb-hoodie-api.png?downloads=true&downloadRank=true&stars=true)](https://nodei.co/npm/pouchdb-hoodie-api/) | ||
|
||
This plugin provides simple methods to add, find, update and remove data. | ||
|
||
## Usage | ||
|
||
```js | ||
PouchDB.plugin(hoodieApi) | ||
var db = new PouchDB('dbname') | ||
var api = db.hoodieApi() | ||
|
||
// all methods return promises | ||
api.add(object) | ||
api.add([object1, object2]) | ||
api.find(id) | ||
api.find(object) // with id property | ||
api.findOrAdd(id, object) | ||
api.findOrAdd(object) | ||
api.findOrAdd([object1, object2]) | ||
api.findAll() | ||
api.findAll(filterFunction) | ||
api.update(id, changedProperties) | ||
api.update(id, updateFunction) | ||
api.update(object) | ||
api.update([object1, object2]) | ||
api.updateOrAdd(id, object) | ||
api.updateOrAdd(object) | ||
api.updateOrAdd([object1, object2]) | ||
api.updateAll(changedProperties) | ||
api.updateAll(updateFunction) | ||
api.remove(id) | ||
api.remove(object) | ||
api.removeAll() | ||
api.removeAll(filterFunction) | ||
api.clear() | ||
``` | ||
|
||
Find the full API documentation at **TO BE DONE** | ||
|
||
|
||
## Installation | ||
|
||
### In the browser | ||
|
||
To use this plugin, include it after `pouchdb.js` in your HTML page: | ||
|
||
```html | ||
<script src="pouchdb.js"></script> | ||
<script src="pouchdb.hoodie-api.js"></script> | ||
``` | ||
|
||
This plugin is also available from Bower: | ||
|
||
``` | ||
bower install pouchdb | ||
bower install pouchdb-hoodie-api | ||
``` | ||
|
||
### In Node.js | ||
|
||
Install via npm | ||
|
||
``` | ||
npm install pouchdb | ||
npm install pouchdb-hoodie-api | ||
``` | ||
|
||
And then attach it to the `PouchDB` object | ||
|
||
```js | ||
var PouchDB = require('pouchdb') | ||
PouchDB(require('pouchdb-hoodie-api')) | ||
``` | ||
|
||
|
||
## Testing | ||
|
||
[![Coverage Status](https://coveralls.io/repos/boennemann/pouchdb-hoodie-api/badge.svg)](https://coveralls.io/r/boennemann/pouchdb-hoodie-api) | ||
[![devDependency Status](https://david-dm.org/boennemann/pouchdb-hoodie-api/dev-status.svg)](https://david-dm.org/boennemann/pouchdb-hoodie-api#info=devDependencies) | ||
[![Sauce Test Status](https://saucelabs.com/browser-matrix/db-pouch.svg)](https://saucelabs.com/u/db-pouch) | ||
|
||
[![Sauce Test Status](https://saucelabs.com/browser-matrix/hoodie-pouch.svg)](https://saucelabs.com/u/hoodie-pouch) | ||
### In Node.js | ||
|
||
[![NPM](https://nodei.co/npm/pouchdb-hoodie-api.png?downloads=true&downloadRank=true&stars=true)](https://nodei.co/npm/pouchdb-hoodie-api/) | ||
Run all tests and validates JavaScript Code Style using [standard](https://www.npmjs.com/package/standard) | ||
|
||
``` | ||
npm test | ||
``` | ||
|
||
To run only the tests | ||
|
||
``` | ||
npm run test:node | ||
``` | ||
|
||
### In the browser | ||
|
||
``` | ||
test:browser:local | ||
``` | ||
|
||
This will start a local server. All tests and coverage will be run at http://localhost:8080/__zuul |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,24 @@ | ||
'use strict' | ||
|
||
module.exports = Store | ||
module.exports = { hoodieApi: hoodieApi } | ||
|
||
function Store (db) { | ||
if (!(this instanceof Store)) return new Store(db) | ||
if (typeof db !== 'object' || typeof db.adapter !== 'string') throw new Error('Must pass a PouchDB') | ||
function hoodieApi () { | ||
var api = { | ||
db: this, | ||
utils: { | ||
Promise: this.constructor.utils.Promise, | ||
Errors: this.constructor.Errors | ||
} | ||
} | ||
|
||
this.db = db | ||
this.PouchDB = db.constructor | ||
api.add = require('./lib/add').bind(api) | ||
api.find = require('./lib/find').bind(api) | ||
api.findAll = require('./lib/find-all').bind(api) | ||
api.findOrAdd = require('./lib/find-or-add').bind(api) | ||
api.update = require('./lib/update').bind(api) | ||
api.updateOrAdd = require('./lib/update-or-add').bind(api) | ||
api.updateAll = require('./lib/update-all').bind(api) | ||
api.remove = require('./lib/remove').bind(api) | ||
|
||
this.add = require('./lib/add').bind(this) | ||
this.find = require('./lib/find').bind(this) | ||
this.findAll = require('./lib/find-all').bind(this) | ||
this.findOrAdd = require('./lib/find-or-add').bind(this) | ||
this.update = require('./lib/update').bind(this) | ||
this.updateOrAdd = require('./lib/update-or-add').bind(this) | ||
this.updateAll = require('./lib/update-all').bind(this) | ||
this.remove = require('./lib/remove').bind(this) | ||
return api | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
'use strict' | ||
|
||
var test = require('tape') | ||
var dbFactory = require('../utils/db') | ||
|
||
test('returns hoodie.store-inspired API', function (t) { | ||
t.plan(2) | ||
|
||
var db = dbFactory() | ||
var store = db.hoodieApi() | ||
|
||
t.is(typeof store, 'object', 'is object') | ||
t.is(store.db, db, 'exposes db') | ||
}) | ||
|
||
test('constructs a store object w/o new', function (t) { | ||
t.plan(2) | ||
|
||
var db = dbFactory() | ||
var store = db.hoodieApi() | ||
|
||
t.is(typeof store, 'object', 'is object') | ||
t.is(store.db, db, 'exposes db') | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.