All Projects → walkersumida → dynamodb-api

walkersumida / dynamodb-api

Licence: MIT License
DynamoDB API wrapper gem. like SQL and simply.

Programming Languages

ruby
36898 projects - #4 most used programming language

Projects that are alternatives of or similar to dynamodb-api

slow-down
A centralized Redis-based lock to help you wait on throttled resources
Stars: ✭ 21 (+40%)
Mutual labels:  gem
pretty trace
Love Your Ruby's Backtrace
Stars: ✭ 13 (-13.33%)
Mutual labels:  gem
academic
Jekyll theme with a focus on simplicity, typography and flexibility
Stars: ✭ 71 (+373.33%)
Mutual labels:  gem
iis
开源微博平台 Open source cloud powered microblog
Stars: ✭ 42 (+180%)
Mutual labels:  dynamodb
yo-ruby
🌈 ✨ A super awesome Ruby wrapper of the Yo API.
Stars: ✭ 15 (+0%)
Mutual labels:  gem
serverless-grocery-app
Grocery Purchase app with serverless AWS Lambda + DynamoDB + React
Stars: ✭ 28 (+86.67%)
Mutual labels:  dynamodb
graphql-pynamodb
Graphene PynamoDB Integration
Stars: ✭ 63 (+320%)
Mutual labels:  dynamodb
arclight
A Rails engine supporting discovery of archival material
Stars: ✭ 25 (+66.67%)
Mutual labels:  gem
jquery-datatables
Jquery datatables ruby gems for assets pipeline
Stars: ✭ 73 (+386.67%)
Mutual labels:  gem
enumerations
Better Rails Enumerations
Stars: ✭ 34 (+126.67%)
Mutual labels:  gem
ae page objects
Page Objects for Capybara
Stars: ✭ 26 (+73.33%)
Mutual labels:  gem
rack-simple user agent
Rack::SimpleUserAgent is stupidly simple UA detector
Stars: ✭ 13 (-13.33%)
Mutual labels:  gem
road-to-orleans
This repository illustrates the road to orleans with practical, real-life examples. From most basic, to more advanced techniques.
Stars: ✭ 55 (+266.67%)
Mutual labels:  dynamodb
twitter
A serverless social network that's under development with some cool stuff, such as Serverless Framework, AppSync, GraphQL, Lambda, DynamoDB, Cognito, Kinesis Firehose, and Algolia ☁️
Stars: ✭ 29 (+93.33%)
Mutual labels:  dynamodb
snapcrawl
Crawl a website and take screenshots
Stars: ✭ 37 (+146.67%)
Mutual labels:  gem
hyper-kube-config
H Y P E R K U B E - A Serverless API and kubectl plugin providing a storage and retrieval Kubernetes cluster credentials. Hyperkube leverages AWS Secrets Manager for storing credential information.
Stars: ✭ 27 (+80%)
Mutual labels:  dynamodb
dynamoc
A DynamoDB GUI client https://ieiayaobb.github.io/dynamoc/
Stars: ✭ 70 (+366.67%)
Mutual labels:  dynamodb
nomad-ruby
The official Ruby client for Nomad
Stars: ✭ 27 (+80%)
Mutual labels:  gem
pwdcalc
Take no risk and help your users to choose good passwords!
Stars: ✭ 11 (-26.67%)
Mutual labels:  gem
log-symbols
A ruby 💎gem💎 for generating log symbols
Stars: ✭ 14 (-6.67%)
Mutual labels:  gem

Dynamodb::Api

Build Status Gem Version

Installation

Add this line to your application's Gemfile:

gem 'dynamodb-api'

And then execute:

$ bundle

Or install it yourself as:

$ gem install dynamodb-api

Configuration

Rails

config/initializers/dynamodb_api.rb

Dynamodb::Api.config do |config|
  config.access_key_id = ''
  config.secret_access_key = ''
  config.region = ''
  config.table_name_prefix = ''
  config.index_name_prefix = ''
end

Other

Dynamodb::Api.config.access_key_id = ''
Dynamodb::Api.config.secret_access_key = ''
Dynamodb::Api.config.region = ''
Dynamodb::Api.config.table_name_prefix = ''
Dynamodb::Api.config.index_name_prefix = ''

How to use

e.g.

cars table.

id maker_id(Partition key) model release_date(Sort key) status
1 1 Accord 0.19760508e8 0
2 2 CROWN 0.19550101e8 0
3 3 Model S 0.20120601e8 0
4 1 S2000 0.19980101e8 1

Scan

Scan returns items in random order.

scan = Dynamodb::Api.scan
scan.from('cars')
items = scan.all.items
id maker_id(Partition key) model release_date(Sort key) status
1 1 Accord 0.19760508e8 0
2 2 CROWN 0.19550101e8 0
3 3 Model S 0.20120601e8 0
4 1 S2000 0.19980101e8 1

Filter

scan = Dynamodb::Api.scan
scan.from('cars').
  filter('model = :model', ':model': 'S2000')
items = scan.all.items
id maker_id(Partition key) model release_date(Sort key) status
4 1 S2000 0.19980101e8 1

Limit

scan = Dynamodb::Api.scan
scan.from('cars').
  limit(1)
items = scan.all.items
id maker_id(Partition key) model release_date(Sort key) status
1 1 Accord 0.19760508e8 0

Next(Paging)

scan = Dynamodb::Api.scan
scan.from('cars').
  limit(1)
_items = scan.all.items
items = scan.next.items
id maker_id(Partition key) model release_date(Sort key) status
2 2 CROWN 0.19550101e8 0

Query

https://docs.aws.amazon.com/sdkforruby/api/Aws/DynamoDB/Client.html#query-instance_method

Partition(Hash) key

query = Dynamodb::Api.query
query.from('cars').index('index_maker_id_release_date').
  where(['maker_id', '=', 1])
items = query.all.items
id maker_id(Partition key) model release_date(Sort key) status
4 1 S2000 0.19980101e8 1
1 1 Accord 0.19760508e8 0

Partition key and Sort(Range) key

query = Dynamodb::Api.query
query.from('cars').index('index_maker_id_release_date').
  where([['maker_id', '=', 1], ['release_date', '>=', 19_980_101]])
items = query.all.items
id maker_id(Partition key) model release_date(Sort key) status
4 1 S2000 0.19980101e8 1

Sorting

query = Dynamodb::Api.query
query.from('cars').index('index_maker_id_release_date').
  where(['maker_id', '=', 1]).
  order('asc') # default: 'desc'
items = query.all.items
id maker_id(Partition key) model release_date(Sort key) status
1 1 Accord 0.19760508e8 0
4 1 S2000 0.19980101e8 1

Filter

query = Dynamodb::Api.query
query.from('cars').index('index_maker_id_release_date').
  where(['maker_id', '=', 1]).
  filter('model = :model', ':model': 'S2000')
items = query.all.items
id maker_id(Partition key) model release_date(Sort key) status
4 1 S2000 0.19980101e8 1

Limit

query = Dynamodb::Api.query
query.from('cars').index('index_maker_id_release_date').
  where(['maker_id', '=', 1]).
  order('asc'). # default: 'desc'
  limit(1)
items = query.all.items
id maker_id(Partition key) model release_date(Sort key) status
1 1 Accord 0.19760508e8 0

Next(Paging)

query = Dynamodb::Api.query
query.from('cars').index('index_maker_id_release_date').
  where(['maker_id', '=', 1]).
  order('asc'). # default: 'desc'
  limit(1)
_items = query.all.items
items = query.next.items
id maker_id(Partition key) model release_date(Sort key) status
4 1 S2000 0.19980101e8 1

Expression Attribute Names

Words reserved in DynamoDB can not be used without special processing. In dynamodb-api , you can omit the special processing by putting # at the beginning of the word. Refer to the list of reserved words from here.

query = Dynamodb::Api.query
query.from('cars').index('index_maker_id_release_date').
  where(['maker_id', '=', 1]).
  filter('#status = :status', ':status': 1)
items = query.all.items
id maker_id(Partition key) model release_date(Sort key) status
4 1 S2000 0.19980101e8 1

If you don't add # to a reserved word, the following error will occur:

Aws::DynamoDB::Errors::ValidationException:
  Invalid FilterExpression: Attribute name is a reserved keyword; reserved keyword: [reserved word]

Insert

item = { id: '5', maker_id: 1, maker: 'Honda', model: 'NSX', release_date: 19900914 }
Dynamodb::Api.insert('cars', item)

Update

key = { id: '5' }
value = { new_col: 'new' }
Dynamodb::Api.update('cars', key, value)

Delete

key = { id: '5' }
Dynamodb::Api.delete('cars', key)

Remove attributes

key = { id: '3' }
attributes = ['status']
Dynamodb::Api.remove_attributes('cars', key, attributes)

query = Dynamodb::Api.query
query.from('cars').index('index_maker_id_release_date').
  where(['maker_id', '=', 3])
items = query.all.items
id maker_id(Partition key) model release_date(Sort key)
3 3 Model S 0.20120601e8

Other API operations

client returns the <Aws::DynamoDB::Client> . So, you can use all API operations.

client = Dynamodb::Api::Adapter.client # <Aws::DynamoDB::Client>

# e.g.
client.create_backup(
  table_name: 'TableName', # required
  backup_name: 'BackupName', # required
)

Development

  • Run docker-compose up to run the dynamodb_local.
  • Run docker-compose run ruby bundle exec rake spec to run the tests. Or run docker-compose run ruby bundle exec appraisal aws-sdk-* rake spec to run the tests. Replase * with aws sdk major version.
  • You can also run docker-compose run ruby bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run docker-compose run ruby bundle exec rake install. To release a new version, update the version number in version.rb, and then run docker-compose run ruby bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/dynamodb-api. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

License

The gem is available as open source under the terms of the MIT License.

Code of Conduct

Everyone interacting in the Dynamodb::Api project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].