Created
December 23, 2011 21:45
-
-
Save sbisbee/1515442 to your computer and use it in GitHub Desktop.
Sag-JS Docu Examples 2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Compact the db | |
couch.compact({ | |
callback: function(resp, succ) { | |
//do stuff | |
} | |
}); | |
//Compact the view | |
couch.compact({ | |
viewName: 'app', | |
callback: function(resp, succ) { | |
//do stuff | |
} | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
couch.generateIDs({ | |
count: 20, | |
callback: function(resp, succ) { | |
//do stuff with IDs | |
} | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
couch.getAllDocs({ | |
limit: 10, | |
includeDocs: true, | |
descending: true, | |
startKey: JSON.encode([ "foo", 1 ]), | |
callback: function(resp, succ) { | |
//do stuff | |
} | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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 | |
} | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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 | |
} | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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