paulcarey-relaxdb 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +20 -0
- data/README.textile +98 -0
- data/Rakefile +52 -0
- data/docs/spec_results.html +602 -0
- data/lib/relaxdb/all_delegator.rb +48 -0
- data/lib/relaxdb/belongs_to_proxy.rb +29 -0
- data/lib/relaxdb/design_doc.rb +50 -0
- data/lib/relaxdb/document.rb +298 -0
- data/lib/relaxdb/has_many_proxy.rb +81 -0
- data/lib/relaxdb/has_one_proxy.rb +45 -0
- data/lib/relaxdb/query.rb +48 -0
- data/lib/relaxdb/references_many_proxy.rb +99 -0
- data/lib/relaxdb/relaxdb.rb +106 -0
- data/lib/relaxdb/server.rb +112 -0
- data/lib/relaxdb/sorted_by_view.rb +42 -0
- data/lib/relaxdb/uuid_generator.rb +21 -0
- data/lib/relaxdb/view_object.rb +34 -0
- data/lib/relaxdb/view_uploader.rb +47 -0
- data/lib/relaxdb/views.rb +42 -0
- data/lib/relaxdb.rb +33 -0
- data/spec/belongs_to_spec.rb +80 -0
- data/spec/design_doc_spec.rb +34 -0
- data/spec/document_spec.rb +301 -0
- data/spec/has_many_spec.rb +139 -0
- data/spec/has_one_spec.rb +121 -0
- data/spec/query_spec.rb +46 -0
- data/spec/references_many_spec.rb +141 -0
- data/spec/relaxdb_spec.rb +50 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +10 -0
- data/spec/spec_models.rb +104 -0
- data/spec/view_object_spec.rb +47 -0
- metadata +111 -0
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2008 Paul Carey
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.textile
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
*Note:* For a correctly formatted version of this page, take a look at the "wiki":http://github.com/paulcarey/relaxdb/wikis
|
2
|
+
|
3
|
+
h2. Overview
|
4
|
+
|
5
|
+
RelaxDB provides a Ruby interface to CouchDB. It offers a simple idiom for specifying object relationships. The underlying objects are persisted to the mighty CouchDB. Combined with the schema free nature of CouchDB, RelaxDB's current strength lies in quick prototyping of object models.
|
6
|
+
|
7
|
+
A few facilities are provided including pretty printing of GET requests and uploading of JavaScript views.
|
8
|
+
|
9
|
+
A basic merb plugin, "merb_relaxdb":http://github.com/paulcarey/merb_relaxdb/tree/master is also available.
|
10
|
+
|
11
|
+
For more complete documentation take a look at docs/spec_results.html and the corresponding specs.
|
12
|
+
|
13
|
+
h2. Details
|
14
|
+
|
15
|
+
h3. Getting started
|
16
|
+
|
17
|
+
<pre>
|
18
|
+
<code>
|
19
|
+
RelaxDB.configure :host => "localhost", :port => 5984
|
20
|
+
RelaxDB.use_db "scratch"
|
21
|
+
</code>
|
22
|
+
</pre>
|
23
|
+
|
24
|
+
h3. Defining models
|
25
|
+
|
26
|
+
<pre>
|
27
|
+
<code>
|
28
|
+
class Writer < RelaxDB::Document
|
29
|
+
property :name, :default => "anon"
|
30
|
+
|
31
|
+
has_many :posts, :class => "Post"
|
32
|
+
has_many :ratings, :class => "Post", :known_as => :critic
|
33
|
+
end
|
34
|
+
|
35
|
+
class Post < RelaxDB::Document
|
36
|
+
property :created_at
|
37
|
+
property :contents
|
38
|
+
|
39
|
+
belongs_to :writer
|
40
|
+
has_many :ratings, :class => "Rating"
|
41
|
+
end
|
42
|
+
|
43
|
+
class Rating < RelaxDB::Document
|
44
|
+
property :thumbs_up, :validator => lambda { |tu| tu >= 0 && tu < 3 }, :validation_msg => "No no"
|
45
|
+
|
46
|
+
belongs_to :post
|
47
|
+
belongs_to :critic
|
48
|
+
end
|
49
|
+
</code>
|
50
|
+
</pre>
|
51
|
+
|
52
|
+
h3. Exploring models
|
53
|
+
|
54
|
+
<pre>
|
55
|
+
<code>
|
56
|
+
paul = Writer.new(:name => "paul").save
|
57
|
+
|
58
|
+
post = Post.new(:contents => "foo")
|
59
|
+
paul.posts << post # post writer is set and post is saved
|
60
|
+
post.created_at # right now
|
61
|
+
paul.ratings << Rating.new(:thumbs_up => 3, :post => post) # returns false as rating fails validation
|
62
|
+
paul.ratings.size # 0
|
63
|
+
|
64
|
+
# Simple views are auto created
|
65
|
+
Rating.all.sorted_by(:thumbs_up) { |q| q.key(2).count(1) } # query params map directly to CouchDB
|
66
|
+
</code>
|
67
|
+
</pre>
|
68
|
+
|
69
|
+
h3. Creating views by hand
|
70
|
+
|
71
|
+
<pre>
|
72
|
+
<code>
|
73
|
+
$ cat view.js
|
74
|
+
function Writer-allnames-map(doc) {
|
75
|
+
if(doc.class == "Writer")
|
76
|
+
emit(null, doc.name);
|
77
|
+
}
|
78
|
+
|
79
|
+
function Writer-allnames-reduce(keys, values) {
|
80
|
+
var allnames = "";
|
81
|
+
for(var i = 0; i < values.length; i++)
|
82
|
+
allnames += values[i];
|
83
|
+
return allnames;
|
84
|
+
}
|
85
|
+
$
|
86
|
+
|
87
|
+
RelaxDB::ViewUploader.upload("view.js")
|
88
|
+
RelaxDB.view("Writer", "allnames") # paul
|
89
|
+
</code>
|
90
|
+
</pre>
|
91
|
+
|
92
|
+
h2. Incomplete list of limitations
|
93
|
+
|
94
|
+
* Error handling is not robust
|
95
|
+
* Destroying an object results in non transactional nullification of child/peer references
|
96
|
+
* Objects can talk to only one database at a time
|
97
|
+
* No caching is used. Although adding an LRU cache would be fairly straightforward, this hasn't been done as it's not yet clear what caching strategies will be most effective.
|
98
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake/gempackagetask'
|
3
|
+
require 'spec/rake/spectask'
|
4
|
+
|
5
|
+
PLUGIN = "relaxdb"
|
6
|
+
NAME = "relaxdb"
|
7
|
+
GEM_VERSION = "0.1.0"
|
8
|
+
AUTHOR = "Paul Carey"
|
9
|
+
EMAIL = "paul.p.carey@gmail.com"
|
10
|
+
HOMEPAGE = "http://github.com/paulcarey/relaxdb/"
|
11
|
+
SUMMARY = "RelaxDB provides a simple interface to CouchDB"
|
12
|
+
|
13
|
+
spec = Gem::Specification.new do |s|
|
14
|
+
s.name = NAME
|
15
|
+
s.version = GEM_VERSION
|
16
|
+
s.platform = Gem::Platform::RUBY
|
17
|
+
s.has_rdoc = true
|
18
|
+
s.extra_rdoc_files = ["README.textile", "LICENSE"]
|
19
|
+
s.summary = SUMMARY
|
20
|
+
s.description = s.summary
|
21
|
+
s.author = AUTHOR
|
22
|
+
s.email = EMAIL
|
23
|
+
s.homepage = HOMEPAGE
|
24
|
+
|
25
|
+
s.add_dependency "extlib", ">=0.9.4"
|
26
|
+
s.add_dependency "json"
|
27
|
+
s.add_dependency "uuid"
|
28
|
+
|
29
|
+
s.require_path = 'lib'
|
30
|
+
s.autorequire = PLUGIN
|
31
|
+
s.files = %w(LICENSE README.textile Rakefile) + Dir.glob("{docs,lib,spec}/**/*")
|
32
|
+
end
|
33
|
+
|
34
|
+
Rake::GemPackageTask.new(spec) do |pkg|
|
35
|
+
pkg.gem_spec = spec
|
36
|
+
end
|
37
|
+
|
38
|
+
desc "Install"
|
39
|
+
task :install => [:package] do
|
40
|
+
sh %{sudo gem install --local pkg/#{NAME}-#{GEM_VERSION} --no-update-sources}
|
41
|
+
end
|
42
|
+
|
43
|
+
desc "Run specs"
|
44
|
+
Spec::Rake::SpecTask.new('spec') do |t|
|
45
|
+
t.spec_files = FileList['spec/**/*.rb']
|
46
|
+
end
|
47
|
+
|
48
|
+
desc "Run specs and produce spec_results.html"
|
49
|
+
Spec::Rake::SpecTask.new('spec:html') do |t|
|
50
|
+
t.spec_files = FileList['spec/**/*.rb']
|
51
|
+
t.spec_opts = ["--format", "html:docs/spec_results.html"]
|
52
|
+
end
|