Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/janl/node-couchdbchanges
Write CouchDB Changes Listeners. Easy.
https://github.com/janl/node-couchdbchanges
Last synced: 2 months ago
JSON representation
Write CouchDB Changes Listeners. Easy.
- Host: GitHub
- URL: https://github.com/janl/node-couchdbchanges
- Owner: janl
- Created: 2012-02-18T14:02:26.000Z (almost 13 years ago)
- Default Branch: master
- Last Pushed: 2012-07-14T13:18:15.000Z (over 12 years ago)
- Last Synced: 2024-10-02T09:54:57.761Z (3 months ago)
- Language: JavaScript
- Homepage:
- Size: 283 KB
- Stars: 6
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Write CouchDB Changes Listeners. Easy.
var changes = require("CouchDBChanges");
changes.follow("database", function(change) {
// do whatever you want with the change.
}, { url: "http://127.0.0.1:5984/database/"});Wow, easy!
CouchDB, The Definitive Guide has
[a chapter on the Changes feed](http://guide.couchdb.org/draft/notifications.html).## Wha?
CouchDB has this amazing feature called the “Changes Feed”. Think of
`git log` for your database. There’s all sorts of awesome you can do
with this. For example, have a database called `outbox` and connect
a CouchDB changes listener to it and whenever your application creates
a new document, say{
"from": "[email protected]",
"to": "[email protected]",
"subject": "Hey there!",
"body": "I think you get the idea"
}the changes listener then gets notified right when the document gets
created, but asynchronously from your application and send the email
that is described. When the email is sent, it can write back a new field"status": "sent"
or, if anything went wrong:
"status": "error",
"error_message": "that email address is bogus you twat!"So yeah, quick example, but there’s tons of things you can do with this.
We should collect nice examples, but for now you can check out
.## API
`follow(database, change_cb, follow_options, changes_options)`
* `database`: (string) name of the database
* `change_cb`: (callable) function to call for each change
* `follow_options`: (object) configurations for following {
* persistent_since: (bool) false whether or not to persist the latest
`seq_id` from the server. This allows us to avoid processing a
change more than once.
}
* `changes_options`: (object) parameters for the [follow library](follow).## Next?
* Make `persistent_since` storage configurable.
## Thanks
This is just a very thin wrapper around Jason Smith’s / Iris Couch’s
excellent [`follow` library](follow).Thanks Jason!
[follow]: https://github.com/iriscouch/follow
## License & Copyright
(c) 2012 Jan Lehnardt
Licensed under the Apache License 2.0.