couchup 0.0.10 → 0.0.11
Sign up to get free protection for your applications and to get access to all the features.
- data/Readme.markdown +11 -5
- data/bin/couchup +28 -0
- data/lib/couchup.rb +0 -5
- data/lib/couchup/commands/drop.rb +7 -3
- data/lib/couchup/commands/map.rb +6 -2
- data/lib/couchup/commands/show.rb +1 -1
- data/lib/couchup/commands/view.rb +4 -1
- data/lib/couchup/couchup.rb +11 -1
- data/lib/couchup/mapreduce.rb +0 -3
- data/lib/couchup/version.rb +1 -1
- data/lib/couchup/view.rb +5 -0
- metadata +2 -2
data/Readme.markdown
CHANGED
@@ -34,9 +34,20 @@ create "database", "riders"
|
|
34
34
|
Some Common Things to do with couchup
|
35
35
|
=====================================
|
36
36
|
|
37
|
+
Command line Params
|
38
|
+
-------------------
|
39
|
+
|
40
|
+
> couchup --help will print the help
|
41
|
+
|
42
|
+
use -h (or--host) to set the host machine to connect to
|
43
|
+
use -p (or --port) to set the port of the host couchdb
|
44
|
+
use -d (or --database) to set the database to use by default
|
45
|
+
|
46
|
+
|
37
47
|
Basics
|
38
48
|
--------
|
39
49
|
|
50
|
+
|
40
51
|
Connects to the couch server at foo.bar.com on the default port of 5984
|
41
52
|
|
42
53
|
> connect "foo.bar.com"
|
@@ -64,11 +75,6 @@ gets docucment by the given ID.
|
|
64
75
|
> get "id"
|
65
76
|
|
66
77
|
|
67
|
-
and because it is all in ruby you can do stuff like
|
68
|
-
|
69
|
-
get("123")[:history].first[:name]
|
70
|
-
|
71
|
-
|
72
78
|
#Running views
|
73
79
|
--------------
|
74
80
|
|
data/bin/couchup
CHANGED
@@ -3,6 +3,8 @@ require File.expand_path( "../../lib/couchup", __FILE__)
|
|
3
3
|
require 'irb'
|
4
4
|
require 'irb/completion'
|
5
5
|
|
6
|
+
require 'optparse'
|
7
|
+
|
6
8
|
if File.exists? ".irbrc"
|
7
9
|
ENV['IRBRC'] = ".irbrc"
|
8
10
|
end
|
@@ -11,6 +13,32 @@ if File.exists?( File.expand_path(rcfile = "~/.couchuprc") )
|
|
11
13
|
load(rcfile)
|
12
14
|
end
|
13
15
|
|
16
|
+
|
17
|
+
options = {}
|
18
|
+
OptionParser.new do |opts|
|
19
|
+
opts.banner = "Usage: example.rb [options]"
|
20
|
+
|
21
|
+
opts.on("-h", "--host HOST", "Host to connect to (Defaults to localhost)") do |h|
|
22
|
+
options[:host] = h
|
23
|
+
end
|
24
|
+
|
25
|
+
opts.on("-p", "--port PORT", "Port to connect to (Defaults to 5984)") do |port|
|
26
|
+
options[:port] = port
|
27
|
+
end
|
28
|
+
|
29
|
+
opts.on("-d", "--database DATABASE", "Database to connect to.") do |db|
|
30
|
+
options[:db] = db
|
31
|
+
end
|
32
|
+
|
33
|
+
end.parse!
|
34
|
+
|
35
|
+
host = options[:host] || 'localhost'
|
36
|
+
port = options[:port] || "5984"
|
37
|
+
Couchup::Commands::Connect.new.run(host, port)
|
38
|
+
Couchup::Commands::Use.new.run(options[:db]) unless options[:db].nil?
|
39
|
+
|
40
|
+
puts "Type help to view the list of things you can do. And Yeah Relax."
|
41
|
+
|
14
42
|
ARGV.clear
|
15
43
|
|
16
44
|
IRB.start
|
data/lib/couchup.rb
CHANGED
@@ -2,12 +2,16 @@ module Couchup
|
|
2
2
|
module Commands
|
3
3
|
class Drop
|
4
4
|
def run(*params)
|
5
|
-
|
6
|
-
|
5
|
+
op_type = params.shift.to_s
|
6
|
+
(params.first.nil? ? Couchup.database : Couchup.database(params.first)).delete! if op_type == 'database'
|
7
|
+
::Couchup::View.new(params.first).delete! if op_type == 'view'
|
8
|
+
Couchup.delete_doc(params.first) if op_type == 'doc'
|
9
|
+
Couchup.delete_all_docs(params.first) if op_type == 'all_docs'
|
10
|
+
|
7
11
|
end
|
8
12
|
|
9
13
|
def self.describe
|
10
|
-
"Drops a database. Use it with drop <dbname>"
|
14
|
+
"Drops a either of :database, :view , doc. Use it with drop :database, <dbname> or drop :view, 'Rider/test2', or drop :doc, <id> or even drop :all_docs which removes just the documents"
|
11
15
|
end
|
12
16
|
end
|
13
17
|
end
|
data/lib/couchup/commands/map.rb
CHANGED
@@ -2,11 +2,15 @@ module Couchup
|
|
2
2
|
module Commands
|
3
3
|
class Map
|
4
4
|
def run(*params)
|
5
|
-
MapReduce.map(*params)
|
5
|
+
rows = MapReduce.map(*params)
|
6
|
+
puts "Found #{rows.size} item(s)"
|
7
|
+
rows.each{|r| puts r.inspect}
|
8
|
+
nil
|
9
|
+
|
6
10
|
end
|
7
11
|
|
8
12
|
def self.describe(p = nil)
|
9
|
-
"Runs a view with just the map function and
|
13
|
+
"Runs a view with just the map function and returns the results"
|
10
14
|
end
|
11
15
|
end
|
12
16
|
end
|
@@ -11,7 +11,7 @@ module Couchup
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def self.describe
|
14
|
-
"show databases if databases is specified or views if
|
14
|
+
"show databases if databases is specified or views if views is specified. defaults to databases."
|
15
15
|
end
|
16
16
|
end
|
17
17
|
end
|
data/lib/couchup/couchup.rb
CHANGED
@@ -21,6 +21,16 @@ module Couchup
|
|
21
21
|
d["doc"]["views"].keys.collect{|view| "#{d['key'].gsub('_design/','')}/#{view}"}
|
22
22
|
end.flatten
|
23
23
|
end
|
24
|
+
def delete_doc(id)
|
25
|
+
doc = database.get(id)
|
26
|
+
database.delete_doc(doc)
|
27
|
+
end
|
28
|
+
def delete_all_docs(view_name)
|
29
|
+
all_docs = view_name.nil? ? all(:include_docs => true)["rows"] : MapReduce.map(view_name)
|
30
|
+
all_docs.collect{|d| d["doc"]}.each do |doc|
|
31
|
+
database.delete_doc(doc) unless (doc["_id"] =~ /^_design/)
|
32
|
+
end
|
33
|
+
end
|
24
34
|
|
25
35
|
def ready?
|
26
36
|
uuid = nil
|
@@ -38,7 +48,7 @@ module Couchup
|
|
38
48
|
end
|
39
49
|
|
40
50
|
def all(options={})
|
41
|
-
@db.documents
|
51
|
+
@db.documents(options)
|
42
52
|
end
|
43
53
|
|
44
54
|
def databases
|
data/lib/couchup/mapreduce.rb
CHANGED
data/lib/couchup/version.rb
CHANGED
data/lib/couchup/view.rb
CHANGED
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: couchup
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0.
|
5
|
+
version: 0.0.11
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- V Sreekanth
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-02-
|
13
|
+
date: 2011-02-27 00:00:00 +05:30
|
14
14
|
default_executable: ey
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|