jchris-couchrest 0.2.2 → 0.7.99
Sign up to get free protection for your applications and to get access to all the features.
- data/README +39 -0
- data/Rakefile +3 -54
- data/lib/couchrest.rb +39 -161
- data/lib/database.rb +83 -0
- data/script/couchdir +58 -0
- data/script/couchview +158 -0
- data/spec/couchrest_spec.rb +86 -0
- data/spec/database_spec.rb +407 -0
- metadata +15 -138
- data/LICENSE +0 -176
- data/README.md +0 -93
- data/THANKS.md +0 -18
- data/examples/model/example.rb +0 -144
- data/examples/word_count/markov +0 -38
- data/examples/word_count/views/books/chunked-map.js +0 -3
- data/examples/word_count/views/books/united-map.js +0 -1
- data/examples/word_count/views/markov/chain-map.js +0 -6
- data/examples/word_count/views/markov/chain-reduce.js +0 -7
- data/examples/word_count/views/word_count/count-map.js +0 -6
- data/examples/word_count/views/word_count/count-reduce.js +0 -3
- data/examples/word_count/word_count.rb +0 -46
- data/examples/word_count/word_count_query.rb +0 -40
- data/examples/word_count/word_count_views.rb +0 -26
- data/lib/couchrest/commands/generate.rb +0 -71
- data/lib/couchrest/commands/push.rb +0 -103
- data/lib/couchrest/core/database.rb +0 -318
- data/lib/couchrest/core/design.rb +0 -89
- data/lib/couchrest/core/document.rb +0 -96
- data/lib/couchrest/core/response.rb +0 -16
- data/lib/couchrest/core/server.rb +0 -88
- data/lib/couchrest/core/view.rb +0 -4
- data/lib/couchrest/helper/pager.rb +0 -103
- data/lib/couchrest/helper/streamer.rb +0 -44
- data/lib/couchrest/helper/upgrade.rb +0 -51
- data/lib/couchrest/mixins.rb +0 -4
- data/lib/couchrest/mixins/attachments.rb +0 -31
- data/lib/couchrest/mixins/callbacks.rb +0 -483
- data/lib/couchrest/mixins/design_doc.rb +0 -64
- data/lib/couchrest/mixins/document_queries.rb +0 -48
- data/lib/couchrest/mixins/extended_attachments.rb +0 -68
- data/lib/couchrest/mixins/extended_document_mixins.rb +0 -6
- data/lib/couchrest/mixins/properties.rb +0 -125
- data/lib/couchrest/mixins/validation.rb +0 -234
- data/lib/couchrest/mixins/views.rb +0 -168
- data/lib/couchrest/monkeypatches.rb +0 -119
- data/lib/couchrest/more/casted_model.rb +0 -28
- data/lib/couchrest/more/extended_document.rb +0 -217
- data/lib/couchrest/more/property.rb +0 -40
- data/lib/couchrest/support/blank.rb +0 -42
- data/lib/couchrest/support/class.rb +0 -191
- data/lib/couchrest/validation/auto_validate.rb +0 -163
- data/lib/couchrest/validation/contextual_validators.rb +0 -78
- data/lib/couchrest/validation/validation_errors.rb +0 -118
- data/lib/couchrest/validation/validators/absent_field_validator.rb +0 -74
- data/lib/couchrest/validation/validators/confirmation_validator.rb +0 -99
- data/lib/couchrest/validation/validators/format_validator.rb +0 -117
- data/lib/couchrest/validation/validators/formats/email.rb +0 -66
- data/lib/couchrest/validation/validators/formats/url.rb +0 -43
- data/lib/couchrest/validation/validators/generic_validator.rb +0 -120
- data/lib/couchrest/validation/validators/length_validator.rb +0 -134
- data/lib/couchrest/validation/validators/method_validator.rb +0 -89
- data/lib/couchrest/validation/validators/numeric_validator.rb +0 -104
- data/lib/couchrest/validation/validators/required_field_validator.rb +0 -109
- data/spec/couchrest/core/couchrest_spec.rb +0 -201
- data/spec/couchrest/core/database_spec.rb +0 -745
- data/spec/couchrest/core/design_spec.rb +0 -131
- data/spec/couchrest/core/document_spec.rb +0 -311
- data/spec/couchrest/core/server_spec.rb +0 -35
- data/spec/couchrest/helpers/pager_spec.rb +0 -122
- data/spec/couchrest/helpers/streamer_spec.rb +0 -23
- data/spec/couchrest/more/casted_extended_doc_spec.rb +0 -40
- data/spec/couchrest/more/casted_model_spec.rb +0 -98
- data/spec/couchrest/more/extended_doc_attachment_spec.rb +0 -130
- data/spec/couchrest/more/extended_doc_spec.rb +0 -509
- data/spec/couchrest/more/extended_doc_view_spec.rb +0 -207
- data/spec/couchrest/more/property_spec.rb +0 -130
- data/spec/couchrest/support/class_spec.rb +0 -59
- data/spec/fixtures/attachments/README +0 -3
- data/spec/fixtures/attachments/couchdb.png +0 -0
- data/spec/fixtures/attachments/test.html +0 -11
- data/spec/fixtures/more/article.rb +0 -34
- data/spec/fixtures/more/card.rb +0 -20
- data/spec/fixtures/more/course.rb +0 -14
- data/spec/fixtures/more/event.rb +0 -6
- data/spec/fixtures/more/invoice.rb +0 -17
- data/spec/fixtures/more/person.rb +0 -8
- data/spec/fixtures/more/question.rb +0 -6
- data/spec/fixtures/more/service.rb +0 -12
- data/spec/fixtures/views/lib.js +0 -3
- data/spec/fixtures/views/test_view/lib.js +0 -3
- data/spec/fixtures/views/test_view/only-map.js +0 -4
- data/spec/fixtures/views/test_view/test-map.js +0 -3
- data/spec/fixtures/views/test_view/test-reduce.js +0 -3
- data/spec/spec.opts +0 -6
- data/spec/spec_helper.rb +0 -26
- data/utils/remap.rb +0 -27
- data/utils/subset.rb +0 -30
data/THANKS.md
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
CouchRest THANKS
|
2
|
-
=====================
|
3
|
-
|
4
|
-
CouchRest was originally developed by J. Chris Anderson <jchris@grabb.it>
|
5
|
-
and a number of other contributors. Many people further contributed to
|
6
|
-
CouchRest by reporting problems, suggesting various improvements or submitting
|
7
|
-
changes. A list of these people is included below.
|
8
|
-
|
9
|
-
* [Matt Aimonetti](http://merbist.com/about/)
|
10
|
-
* [Greg Borenstein](http://ideasfordozens.com)
|
11
|
-
* [Geoffrey Grosenbach](http://nubyonrails.com/)
|
12
|
-
* [Jonathan S. Katz](http://github.com/jkatz)
|
13
|
-
* [Matt Lyon](http://mattly.tumblr.com/)
|
14
|
-
* Simon Rozet (simon /at/ rozet /dot/ name)
|
15
|
-
|
16
|
-
Patches are welcome. The primary source for this software project is [on Github](http://github.com/jchris/couchrest/tree/master)
|
17
|
-
|
18
|
-
A lot of people have active forks - thank you all - even the patches I don't end up using are helpful.
|
data/examples/model/example.rb
DELETED
@@ -1,144 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), '..', '..', 'lib', 'couchrest')
|
2
|
-
|
3
|
-
def show obj
|
4
|
-
puts obj.inspect
|
5
|
-
puts
|
6
|
-
end
|
7
|
-
|
8
|
-
SERVER = CouchRest.new
|
9
|
-
SERVER.default_database = 'couchrest-extendeddoc-example'
|
10
|
-
|
11
|
-
class Author < CouchRest::ExtendedDocument
|
12
|
-
use_database SERVER.default_database
|
13
|
-
property :name
|
14
|
-
|
15
|
-
def drink_scotch
|
16
|
-
puts "... glug type glug ... I'm #{name} ... type glug glug ..."
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
class Post < CouchRest::ExtendedDocument
|
21
|
-
use_database SERVER.default_database
|
22
|
-
|
23
|
-
property :title
|
24
|
-
property :body
|
25
|
-
property :author, :cast_as => 'Author'
|
26
|
-
|
27
|
-
timestamps!
|
28
|
-
end
|
29
|
-
|
30
|
-
class Comment < CouchRest::ExtendedDocument
|
31
|
-
use_database SERVER.default_database
|
32
|
-
|
33
|
-
property :commenter, :cast_as => 'Author'
|
34
|
-
timestamps!
|
35
|
-
|
36
|
-
def post= post
|
37
|
-
self["post_id"] = post.id
|
38
|
-
end
|
39
|
-
def post
|
40
|
-
Post.get(self['post_id']) if self['post_id']
|
41
|
-
end
|
42
|
-
|
43
|
-
end
|
44
|
-
|
45
|
-
puts "Act I: CRUD"
|
46
|
-
puts
|
47
|
-
puts "(pause for dramatic effect)"
|
48
|
-
puts
|
49
|
-
sleep 2
|
50
|
-
|
51
|
-
puts "Create an author."
|
52
|
-
quentin = Author.new("name" => "Quentin Hazel")
|
53
|
-
show quentin
|
54
|
-
|
55
|
-
puts "Create a new post."
|
56
|
-
post = Post.new(:title => "First Post", :body => "Lorem ipsum dolor sit amet, consectetur adipisicing elit...")
|
57
|
-
show post
|
58
|
-
|
59
|
-
puts "Add the author to the post."
|
60
|
-
post.author = quentin
|
61
|
-
show post
|
62
|
-
|
63
|
-
puts "Save the post."
|
64
|
-
post.save
|
65
|
-
show post
|
66
|
-
|
67
|
-
puts "Load the post."
|
68
|
-
reloaded = Post.get(post.id)
|
69
|
-
show reloaded
|
70
|
-
|
71
|
-
puts "The author of the post is an instance of Author."
|
72
|
-
reloaded.author.drink_scotch
|
73
|
-
|
74
|
-
puts "\nAdd some comments to the post."
|
75
|
-
comment_one = Comment.new :text => "Blah blah blah", :commenter => {:name => "Joe Sixpack"}
|
76
|
-
comment_two = Comment.new :text => "Yeah yeah yeah", :commenter => {:name => "Jane Doe"}
|
77
|
-
comment_three = Comment.new :text => "Whatever...", :commenter => {:name => "John Stewart"}
|
78
|
-
|
79
|
-
# TODO - maybe add some magic here?
|
80
|
-
comment_one.post = post
|
81
|
-
comment_two.post = post
|
82
|
-
comment_three.post = post
|
83
|
-
comment_one.save
|
84
|
-
comment_two.save
|
85
|
-
comment_three.save
|
86
|
-
|
87
|
-
show comment_one
|
88
|
-
show comment_two
|
89
|
-
show comment_three
|
90
|
-
|
91
|
-
puts "We can load a post through its comment (no magic here)."
|
92
|
-
show post = comment_one.post
|
93
|
-
|
94
|
-
puts "Commenters are also authors."
|
95
|
-
comment_two['commenter'].drink_scotch
|
96
|
-
comment_one['commenter'].drink_scotch
|
97
|
-
comment_three['commenter'].drink_scotch
|
98
|
-
|
99
|
-
puts "\nLet's save an author to her own document."
|
100
|
-
jane = comment_two['commenter']
|
101
|
-
jane.save
|
102
|
-
show jane
|
103
|
-
|
104
|
-
puts "Oh, that's neat! Because Ruby passes hash valuee by reference, Jane's new id has been added to the comment she left."
|
105
|
-
show comment_two
|
106
|
-
|
107
|
-
puts "Of course, we'd better remember to save it."
|
108
|
-
comment_two.save
|
109
|
-
show comment_two
|
110
|
-
|
111
|
-
puts "Oooh, denormalized... feel the burn!"
|
112
|
-
puts
|
113
|
-
puts
|
114
|
-
puts
|
115
|
-
puts "Act II: Views"
|
116
|
-
puts
|
117
|
-
puts
|
118
|
-
sleep 2
|
119
|
-
|
120
|
-
puts "Let's find all the comments that go with our post."
|
121
|
-
puts "Our post has id #{post.id}, so lets find all the comments with that post_id."
|
122
|
-
puts
|
123
|
-
|
124
|
-
class Comment
|
125
|
-
view_by :post_id
|
126
|
-
end
|
127
|
-
|
128
|
-
comments = Comment.by_post_id :key => post.id
|
129
|
-
show comments
|
130
|
-
|
131
|
-
puts "That was too easy."
|
132
|
-
puts "We can even wrap it up in a finder on the Post class."
|
133
|
-
puts
|
134
|
-
|
135
|
-
class Post
|
136
|
-
def comments
|
137
|
-
Comment.by_post_id :key => id
|
138
|
-
end
|
139
|
-
end
|
140
|
-
|
141
|
-
show post.comments
|
142
|
-
puts "Gimme 5 minutes and I'll roll this into the framework. ;)"
|
143
|
-
puts
|
144
|
-
puts "There is a lot more that can be done with views, but a lot of the interesting stuff is joins, which of course range across types. We'll pick up where we left off, next time."
|
data/examples/word_count/markov
DELETED
@@ -1,38 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require File.expand_path(File.dirname(__FILE__)) + '/../../couchrest'
|
4
|
-
|
5
|
-
cr = CouchRest.new("http://127.0.0.1:5984")
|
6
|
-
@db = cr.database('word-count-example')
|
7
|
-
@word_memoizer = {}
|
8
|
-
|
9
|
-
def probable_follower_for(word)
|
10
|
-
@word_memoizer[word] ||= @db.view('markov/chain-reduce', :startkey => [word,nil], :endkey => [word,{}],:group_level => 2)
|
11
|
-
|
12
|
-
# puts
|
13
|
-
# puts "search #{word} #{wprobs[word]['rows'].length}"
|
14
|
-
# @word_memoizer[word]['rows'].sort_by{|r|r['value']}.each{|r|puts [r['value'],r['key']].inspect}
|
15
|
-
|
16
|
-
rows = @word_memoizer[word]['rows'].select{|r|(r['key'][1]!='')}.sort_by{|r|r['value']}
|
17
|
-
row = rows[(-1*[rows.length,5].min)..-1].sort_by{rand}[0]
|
18
|
-
row ? row['key'][1] : nil
|
19
|
-
end
|
20
|
-
|
21
|
-
|
22
|
-
word = ARGV[0]
|
23
|
-
words = [word]
|
24
|
-
|
25
|
-
while word
|
26
|
-
$stdout.print ' ' if words.length > 1
|
27
|
-
$stdout.print word
|
28
|
-
$stdout.flush
|
29
|
-
word = probable_follower_for(word)
|
30
|
-
words << word
|
31
|
-
end
|
32
|
-
|
33
|
-
$stdout.print '.'
|
34
|
-
$stdout.flush
|
35
|
-
puts
|
36
|
-
|
37
|
-
# `say #{words.join(' ')}`
|
38
|
-
|
@@ -1 +0,0 @@
|
|
1
|
-
function(doc){if(doc.text && doc.text.match(/united/)) emit([doc.title, doc.chunk],null)}
|
@@ -1,46 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'couchrest'
|
3
|
-
|
4
|
-
couch = CouchRest.new("http://127.0.0.1:5984")
|
5
|
-
db = couch.database('word-count-example')
|
6
|
-
db.delete! rescue nil
|
7
|
-
db = couch.create_db('word-count-example')
|
8
|
-
|
9
|
-
books = {
|
10
|
-
'outline-of-science.txt' => 'http://www.gutenberg.org/files/20417/20417.txt',
|
11
|
-
'ulysses.txt' => 'http://www.gutenberg.org/dirs/etext03/ulyss12.txt',
|
12
|
-
'america.txt' => 'http://www.gutenberg.org/files/16960/16960.txt',
|
13
|
-
'da-vinci.txt' => 'http://www.gutenberg.org/dirs/etext04/7ldv110.txt'
|
14
|
-
}
|
15
|
-
|
16
|
-
books.each do |file, url|
|
17
|
-
pathfile = File.join(File.dirname(__FILE__),file)
|
18
|
-
`curl #{url} > #{pathfile}` unless File.exists?(pathfile)
|
19
|
-
end
|
20
|
-
|
21
|
-
|
22
|
-
books.keys.each do |book|
|
23
|
-
title = book.split('.')[0]
|
24
|
-
puts title
|
25
|
-
File.open(File.join(File.dirname(__FILE__),book),'r') do |file|
|
26
|
-
lines = []
|
27
|
-
chunk = 0
|
28
|
-
while line = file.gets
|
29
|
-
lines << line
|
30
|
-
if lines.length > 10
|
31
|
-
db.save({
|
32
|
-
:title => title,
|
33
|
-
:chunk => chunk,
|
34
|
-
:text => lines.join('')
|
35
|
-
})
|
36
|
-
chunk += 1
|
37
|
-
puts chunk
|
38
|
-
lines = []
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
# puts "The books have been stored in your CouchDB. To initiate the MapReduce process, visit http://127.0.0.1:5984/_utils/ in your browser and click 'word-count-example', then select view 'words' or 'count'. The process could take about 15 minutes on an average MacBook."
|
45
|
-
|
46
|
-
|
@@ -1,40 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'couchrest'
|
3
|
-
|
4
|
-
couch = CouchRest.new("http://127.0.0.1:5984")
|
5
|
-
db = couch.database('word-count-example')
|
6
|
-
|
7
|
-
puts "Now that we've parsed all those books into CouchDB, the queries we can run are incredibly flexible."
|
8
|
-
puts "\nThe simplest query we can run is the total word count for all words in all documents:"
|
9
|
-
puts "this will take a few minutes the first time. if it times out, just rerun this script in a few few minutes."
|
10
|
-
puts db.view('word_count/words').inspect
|
11
|
-
|
12
|
-
puts "\nWe can also narrow the query down to just one word, across all documents. Here is the count for 'flight' in all three books:"
|
13
|
-
|
14
|
-
word = 'flight'
|
15
|
-
params = {
|
16
|
-
:startkey => [word],
|
17
|
-
:endkey => [word,{}]
|
18
|
-
}
|
19
|
-
|
20
|
-
puts db.view('word_count/words',params).inspect
|
21
|
-
|
22
|
-
puts "\nWe scope the query using startkey and endkey params to take advantage of CouchDB's collation ordering. Here are the params for the last query:"
|
23
|
-
puts params.inspect
|
24
|
-
|
25
|
-
puts "\nWe can also count words on a per-title basis."
|
26
|
-
|
27
|
-
title = 'da-vinci'
|
28
|
-
params = {
|
29
|
-
:key => [word, title]
|
30
|
-
}
|
31
|
-
|
32
|
-
puts db.view('word_count/words',params).inspect
|
33
|
-
|
34
|
-
|
35
|
-
puts "\nHere are the params for 'flight' in the da-vinci book:"
|
36
|
-
puts params.inspect
|
37
|
-
puts
|
38
|
-
puts 'The url looks like this:'
|
39
|
-
puts 'http://127.0.0.1:5984/word-count-example/_view/word_count/count?key=["flight","da-vinci"]'
|
40
|
-
puts "\nTry dropping that in your browser..."
|
@@ -1,26 +0,0 @@
|
|
1
|
-
require 'rubygems'
|
2
|
-
require 'couchrest'
|
3
|
-
|
4
|
-
couch = CouchRest.new("http://127.0.0.1:5984")
|
5
|
-
db = couch.database('word-count-example')
|
6
|
-
|
7
|
-
word_count = {
|
8
|
-
:map => 'function(doc){
|
9
|
-
var words = doc.text.split(/\W/);
|
10
|
-
words.forEach(function(word){
|
11
|
-
if (word.length > 0) emit([word,doc.title],1);
|
12
|
-
});
|
13
|
-
}',
|
14
|
-
:reduce => 'function(key,combine){
|
15
|
-
return sum(combine);
|
16
|
-
}'
|
17
|
-
}
|
18
|
-
|
19
|
-
db.delete db.get("_design/word_count") rescue nil
|
20
|
-
|
21
|
-
db.save({
|
22
|
-
"_id" => "_design/word_count",
|
23
|
-
:views => {
|
24
|
-
:words => word_count
|
25
|
-
}
|
26
|
-
})
|
@@ -1,71 +0,0 @@
|
|
1
|
-
require 'fileutils'
|
2
|
-
|
3
|
-
module CouchRest
|
4
|
-
module Commands
|
5
|
-
module Generate
|
6
|
-
|
7
|
-
def self.run(options)
|
8
|
-
directory = options[:directory]
|
9
|
-
design_names = options[:trailing_args]
|
10
|
-
|
11
|
-
FileUtils.mkdir_p(directory)
|
12
|
-
filename = File.join(directory, "lib.js")
|
13
|
-
self.write(filename, <<-FUNC)
|
14
|
-
// Put global functions here.
|
15
|
-
// Include in your views with
|
16
|
-
//
|
17
|
-
// //include-lib
|
18
|
-
FUNC
|
19
|
-
|
20
|
-
design_names.each do |design_name|
|
21
|
-
subdirectory = File.join(directory, design_name)
|
22
|
-
FileUtils.mkdir_p(subdirectory)
|
23
|
-
filename = File.join(subdirectory, "sample-map.js")
|
24
|
-
self.write(filename, <<-FUNC)
|
25
|
-
function(doc) {
|
26
|
-
// Keys is first letter of _id
|
27
|
-
emit(doc._id[0], doc);
|
28
|
-
}
|
29
|
-
FUNC
|
30
|
-
|
31
|
-
filename = File.join(subdirectory, "sample-reduce.js")
|
32
|
-
self.write(filename, <<-FUNC)
|
33
|
-
function(keys, values) {
|
34
|
-
// Count the number of keys starting with this letter
|
35
|
-
return values.length;
|
36
|
-
}
|
37
|
-
FUNC
|
38
|
-
|
39
|
-
filename = File.join(subdirectory, "lib.js")
|
40
|
-
self.write(filename, <<-FUNC)
|
41
|
-
// Put functions specific to '#{design_name}' here.
|
42
|
-
// Include in your views with
|
43
|
-
//
|
44
|
-
// //include-lib
|
45
|
-
FUNC
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
def self.help
|
50
|
-
helpstring = <<-GEN
|
51
|
-
|
52
|
-
Usage: couchview generate directory design1 design2 design3 ...
|
53
|
-
|
54
|
-
Couchview will create directories and example views for the design documents you specify.
|
55
|
-
|
56
|
-
GEN
|
57
|
-
helpstring.gsub(/^ /, '')
|
58
|
-
end
|
59
|
-
|
60
|
-
def self.write(filename, contents)
|
61
|
-
puts "Writing #{filename}"
|
62
|
-
File.open(filename, "w") do |f|
|
63
|
-
# Remove leading spaces
|
64
|
-
contents.gsub!(/^ ( )?/, '')
|
65
|
-
f.write contents
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
@@ -1,103 +0,0 @@
|
|
1
|
-
module CouchRest
|
2
|
-
|
3
|
-
module Commands
|
4
|
-
|
5
|
-
module Push
|
6
|
-
|
7
|
-
def self.run(options)
|
8
|
-
directory = options[:directory]
|
9
|
-
database = options[:trailing_args].first
|
10
|
-
|
11
|
-
fm = CouchRest::FileManager.new(database)
|
12
|
-
fm.loud = options[:loud]
|
13
|
-
|
14
|
-
if options[:loud]
|
15
|
-
puts "Pushing views from directory #{directory} to database #{fm.db}"
|
16
|
-
end
|
17
|
-
|
18
|
-
fm.push_views(directory)
|
19
|
-
end
|
20
|
-
|
21
|
-
def self.help
|
22
|
-
helpstring = <<-GEN
|
23
|
-
|
24
|
-
== Pushing views with Couchview ==
|
25
|
-
|
26
|
-
Usage: couchview push directory dbname
|
27
|
-
|
28
|
-
Couchview expects a specific filesystem layout for your CouchDB views (see
|
29
|
-
example below). It also supports advanced features like inlining of library
|
30
|
-
code (so you can keep DRY) as well as avoiding unnecessary document
|
31
|
-
modification.
|
32
|
-
|
33
|
-
Couchview also solves a problem with CouchDB's view API, which only provides
|
34
|
-
access to the final reduce side of any views which have both a map and a
|
35
|
-
reduce function defined. The intermediate map results are often useful for
|
36
|
-
development and production. CouchDB is smart enough to reuse map indexes for
|
37
|
-
functions duplicated across views within the same design document.
|
38
|
-
|
39
|
-
For views with a reduce function defined, Couchview creates both a reduce view
|
40
|
-
and a map-only view, so that you can browse and query the map side as well as
|
41
|
-
the reduction, with no performance penalty.
|
42
|
-
|
43
|
-
== Example ==
|
44
|
-
|
45
|
-
couchview push foo-project/bar-views baz-database
|
46
|
-
|
47
|
-
This will push the views defined in foo-project/bar-views into a database
|
48
|
-
called baz-database. Couchview expects the views to be defined in files with
|
49
|
-
names like:
|
50
|
-
|
51
|
-
foo-project/bar-views/my-design/viewname-map.js
|
52
|
-
foo-project/bar-views/my-design/viewname-reduce.js
|
53
|
-
foo-project/bar-views/my-design/noreduce-map.js
|
54
|
-
|
55
|
-
Pushed to => http://127.0.0.1:5984/baz-database/_design/my-design
|
56
|
-
|
57
|
-
And the design document:
|
58
|
-
{
|
59
|
-
"views" : {
|
60
|
-
"viewname-map" : {
|
61
|
-
"map" : "### contents of view-name-map.js ###"
|
62
|
-
},
|
63
|
-
"viewname-reduce" : {
|
64
|
-
"map" : "### contents of view-name-map.js ###",
|
65
|
-
"reduce" : "### contents of view-name-reduce.js ###"
|
66
|
-
},
|
67
|
-
"noreduce-map" : {
|
68
|
-
"map" : "### contents of noreduce-map.js ###"
|
69
|
-
}
|
70
|
-
}
|
71
|
-
}
|
72
|
-
|
73
|
-
Couchview will create a design document for each subdirectory of the views
|
74
|
-
directory specified on the command line.
|
75
|
-
|
76
|
-
== Library Inlining ==
|
77
|
-
|
78
|
-
Couchview can optionally inline library code into your views so you only have
|
79
|
-
to maintain it in one place. It looks for any files named lib.* in your
|
80
|
-
design-doc directory (for doc specific libs) and in the parent views directory
|
81
|
-
(for project global libs). These libraries are only inserted into views which
|
82
|
-
include the text
|
83
|
-
|
84
|
-
// !include lib
|
85
|
-
|
86
|
-
or
|
87
|
-
|
88
|
-
# !include lib
|
89
|
-
|
90
|
-
Couchview is a result of scratching my own itch. I'd be happy to make it more
|
91
|
-
general, so please contact me at jchris@grabb.it if you'd like to see anything
|
92
|
-
added or changed.
|
93
|
-
|
94
|
-
GEN
|
95
|
-
helpstring.gsub(/^ /, '')
|
96
|
-
end
|
97
|
-
|
98
|
-
end
|
99
|
-
|
100
|
-
|
101
|
-
end
|
102
|
-
|
103
|
-
end
|