Created
May 15, 2009 21:36
-
-
Save ratbeard/112451 to your computer and use it in GitHub Desktop.
This file contains 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
// map.js | |
function(doc) { | |
// !json sentences.sentences | |
var k | |
for (k in doc) { | |
if (sentences.sentences[k]) | |
emit([doc._id, k], sentences.sentences[k]); | |
} | |
}; | |
// sentences/sentences.js | |
{ | |
"revenue" : { | |
[-Infinity, -1] : "Revenue growth was poor", | |
[-1, 1] : "Revenue growth was stable", | |
[1, Infinity] : "Revenue growth was positive" | |
} | |
} | |
// in the design doc: | |
// inserted json as string :"( | |
function(doc) { | |
var sentences = {"sentences": "{\n\t\"revenue\" : {\n\t\t[-Infinity, -1] : \"Revenue growth was poor\",\n\t\t[-1, 1] : \"Revenue growth was stable\",\n\t\t[1, Infinity] : \"Revenue growth was positive\"\n\t}\n}"}; | |
var k, keys = [] | |
for (k in doc) { | |
if (sentences.sentences[k]) | |
emit([doc._id, k], sentences.sentences[k]); | |
} | |
}; | |
This file contains 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
yikes, if I add another key to my json file: | |
{ | |
"revenue" : [ | |
{ "min": -Infinity, "max": -1, "result": "Revenue growth was poor" }, | |
{ "min": -1, "max": 1, "result": "Revenue growth was stable" }, | |
{ "min": 1, "max": Infinity, "result": "Revenue growth was da bomb!"}, | |
], | |
"what": "sup" | |
} | |
// Things really blow up: | |
» couchapp push http://localhost:5984/relax2 | |
Traceback (most recent call last): | |
File "/usr/local/bin/couchapp", line 8, in <module> | |
load_entry_point('Couchapp==0.2', 'console_scripts', 'couchapp')() | |
File "/Library/Python/2.5/site-packages/Couchapp-0.2-py2.5.egg/couchapp/bin/couchapp_cli.py", line 148, in main | |
push(appdir, appname, dbstring, options.verbose, options=options) | |
File "/Library/Python/2.5/site-packages/Couchapp-0.2-py2.5.egg/couchapp/bin/couchapp_cli.py", line 47, in push | |
nocss=options.css, nojs=options.js) | |
File "/Library/Python/2.5/site-packages/Couchapp-0.2-py2.5.egg/couchapp/file_manager.py", line 251, in push_app | |
self.package_views(doc["views"], app_dir, verbose=verbose) | |
File "/Library/Python/2.5/site-packages/Couchapp-0.2-py2.5.egg/couchapp/file_manager.py", line 693, in package_views | |
self.apply_lib(funcs, app_dir, verbose=verbose) | |
File "/Library/Python/2.5/site-packages/Couchapp-0.2-py2.5.egg/couchapp/file_manager.py", line 706, in apply_lib | |
app_dir, verbose=verbose) | |
File "/Library/Python/2.5/site-packages/Couchapp-0.2-py2.5.egg/couchapp/file_manager.py", line 791, in run_json_macros | |
re_json.sub(rjson, f_string) | |
File "/Library/Python/2.5/site-packages/Couchapp-0.2-py2.5.egg/couchapp/file_manager.py", line 778, in rjson | |
library = library[field] | |
TypeError: string indices must be integers | |
This file contains 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
doh, use !code, not !json. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment