Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Cross-domain AJAX for CouchDB
branch: master

This branch is even with benvinegar:master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
_attachments
.gitignore
LICENSE
README.textile
_id
couchapp.json

README.textile

couchdb-xd

Cross-domain AJAX for CouchDB, distributed as a CouchApp.

Installation

First, create a new database in CouchDB to store the app. The instructions assume you’ll name it “couchdb-xd”.

$ git clone git@github.com:benvinegar/couchdb-xd.git
$ cd couchdb-xd
$ couchapp push . http://user:pass@your-couch-host.com/couchdb-xd

Afterwards, include the following script tag in your app/web page:

<script src="http://your-couch-host.com/couchdb-xd/_design/couchdb-xd/couchdb.js" type="text/javascript"></script>

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.

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) { });

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

Caveats

Only works with browsers that support window.postMessage (IE8+, Firefox 3.5+, Safari 4+, Chrome).

Todo

Something went wrong with that request. Please try again.