Created
October 14, 2012 04:50
-
-
Save okaram/3887379 to your computer and use it in GitHub Desktop.
dynamodb examples
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
conn=boto.connect_dynamodb() # if set in ~/.boto | |
# or | |
conn = boto.connect_dynamodb(aws_access_key_id='...',aws_secret_access_key='...') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
myschema=conn.create_schema(hash_key_name='username',hash_key_proto_value='S'); | |
table=conn.create_table(name='users', schema=myschema, read_units=1, write_units=1); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
it=table.get_item("okaram") | |
# or select only some fields | |
it=table.get_item("okaram", attributes_to_get=['email']) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
user_data={'name':'Orlando Karam', 'password':'abc123', 'email':'[email protected]'}; | |
user=table.new_item(hash_key='okaram', attrs=user_data); | |
user.put(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
users=table.scan(scan_filter={'username':CONTAINS('o')}) | |
# and later we cab iterate like | |
for user in users: | |
print user; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment