couchdb-xd
couchdb-xd copied to clipboard
Cross-domain AJAX for CouchDB
h1. couchdb-xd
Cross-domain AJAX for CouchDB, distributed as a "CouchApp":http://github.com/couchapp/couchapp#readme.
h2. Installation
First, create a new database in CouchDB to store the app. The instructions assume you'll name it "couchdb-xd".
$ git clone [email protected]:benvinegar/couchdb-xd.git $ cd couchdb-xd $ couchapp push . http://user:[email protected]/couchdb-xd
Afterwards, include the following script tag in your app/web page:
You'll now have access to the Couch global JavaScript object, which exposes a number of utility classes and methods for manipulating any CouchDB database hosted on that domain. See below for usage.
h2. Usage
Initialize the library.
Couch.init(function() { // execute on ready });
Get, create, and delete databases.
var server = new Couch.Server('http://localhost:5984', 'user', 'pass'); server.get(server, 'dbname', function(resp) { }); server.destroy(server, 'dbname', function(resp) { }); server.create(server, 'dbname', function(resp) { });
Get, create, update, delete, and copy documents.
var db = new Couch.Database(server, 'dbname'); db.get('some-record', function(resp) { }); db.put('some-record', { hello: 'world' }, function(resp) { }); db.post({ hello: 'world' }, function(resp) { }); db.destroy('some-record', { rev: 'abcdef123456789' }, function(resp) { }); db.copy('some-record', 'new-record', { rev: 'abcdef123456789' }, function(resp) { });
h2. Unit Tests
After installing, you can run the provided unit tests at:
"http://your-couch-host.com/couchdb-xd/_design/couchdb-xd/test/index.html":http://your-couch-host.com/couchdb-xd/_design/couchdb-xd/test/index.html
h2. Caveats
Only works with browsers that support window.postMessage (IE8+, Firefox 3.5+, Safari 4+, Chrome).
h2. Todo
- Bulk Document API ** "http://wiki.apache.org/couchdb/HTTP_Bulk_Document_API":http://wiki.apache.org/couchdb/HTTP_Bulk_Document_API
- Database API ** _changes, _all_dbs ** "http://wiki.apache.org/couchdb/HTTP_database_API":http://wiki.apache.org/couchdb/HTTP_database_API
- Support non-postMessage browsers