sdbcli 0.1.6 → 0.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README +4 -0
- data/bin/sdbcli +127 -103
- data/lib/sdbcli/sdb-driver.rb +8 -1
- metadata +7 -5
data/README
CHANGED
@@ -47,6 +47,10 @@ https://bitbucket.org/winebarrel/sdbcli
|
|
47
47
|
---
|
48
48
|
- [itemname1, {attr1: val1, attr2: val2}]
|
49
49
|
- [itemname2, {attr1: val1, attr2: val2}]
|
50
|
+
|
51
|
+
Attribute and domain names may appear without quotes if they contain only letters, numbers, underscores (_), or dollar symbols ($) and do not start with a number.
|
52
|
+
You must quote all other attribute and domain names with the backtick (`).
|
53
|
+
see http://docs.amazonwebservices.com/AmazonSimpleDB/latest/DeveloperGuide/QuotingRulesSelect.html
|
50
54
|
|
51
55
|
ap-northeast-1> select * from test \G
|
52
56
|
---
|
data/bin/sdbcli
CHANGED
@@ -1,103 +1,127 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
$LOAD_PATH << File.join(File.expand_path(File.dirname(__FILE__)), '..', 'lib')
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
require '
|
9
|
-
|
10
|
-
require '
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
opt.on('-
|
20
|
-
opt.
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
region =
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
$LOAD_PATH << File.join(File.expand_path(File.dirname(__FILE__)), '..', 'lib')
|
3
|
+
|
4
|
+
Version = '0.1.6'
|
5
|
+
HISTORY_FILE = File.join((ENV['HOME'] || ENV['USERPROFILE'] || '.'), '.sdbcli_history')
|
6
|
+
|
7
|
+
require 'rubygems'
|
8
|
+
require 'sdbcli'
|
9
|
+
|
10
|
+
require 'optparse'
|
11
|
+
require 'readline'
|
12
|
+
require 'yaml'
|
13
|
+
|
14
|
+
access_key_id = ENV['AWS_ACCESS_KEY_ID']
|
15
|
+
secret_access_key = ENV['AWS_SECRET_ACCESS_KEY']
|
16
|
+
sdb_endpoint = ENV['SDB_ENDPOINT'] || 'sdb.amazonaws.com'
|
17
|
+
|
18
|
+
ARGV.options do |opt|
|
19
|
+
opt.on('-k', '--access-key=ACCESS_KEY') {|v| access_key_id = v }
|
20
|
+
opt.on('-s', '--secret-key=SECRET_KEY') {|v| secret_access_key = v }
|
21
|
+
opt.on('-e', '--endpoint=ENDPOINT') {|v| sdb_endpoint = v }
|
22
|
+
opt.parse!
|
23
|
+
|
24
|
+
unless access_key_id and secret_access_key and sdb_endpoint
|
25
|
+
puts opt.help
|
26
|
+
exit 1
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
$runner = SimpleDB::Runner.new(access_key_id, secret_access_key, sdb_endpoint)
|
31
|
+
|
32
|
+
def execute(query)
|
33
|
+
query = query.strip.sub(/\s*;\Z/, '')
|
34
|
+
inline = true
|
35
|
+
|
36
|
+
if query =~ /\s*\\G\Z/i
|
37
|
+
query = query.sub(/\s*\\G\Z/i, '')
|
38
|
+
inline = false
|
39
|
+
end
|
40
|
+
|
41
|
+
out = $runner.execute(query, inline)
|
42
|
+
|
43
|
+
if out
|
44
|
+
out = YAML.dump(out)
|
45
|
+
out << "\n" unless out =~ /\n\n\Z/
|
46
|
+
puts out
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
unless $stdin.tty?
|
51
|
+
execute($stdin.read)
|
52
|
+
exit 0
|
53
|
+
end
|
54
|
+
|
55
|
+
if sdb_endpoint =~ /sdb\.([^.]+)\.amazonaws\.com/
|
56
|
+
region = $1
|
57
|
+
else
|
58
|
+
region = 'us-east-1'
|
59
|
+
end
|
60
|
+
|
61
|
+
def help
|
62
|
+
<<-EOS
|
63
|
+
SHOW domains
|
64
|
+
displays a domain list
|
65
|
+
|
66
|
+
CREATE domain domain_name
|
67
|
+
creates a domain
|
68
|
+
|
69
|
+
DROP DOMAIN domain_name
|
70
|
+
deletes a domain
|
71
|
+
|
72
|
+
GET [attr_list] FROM domain_name WHERE itemName = '...'
|
73
|
+
gets the attribute of an item
|
74
|
+
|
75
|
+
INSERT INTO domain_name (itemName, attr1, ...) values ('name', 'val1', ...)
|
76
|
+
creates an item
|
77
|
+
|
78
|
+
UPDATE domain_name set attr1 = 'val1', ... where itemName = '...'
|
79
|
+
updates an item
|
80
|
+
|
81
|
+
DELETE [attr1, ...] FROM domain_name itemName = '...'
|
82
|
+
deletes the attribute of an item or an item
|
83
|
+
|
84
|
+
SELECT output_list FROM domain_name [where expression] [sort_instructions] [limit limit]
|
85
|
+
queries using the SELECT statement
|
86
|
+
|
87
|
+
EOS
|
88
|
+
end
|
89
|
+
|
90
|
+
if File.exist?(HISTORY_FILE)
|
91
|
+
open(HISTORY_FILE) do |f|
|
92
|
+
f.each_line do |line|
|
93
|
+
line = line.strip
|
94
|
+
Readline::HISTORY.push(line) unless line.empty?
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
at_exit do
|
100
|
+
unless Readline::HISTORY.empty?
|
101
|
+
open(HISTORY_FILE, 'a') do |f|
|
102
|
+
Readline::HISTORY.each do |line|
|
103
|
+
line = line.strip
|
104
|
+
f.puts line
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
while buf = Readline.readline("#{region}> ", true)
|
111
|
+
Readline::HISTORY.pop if /\A\s*\Z/ =~ buf
|
112
|
+
|
113
|
+
begin
|
114
|
+
case buf.downcase
|
115
|
+
when 'help'
|
116
|
+
puts help
|
117
|
+
when 'exit', 'quit'
|
118
|
+
exit
|
119
|
+
when 'version'
|
120
|
+
puts "sdbcli #{Version}"
|
121
|
+
else
|
122
|
+
execute(buf)
|
123
|
+
end
|
124
|
+
rescue => e
|
125
|
+
puts e.message.strip
|
126
|
+
end
|
127
|
+
end
|
data/lib/sdbcli/sdb-driver.rb
CHANGED
@@ -4,6 +4,8 @@ module SimpleDB
|
|
4
4
|
class Error < StandardError; end
|
5
5
|
|
6
6
|
class Driver
|
7
|
+
attr_accessor :iteratable
|
8
|
+
|
7
9
|
def initialize(accessKeyId, secretAccessKey, endpoint = 'sdb.amazonaws.com')
|
8
10
|
@client = Client.new(accessKeyId, secretAccessKey, endpoint)
|
9
11
|
end
|
@@ -157,7 +159,12 @@ module SimpleDB
|
|
157
159
|
@params.update(:NextToken => @token.content) if @token != :first
|
158
160
|
doc = @client.send(@method, @params)
|
159
161
|
yield(doc)
|
160
|
-
|
162
|
+
|
163
|
+
if @iteratable
|
164
|
+
@token = doc.at_css('NextToken')
|
165
|
+
else
|
166
|
+
@token = nil
|
167
|
+
end
|
161
168
|
end
|
162
169
|
end
|
163
170
|
end # Iterator
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sdbcli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 21
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 7
|
10
|
+
version: 0.1.7
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- winebarrel
|
@@ -15,7 +15,8 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-01-17 00:00:00
|
18
|
+
date: 2012-01-17 00:00:00 +09:00
|
19
|
+
default_executable:
|
19
20
|
dependencies:
|
20
21
|
- !ruby/object:Gem::Dependency
|
21
22
|
name: nokogiri
|
@@ -48,6 +49,7 @@ files:
|
|
48
49
|
- lib/sdbcli/sdb-parser.y
|
49
50
|
- lib/sdbcli/sdb-runner.rb
|
50
51
|
- lib/sdbcli.rb
|
52
|
+
has_rdoc: true
|
51
53
|
homepage: https://bitbucket.org/winebarrel/sdbcli
|
52
54
|
licenses: []
|
53
55
|
|
@@ -77,7 +79,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
77
79
|
requirements: []
|
78
80
|
|
79
81
|
rubyforge_project:
|
80
|
-
rubygems_version: 1.
|
82
|
+
rubygems_version: 1.4.2
|
81
83
|
signing_key:
|
82
84
|
specification_version: 3
|
83
85
|
summary: sdbcli is an interactive command-line client of Amazon SimpleDB.
|