https://github.com/mikeal/couchie
Minimalist localStorage database API. Works well as a cache for CouchDB documents.
https://github.com/mikeal/couchie
Last synced: 2 months ago
JSON representation
Minimalist localStorage database API. Works well as a cache for CouchDB documents.
- Host: GitHub
- URL: https://github.com/mikeal/couchie
- Owner: mikeal
- Created: 2012-03-06T09:40:04.000Z (over 13 years ago)
- Default Branch: master
- Last Pushed: 2017-07-11T21:45:13.000Z (almost 8 years ago)
- Last Synced: 2024-10-18T09:13:52.485Z (9 months ago)
- Language: JavaScript
- Homepage:
- Size: 80.1 KB
- Stars: 20
- Watchers: 3
- Forks: 2
- Open Issues: 2
-
Metadata Files:
- Readme: README.mkd
Awesome Lists containing this project
README
# couchie
## Installing
```
npm install browserify
browserify index.js > couchie.js
```### Tests
[](https://ci.testling.com/mikeal/couchie)
### Minimalist localStorage database API. Works well as a cache for CouchDB documents.
```html
// get a database by name
var db = couchie('name')// write a document, MUST include _id and _rev
db.post({_id:'550e8400-e29b-41d4-a716-446655440000', _rev:'1-550e8400', data:'test'}, function (e) {
if (e) throw e// get a document by id
db.get('550e8400-e29b-41d4-a716-446655440000', function (e, doc) {
if (e) throw e
doc // {_id:'550e8400-e29b-41d4-a716-446655440000', _rev:'1-550e8400', data:'test'}
db.revs() // {'550e8400-e29b-41d4-a716-446655440000': '1-550e8400'}// write documents in bulk, much more efficient
db.bulk([ /* array of docs */ ], function (e) {
if (e) throw e// get array of all documents
db.all(function (e, docs) {
if (e) throw e
docs // array of all documents
})
})
})
})```
### FAQ
If localStorage is blocking why is this a callback API?
**In the future couchie may implement a few features that require a non-blocking API. The first is `lock()` which would queue any changes coming in to the database until the lock is removed. The second is pagination across documents for large operations, basically wrapping all the synchronous file access in setTimeout calls so that we don't block the main event loop on large db operations.**
When localStorage is not available couchie assumes the environment is node.js and will write to the filesystem. In this case the `name` of the database is a directory to write files.