Skip to content

ssmith-wustl/couchdb-xd

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Cross-domain AJAX for CouchDB

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published