relaxo-query-server 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.gitignore +17 -0
- data/.travis.yml +11 -0
- data/Gemfile +8 -0
- data/README.md +23 -23
- data/lib/relaxo/query_server/context.rb +2 -1
- data/lib/relaxo/query_server/library.rb +21 -0
- data/lib/relaxo/query_server/mapper.rb +5 -16
- data/lib/relaxo/query_server/reducer.rb +8 -1
- data/lib/relaxo/query_server/version.rb +1 -7
- data/rakefile.rb +3 -3
- data/relaxo-query-server.gemspec +33 -0
- data/test/helper.rb +10 -1
- data/test/test_reduce.rb +23 -0
- metadata +113 -67
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
ZDVhYmYxZWNlYmQwNmQzNGRmYzdiYzJhMTQxY2Y3MTY2N2E1MjBlNw==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
MDUzMmI3YjIzNWZmMzU3NTNjNDBmNmUwYTVmM2ExYjU2NzMzMWYyNA==
|
7
|
+
!binary "U0hBNTEy":
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
YTgxMjllODIyMjhmM2JmYzA2ODMxZmM0M2I2YWQ1MjRhYzE0ZDgyYmFhMjQy
|
10
|
+
ZGVjYzEwMzQ5MDBiOTNkNjIwYmM1NTJiZDc0MDg4OGFkNGM3NmNkNmIzNjA3
|
11
|
+
ZjY1ZjRiYzJhMzQxOGQ5MmZjMWQzNzJlMGVkYjZmMTNkOTMzNzY=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
YmJhZjVhNmU4ZmRiM2FiMTc1NWU2Nzg4MDRmYTgwNDU1MDYyODE2YmU4ZDIy
|
14
|
+
M2UwZTJhOTI1NDBlNWFmMWFiMzYyNWNiMDI5NDljMzNhYTIyNDllNmZiOTli
|
15
|
+
MGQ1YzcxOTZkOTAzZDlhMjY3NGUyZWMyYmIyY2M5M2ExYTAxNmY=
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README.md
CHANGED
@@ -1,14 +1,14 @@
|
|
1
|
-
Relaxo Query Server
|
2
|
-
===================
|
3
|
-
|
4
|
-
* Author: Samuel G. D. Williams (<http://www.oriontransfer.co.nz>)
|
5
|
-
* Copyright (C) 2012 Samuel G. D. Williams.
|
6
|
-
* Released under the MIT license.
|
1
|
+
# Relaxo Query Server
|
7
2
|
|
8
3
|
The Relaxo Query Server implements the CouchDB Query Server protocol for CouchDB 1.1.0+. It provides a comprehensive Ruby-style view server along with full support for Design Document based processing.
|
9
4
|
|
10
|
-
|
11
|
-
|
5
|
+
For more information and examples please see the main [project page][1].
|
6
|
+
|
7
|
+
[1]: http://www.codeotaku.com/projects/relaxo/query-server
|
8
|
+
|
9
|
+
[![Build Status](https://secure.travis-ci.org/ioquatix/relaxo-query-server.png)](http://travis-ci.org/ioquatix/relaxo-query-server)
|
10
|
+
|
11
|
+
## Installation
|
12
12
|
|
13
13
|
Install the ruby gem as follows:
|
14
14
|
|
@@ -27,15 +27,9 @@ Make sure the `relaxo-query-server` executable is accessible from `$PATH`.
|
|
27
27
|
|
28
28
|
(You can also load code by specifying libraries in your design documents and views.)
|
29
29
|
|
30
|
-
|
30
|
+
##Usage
|
31
31
|
|
32
|
-
|
33
|
-
sudo GEM=gem1.9 rake1.9 install_gem
|
34
|
-
|
35
|
-
Usage
|
36
|
-
-----
|
37
|
-
|
38
|
-
### Mapping Function ###
|
32
|
+
### Mapping Function
|
39
33
|
|
40
34
|
Select documents of `type == 'user'`:
|
41
35
|
|
@@ -45,7 +39,7 @@ Select documents of `type == 'user'`:
|
|
45
39
|
end
|
46
40
|
end
|
47
41
|
|
48
|
-
### Reduction Function
|
42
|
+
### Reduction Function
|
49
43
|
|
50
44
|
Calculate the sum:
|
51
45
|
|
@@ -53,7 +47,7 @@ Calculate the sum:
|
|
53
47
|
values.inject &:+
|
54
48
|
end
|
55
49
|
|
56
|
-
### Design Document
|
50
|
+
### Design Document
|
57
51
|
|
58
52
|
A simple application:
|
59
53
|
|
@@ -105,18 +99,24 @@ The previous `design.yaml` document can be loaded using the `relaxo` client comm
|
|
105
99
|
|
106
100
|
relaxo http://localhost:5984/test design.yaml
|
107
101
|
|
108
|
-
|
109
|
-
|
102
|
+
## Contributing
|
103
|
+
|
104
|
+
1. Fork it
|
105
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
106
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
107
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
108
|
+
5. Create new Pull Request
|
109
|
+
|
110
|
+
## To Do
|
110
111
|
|
111
112
|
- Improve documentation, including better sample code.
|
112
113
|
- More tests, including performance benchmarks.
|
113
114
|
- Explore `parse_function` to improve performance of code execution by caching functions.
|
114
115
|
- Helper methods for commonly used mapping functions.
|
115
116
|
|
116
|
-
License
|
117
|
-
-------
|
117
|
+
## License
|
118
118
|
|
119
|
-
Copyright (c) 2010, 2012 Samuel G. D. Williams. <http://www.
|
119
|
+
Copyright (c) 2010, 2012 Samuel G. D. Williams. <http://www.codeotaku.com>
|
120
120
|
|
121
121
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
122
122
|
of this software and associated documentation files (the "Software"), to deal
|
@@ -69,7 +69,8 @@ module Relaxo
|
|
69
69
|
when 'add_fun'
|
70
70
|
@mapper.add_function command[1]; true
|
71
71
|
when 'add_lib'
|
72
|
-
@mapper.add_libraries command[1]
|
72
|
+
@mapper.add_libraries command[1]
|
73
|
+
@reducer.add_libraries command[1]; true
|
73
74
|
when 'map_doc'
|
74
75
|
@mapper.map command[1]
|
75
76
|
when 'reset'
|
@@ -78,5 +78,26 @@ module Relaxo
|
|
78
78
|
@instance ||= @klass.new
|
79
79
|
end
|
80
80
|
end
|
81
|
+
|
82
|
+
class Loader
|
83
|
+
# The default library name
|
84
|
+
DEFAULT = ['_default']
|
85
|
+
|
86
|
+
def initialize
|
87
|
+
@libraries = {}
|
88
|
+
end
|
89
|
+
|
90
|
+
def load(path)
|
91
|
+
Library.for(@libraries, path)
|
92
|
+
end
|
93
|
+
|
94
|
+
def add_libraries(libraries)
|
95
|
+
@libraries.merge!(libraries)
|
96
|
+
end
|
97
|
+
|
98
|
+
def load_default
|
99
|
+
load(DEFAULT)
|
100
|
+
end
|
101
|
+
end
|
81
102
|
end
|
82
103
|
end
|
@@ -53,34 +53,23 @@ module Relaxo
|
|
53
53
|
end
|
54
54
|
end
|
55
55
|
|
56
|
-
class Mapper
|
57
|
-
# The default library name
|
58
|
-
DEFAULT = ['_default']
|
59
|
-
|
56
|
+
class Mapper < Loader
|
60
57
|
def initialize(context)
|
58
|
+
super()
|
59
|
+
|
61
60
|
@context = context
|
62
61
|
@functions = []
|
63
|
-
|
64
|
-
@libraries = {}
|
65
62
|
end
|
66
63
|
|
67
64
|
# Adds a function by parsing the text, typically containing a textual representation of a lambda.
|
68
|
-
def add_function
|
65
|
+
def add_function(text)
|
69
66
|
@functions << @context.parse_function(text, binding)
|
70
67
|
end
|
71
68
|
|
72
|
-
def load(path)
|
73
|
-
Library.for(@libraries, path)
|
74
|
-
end
|
75
|
-
|
76
|
-
def add_libraries libraries
|
77
|
-
@libraries = libraries
|
78
|
-
end
|
79
|
-
|
80
69
|
# Map a document to a set of results by appling all functions.
|
81
70
|
def map(document)
|
82
71
|
# Force load the default library:
|
83
|
-
|
72
|
+
load_default
|
84
73
|
|
85
74
|
@functions.map do |function|
|
86
75
|
MappingProcess.new(@context, @libraries, function).run(document)
|
@@ -19,6 +19,7 @@
|
|
19
19
|
# THE SOFTWARE.
|
20
20
|
|
21
21
|
require 'relaxo/query_server/process'
|
22
|
+
require 'relaxo/query_server/library'
|
22
23
|
|
23
24
|
module Relaxo
|
24
25
|
module QueryServer
|
@@ -35,9 +36,11 @@ module Relaxo
|
|
35
36
|
end
|
36
37
|
|
37
38
|
# Implements the `reduce` and `rereduce` functions along with all associated state.
|
38
|
-
class Reducer
|
39
|
+
class Reducer < Loader
|
39
40
|
# Create a reducer attached to the given context.
|
40
41
|
def initialize(context)
|
42
|
+
super()
|
43
|
+
|
41
44
|
@context = context
|
42
45
|
end
|
43
46
|
|
@@ -53,6 +56,8 @@ module Relaxo
|
|
53
56
|
# @param [Array] items
|
54
57
|
# A composite list of items.
|
55
58
|
def reduce(functions, items)
|
59
|
+
load_default
|
60
|
+
|
56
61
|
functions = functions.collect do |function_text|
|
57
62
|
@context.parse_function(function_text, binding)
|
58
63
|
end
|
@@ -79,6 +84,8 @@ module Relaxo
|
|
79
84
|
# @param [Array] values
|
80
85
|
# An array of values to reduce
|
81
86
|
def rereduce(functions, values)
|
87
|
+
load_default
|
88
|
+
|
82
89
|
functions = functions.collect do |function_text|
|
83
90
|
@context.parse_function(function_text, binding)
|
84
91
|
end
|
data/rakefile.rb
CHANGED
@@ -0,0 +1,33 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'relaxo/query_server/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "relaxo-query-server"
|
8
|
+
spec.version = Relaxo::QueryServer::VERSION
|
9
|
+
spec.authors = ["Samuel Williams"]
|
10
|
+
spec.email = ["samuel.williams@oriontransfer.co.nz"]
|
11
|
+
spec.description = <<-EOF
|
12
|
+
Relaxo Query Server is a query server for CouchDB which provides full
|
13
|
+
support for map/reduce functionality using Ruby code. It's main purpose
|
14
|
+
is to provide a consistent backend for Ruby based clients to CouchDB.
|
15
|
+
In practice, it allows code to be shared between Ruby based client
|
16
|
+
applications and CouchDB servers.
|
17
|
+
EOF
|
18
|
+
spec.summary = %q{Relaxo Query Server provides support for executing CouchDB functions using Ruby.}
|
19
|
+
spec.homepage = ""
|
20
|
+
spec.license = "MIT"
|
21
|
+
|
22
|
+
spec.files = `git ls-files`.split($/)
|
23
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
24
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
25
|
+
spec.require_paths = ["lib"]
|
26
|
+
|
27
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
28
|
+
spec.add_development_dependency "rake"
|
29
|
+
|
30
|
+
spec.add_dependency "relaxo", "~> 0.4.0"
|
31
|
+
spec.add_dependency "json", "~> 1.7.3"
|
32
|
+
spec.add_dependency "rest-client"
|
33
|
+
end
|
data/test/helper.rb
CHANGED
@@ -8,8 +8,17 @@ require 'stringio'
|
|
8
8
|
require "relaxo/json"
|
9
9
|
require "relaxo/query_server"
|
10
10
|
|
11
|
+
class Test::Unit::TestCase
|
12
|
+
def self.abstract_test_case!
|
13
|
+
self.class_eval do
|
14
|
+
def test_default
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
11
20
|
class ContextualTestCase < Test::Unit::TestCase
|
12
|
-
|
21
|
+
abstract_test_case!
|
13
22
|
|
14
23
|
def setup_context(options)
|
15
24
|
@shell = Relaxo::QueryServer::MockShell.new
|
data/test/test_reduce.rb
CHANGED
@@ -12,4 +12,27 @@ class ReduceTest < ContextualTestCase
|
|
12
12
|
response = @context.run ["rereduce", [SUM, CONCAT], (0...10).map{|i|i}]
|
13
13
|
assert_equal [true, [45, "0_1_2_3_4_5_6_7_8_9"]], response
|
14
14
|
end
|
15
|
+
|
16
|
+
def test_reduce_libraries
|
17
|
+
library_code = %q{
|
18
|
+
def sum(values)
|
19
|
+
values.inject(&:+)
|
20
|
+
end
|
21
|
+
}
|
22
|
+
|
23
|
+
reduce_function = %q{
|
24
|
+
foo = load('foo')
|
25
|
+
|
26
|
+
lambda {|k,v,r|
|
27
|
+
puts v.inspect
|
28
|
+
foo.sum(v)
|
29
|
+
}
|
30
|
+
}
|
31
|
+
|
32
|
+
response = @context.run ['add_lib', {'foo' => library_code}]
|
33
|
+
assert_equal true, response
|
34
|
+
|
35
|
+
response = @context.run ['reduce', [reduce_function], (0...10).map{|i|[i,i]}]
|
36
|
+
assert_equal [true, [45]], response
|
37
|
+
end
|
15
38
|
end
|
metadata
CHANGED
@@ -1,60 +1,103 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: relaxo-query-server
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
segments:
|
6
|
-
- 0
|
7
|
-
- 1
|
8
|
-
- 2
|
9
|
-
version: 0.1.2
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.3
|
10
5
|
platform: ruby
|
11
|
-
authors:
|
6
|
+
authors:
|
12
7
|
- Samuel Williams
|
13
8
|
autorequire:
|
14
9
|
bindir: bin
|
15
10
|
cert_chain: []
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
11
|
+
date: 2013-04-04 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
22
35
|
prerelease: false
|
23
|
-
|
24
|
-
requirements:
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: relaxo
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
25
45
|
- - ~>
|
26
|
-
- !ruby/object:Gem::Version
|
27
|
-
segments:
|
28
|
-
- 0
|
29
|
-
- 4
|
30
|
-
- 0
|
46
|
+
- !ruby/object:Gem::Version
|
31
47
|
version: 0.4.0
|
32
48
|
type: :runtime
|
33
|
-
|
34
|
-
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.4.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
35
56
|
name: json
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 1.7.3
|
62
|
+
type: :runtime
|
36
63
|
prerelease: false
|
37
|
-
|
38
|
-
requirements:
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
39
66
|
- - ~>
|
40
|
-
- !ruby/object:Gem::Version
|
41
|
-
segments:
|
42
|
-
- 1
|
43
|
-
- 7
|
44
|
-
- 3
|
67
|
+
- !ruby/object:Gem::Version
|
45
68
|
version: 1.7.3
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rest-client
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ! '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
46
76
|
type: :runtime
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ! '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: ! "\tRelaxo Query Server is a query server for CouchDB which provides
|
84
|
+
full\n\tsupport for map/reduce functionality using Ruby code. It's main purpose\n\tis
|
85
|
+
to provide a consistent backend for Ruby based clients to CouchDB.\n\tIn practice,
|
86
|
+
it allows code to be shared between Ruby based client \n\tapplications and CouchDB
|
87
|
+
servers.\n"
|
88
|
+
email:
|
89
|
+
- samuel.williams@oriontransfer.co.nz
|
90
|
+
executables:
|
51
91
|
- relaxo-query-server
|
52
92
|
extensions: []
|
53
|
-
|
54
93
|
extra_rdoc_files: []
|
55
|
-
|
56
|
-
|
94
|
+
files:
|
95
|
+
- .gitignore
|
96
|
+
- .travis.yml
|
97
|
+
- Gemfile
|
98
|
+
- README.md
|
57
99
|
- bin/relaxo-query-server
|
100
|
+
- lib/relaxo/query_server.rb
|
58
101
|
- lib/relaxo/query_server/context.rb
|
59
102
|
- lib/relaxo/query_server/designer.rb
|
60
103
|
- lib/relaxo/query_server/library.rb
|
@@ -63,7 +106,8 @@ files:
|
|
63
106
|
- lib/relaxo/query_server/reducer.rb
|
64
107
|
- lib/relaxo/query_server/shell.rb
|
65
108
|
- lib/relaxo/query_server/version.rb
|
66
|
-
-
|
109
|
+
- rakefile.rb
|
110
|
+
- relaxo-query-server.gemspec
|
67
111
|
- test/helper.rb
|
68
112
|
- test/test_filters.rb
|
69
113
|
- test/test_libraries.rb
|
@@ -74,37 +118,39 @@ files:
|
|
74
118
|
- test/test_updates.rb
|
75
119
|
- test/test_validations.rb
|
76
120
|
- test/test_views.rb
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
licenses: []
|
82
|
-
|
121
|
+
homepage: ''
|
122
|
+
licenses:
|
123
|
+
- MIT
|
124
|
+
metadata: {}
|
83
125
|
post_install_message:
|
84
126
|
rdoc_options: []
|
85
|
-
|
86
|
-
require_paths:
|
127
|
+
require_paths:
|
87
128
|
- lib
|
88
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
89
|
-
requirements:
|
90
|
-
- -
|
91
|
-
- !ruby/object:Gem::Version
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
- !ruby/object:Gem::Version
|
99
|
-
segments:
|
100
|
-
- 0
|
101
|
-
version: "0"
|
129
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
130
|
+
requirements:
|
131
|
+
- - ! '>='
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '0'
|
134
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ! '>='
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
102
139
|
requirements: []
|
103
|
-
|
104
140
|
rubyforge_project:
|
105
|
-
rubygems_version:
|
141
|
+
rubygems_version: 2.0.2
|
106
142
|
signing_key:
|
107
|
-
specification_version:
|
108
|
-
summary: Relaxo Query Server provides support for executing CouchDB functions using
|
109
|
-
|
110
|
-
|
143
|
+
specification_version: 4
|
144
|
+
summary: Relaxo Query Server provides support for executing CouchDB functions using
|
145
|
+
Ruby.
|
146
|
+
test_files:
|
147
|
+
- test/helper.rb
|
148
|
+
- test/test_filters.rb
|
149
|
+
- test/test_libraries.rb
|
150
|
+
- test/test_lists.rb
|
151
|
+
- test/test_map.rb
|
152
|
+
- test/test_reduce.rb
|
153
|
+
- test/test_shows.rb
|
154
|
+
- test/test_updates.rb
|
155
|
+
- test/test_validations.rb
|
156
|
+
- test/test_views.rb
|