couchup 0.0.10 → 0.0.11

Sign up to get free protection for your applications and to get access to all the features.
@@ -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
 
@@ -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
@@ -18,8 +18,3 @@ Couchup::Commands.constants.each do |c|
18
18
  end
19
19
  end"
20
20
  end
21
-
22
- puts "Type help to view the list of things you can do. And Yeah Relax."
23
-
24
-
25
-
@@ -2,12 +2,16 @@ module Couchup
2
2
  module Commands
3
3
  class Drop
4
4
  def run(*params)
5
- db = params.first.nil? ? Couchup.server.database : Couchup.server.database(params.first)
6
- db.delete!
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
@@ -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 retuns the results"
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 vies is specified. defaults to databases."
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
@@ -2,7 +2,10 @@ module Couchup
2
2
  module Commands
3
3
  class View
4
4
  def run(*params)
5
- MapReduce.reduce(*params)
5
+ rows = MapReduce.reduce(*params)
6
+ puts "Found #{rows.size} item(s)"
7
+ rows.each{|r| puts r.inspect}
8
+ nil
6
9
  end
7
10
 
8
11
  def self.describe(params = nil)
@@ -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
@@ -25,9 +25,6 @@ module Couchup
25
25
  end
26
26
  response = Couchup.database.view(name, view_params)
27
27
  rows = response["rows"]
28
- puts "Found #{rows.size} item(s)"
29
- rows.each{|r| puts r.inspect}
30
- nil
31
28
  end
32
29
  end
33
30
  end
@@ -1,3 +1,3 @@
1
1
  module Couchup
2
- VERSION = "0.0.10"
2
+ VERSION = "0.0.11"
3
3
  end
@@ -50,6 +50,11 @@ module Couchup
50
50
  def reduce?
51
51
  @doc["views"][@name] && !@doc["views"][@name]["reduce"].blank?
52
52
  end
53
+
54
+ def delete!
55
+ @doc["views"].delete(@name)
56
+ save
57
+ end
53
58
 
54
59
 
55
60
  def self.create(name, file_contents)
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: couchup
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.10
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-26 00:00:00 +05:30
13
+ date: 2011-02-27 00:00:00 +05:30
14
14
  default_executable: ey
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency