sdbcli
Description
sdbcli is an interactive command-line client of Amazon SimpleDB.
Source Code
bitbucket.org/winebarrel/sdbcli
Install
shell> gem install sdbcli
shell> sdbcli -h
Usage: sdbcli [options]
-k, --access-key=ACCESS_KEY
-s, --secret-key=SECRET_KEY
-r, --region=REGION
-e, --eval=COMMAND
-f, --format=YAML_OR_JSON
-c, --consistent
-t, --timeout=SECOND
--import=DOMAIN,FILE
--import-replace=DOMAIN,FILE
--export=DOMAIN,FILE
--retry=NUM
--retry-interval=SECOND
shell> export AWS_ACCESS_KEY_ID='...'
shell> export AWS_SECRET_ACCESS_KEY='...'
shell> export SDB_ENDPOINT='sdb.ap-northeast-1.amazonaws.com' # or SDB_REGION=ap-northeast-1
shell> sdbcli -e 'show domains'
---
- test
- test-2
shell> sdbcli -f json -e 'show domains'
[
"test",
"test-2"
]
shell> sdbcli # show prompt
Example
ap-northeast-1> .help
# Explanatory notes of a query
SHOW DOMAINS
displays a domain list
SHOW REGIONS
displays a region list
CREATE domain domain_name
creates a domain
DROP DOMAIN domain_name
deletes a domain
GET [attr_list] FROM domain_name WHERE itemName = '...'
gets the attribute of an item
INSERT INTO domain_name (itemName, attr1, ...) VALUES ('name1', 'val1', ...), ('name2', 'val2', ...), ...
creates an item
UPDATE domain_name {SET|ADD} attr1 = 'val1', ... WHERE itemName = '...'
UPDATE domain_name {SET|ADD} attr1 = 'val1', ... [WHERE expression] [sort_instructions] [LIMIT limit]
updates an item
DELETE [attr1, ...] FROM domain_name WHERE itemName = '...'
DELETE [attr1, ...] FROM domain_name WHERE [WHERE expression] [sort_instructions] [LIMIT limit]
deletes the attribute of an item or an item
SELECT output_list FROM domain_name [WHERE expression] [sort_instructions] [LIMIT limit] [ | ruby script ]
queries using the SELECT statement
see http://docs.aws.amazon.com/AmazonSimpleDB/latest/DeveloperGuide/UsingSelect.html
DESC domain_name
displays information about the domain
USE region_or_endpoint
changes an endpoint
# List of commands
.help displays this message
.quit | .exit exits sdbcli
.format (yaml|json)? displays a format or changes it
.consistent (true|false)? displays ConsistentRead parameter or changes it
.timeout SECOND displays a timeout second or changes it
.version displays a version
ap-northeast-1> select * from test;
---
- [itemname1, {attr1: val1, attr2: val2}]
- [itemname2, {attr1: val1, attr2: val2}]
# 2 rows in set
ap-northeast-1> select count(*) from `test-2`;
---
- [Domain, {Count: "100"}]
# 1 row in set
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. You must quote all other attribute and domain names with the backtick (‘). see docs.amazonwebservices.com/AmazonSimpleDB/latest/DeveloperGuide/QuotingRulesSelect.html
ap-northeast-1> select * from test \G
---
- - itemname1
- attr1: val1
attr2: val2
- itemname2
- attr1: val1
attr2: val2
# 2 rows in set
shell> echo 'select * from test' | sdbcli
---
- [itemname1, {attr1: val1, attr2: val2}]
- [itemname2, {attr1: val1, attr2: val2}]
Import/Export
shell> sdbcli -f json --export=employees,employees.json
// 2500 rows was outputted...
// 5000 rows was outputted...
// 7500 rows was outputted...
...
shell> sdbcli -f json --import=employees,employees.json
// 2500 rows was inputted...
// 5000 rows was inputted...
// 7500 rows was inputted...
If ‘-’ is specified as a file name, the input/output of data will become a standard input/output.
Pipe to ruby
ap-northeast-1> select * from employees limit 3;
---
- ["100000", {first_name: Hiroyasu, hire_date: "1991-07-02", birth_date: "1956-01-11", last_name: Emden}]
- ["100001", {first_name: Jasminko, hire_date: "1994-12-25", birth_date: "1953-02-07", last_name: Antonakopoulos}]
- ["100002", {first_name: Claudi, hire_date: "1988-02-20", birth_date: "1957-03-04", last_name: Kolinko}]
# 3 rows in set
ap-northeast-1> select * from employees limit 3 | hire_date.max;
--- "1994-12-25"
ap-northeast-1> select * from employees limit 3 | hire_date.to_i;
---
- 1991
- 1994
- 1988
# 3 rows in set
ap-northeast-1> select * from employees limit 3 | hire_date.to_f.avg;
--- 1991.0
‘sum’ method and ‘avg’ method are added to Array class.