Created
May 29, 2010 01:19
-
-
Save NakedMoleRatScientist/417942 to your computer and use it in GitHub Desktop.
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
| var sys = require('sys') | |
| var couch = require('node-couchdb/lib/couchdb') | |
| var client = couch.createClient(5984,'localhost'); | |
| var db = client.db('server') | |
| var document = | |
| { | |
| names: [], | |
| scores: [], | |
| rev: 0 | |
| } | |
| exports.add_to_list = function(name,points) | |
| { | |
| document.names << name; | |
| document.scores << points; | |
| } | |
| exports.save = function() | |
| { | |
| db.saveDoc('score', document,function(er,ok) { | |
| if (er) throw new Error(JSON.stringify(er)); | |
| sys.puts("save a document"); | |
| }); | |
| } | |
| exports.destroy = function() | |
| { | |
| db.getDoc('score',function(er,doc){ | |
| if (er) throw new Error(JSON.stringify(er)); | |
| sys.puts("destroy a document") | |
| db.removeDoc(doc._id,doc._rev); | |
| }); | |
| } | |
| exports.getList = function() | |
| { | |
| db.getDoc('score',function(er,doc){ | |
| if (er) throw new Error(JSON.stringify(er)); | |
| for(var i = 0; i < doc.names.size;i++) | |
| { | |
| document.names << doc._names[i]; | |
| document.scores << doc._scores[i]; | |
| } | |
| rev = doc._rev; | |
| }); | |
| return document; | |
| } | |
| exports.use_db = function(name) | |
| { | |
| db = client.db(name); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment