Skip to content

Instantly share code, notes, and snippets.

@sbisbee
Created December 23, 2011 21:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sbisbee/1515442 to your computer and use it in GitHub Desktop.
Save sbisbee/1515442 to your computer and use it in GitHub Desktop.
Sag-JS Docu Examples 2
//Compact the db
couch.compact({
callback: function(resp, succ) {
//do stuff
}
});
//Compact the view
couch.compact({
viewName: 'app',
callback: function(resp, succ) {
//do stuff
}
});
couch.generateIDs({
count: 20,
callback: function(resp, succ) {
//do stuff with IDs
}
});
couch.getAllDocs({
limit: 10,
includeDocs: true,
descending: true,
startKey: JSON.encode([ "foo", 1 ]),
callback: function(resp, succ) {
//do stuff
}
});
//Basic auth
couch.login({
user: 'admin',
pass: 'passwd'
});
//Cookie auth
couch.login({
user: 'admin',
pass: 'passwd',
type: sag.AUTH_COOKIE,
callback: function(resp, succ) {
//do stuff
}
});
//Do a non-continuous replication, creating the target db if it doesn't exist
couch.replicate({
source: 'srcdb',
target: 'targetdb',
createTarget: true,
callback: function(resp, success) {
//do stuff
}
});
//The attachment info we are saving with.
var attachment = {
name: 'lyrics',
data: 'If I could turn back time...',
cType: 'text/ascii'
};
//Get the parent document we are going to set the attachment on
couch.get({
url: 'one',
callback: function(resp) {
//Set the attachment now that we have the _rev
couch.setAttachment({
docID: resp.body._id,
docRev: resp.body._rev,
name: attachment.name,
data: attachment.data,
contentType: attachment.cType,
callback: function(resp) {
//do stuff
}
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment