Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/candlerb/couchdb_ruby_view
View server for CouchDB which lets you write map and reduce functions in ruby
https://github.com/candlerb/couchdb_ruby_view
Last synced: about 2 months ago
JSON representation
View server for CouchDB which lets you write map and reduce functions in ruby
- Host: GitHub
- URL: https://github.com/candlerb/couchdb_ruby_view
- Owner: candlerb
- License: mit
- Created: 2009-07-08T21:48:52.000Z (over 15 years ago)
- Default Branch: master
- Last Pushed: 2010-08-25T19:39:34.000Z (over 14 years ago)
- Last Synced: 2023-04-13T13:47:06.837Z (over 1 year ago)
- Language: Ruby
- Homepage:
- Size: 90.8 KB
- Stars: 29
- Watchers: 3
- Forks: 5
- Open Issues: 0
-
Metadata Files:
- Readme: README
- License: License.txt
Awesome Lists containing this project
README
Installation
------------
Copy bin/couchdb_ruby_view to somewhere like /usr/local/bin, and make
sure it is executable.Edit /usr/local/etc/couchdb/local.ini and set:
[query_servers]
ruby = /usr/local/bin/couchdb_ruby_viewor
ruby = /path/to/ruby /usr/local/bin/couchdb_ruby_view
Restart couchdb.
API
---
map:proc { |doc|
...
emit(key,val)
...
}reduce/rereduce:
proc { |ks,vs,rereduce|
vs.inject(0) { |a,b| a+b }
}Note that CouchDB actually passes objects which could be iterated directly
using { |(k,id),v| ... }. However I've split these into separate arrays of
[k,id] and v for consistency with the Javascript view server, and because it
simplifies some reduce/rereduce functions (as in the example above, where
both reduce and rereduce are the same)*** IMPORTANT SECURITY WARNING ***
----------------------------------
DON'T USE THIS CODE IF UNTRUSTED USERS HAVE DIRECT ACCESS TO YOUR DATABASE!
They will be able to run *any* code or read/write *any* file as the couchdb
user if they can post to _temp_view or update design documents.TODO: improve this by compiling and running the functions in a separate
thread with $SAFE=4. There is also _why's ruby sandbox gem, although this
requires a small patch to the ruby interpreter itself.ALSO TODO
---------
If map/reduce functions define helper methods using 'def', they should do
this inside a singleton class rather than globally.Authors
-------
Johan Sørensen
Brian Candler