{"id":15632210,"url":"https://github.com/walkersumida/dynamodb-api","last_synced_at":"2025-04-30T06:44:42.659Z","repository":{"id":54761527,"uuid":"140596905","full_name":"walkersumida/dynamodb-api","owner":"walkersumida","description":"AWS DynamoDB SDK wrapper gem. like ActiveRecord and simply.","archived":false,"fork":false,"pushed_at":"2021-06-27T13:28:53.000Z","size":165,"stargazers_count":16,"open_issues_count":4,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-30T06:44:37.331Z","etag":null,"topics":["aws","dynamodb","gem","ruby"],"latest_commit_sha":null,"homepage":"https://rubygems.org/gems/dynamodb-api","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/walkersumida.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-07-11T15:44:26.000Z","updated_at":"2022-11-14T01:43:18.000Z","dependencies_parsed_at":"2022-08-14T02:00:59.567Z","dependency_job_id":null,"html_url":"https://github.com/walkersumida/dynamodb-api","commit_stats":null,"previous_names":[],"tags_count":20,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/walkersumida%2Fdynamodb-api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/walkersumida%2Fdynamodb-api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/walkersumida%2Fdynamodb-api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/walkersumida%2Fdynamodb-api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/walkersumida","download_url":"https://codeload.github.com/walkersumida/dynamodb-api/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251658196,"owners_count":21622819,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["aws","dynamodb","gem","ruby"],"created_at":"2024-10-03T10:43:00.483Z","updated_at":"2025-04-30T06:44:42.639Z","avatar_url":"https://github.com/walkersumida.png","language":"Ruby","readme":"# Dynamodb::Api\n\n![Build Status](https://github.com/walkersumida/dynamodb-api/workflows/build/badge.svg?branch=master)\n[![Gem Version](https://badge.fury.io/rb/dynamodb-api.svg)](https://badge.fury.io/rb/dynamodb-api)\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'dynamodb-api'\n```\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install dynamodb-api\n\n## Configuration\n\n### Rails\n\n`config/initializers/dynamodb_api.rb`\n\n```ruby\nDynamodb::Api.config do |config|\n  config.access_key_id = ''\n  config.secret_access_key = ''\n  config.region = ''\n  config.table_name_prefix = ''\n  config.index_name_prefix = ''\nend\n```\n\n### Other\n\n```ruby\nDynamodb::Api.config.access_key_id = ''\nDynamodb::Api.config.secret_access_key = ''\nDynamodb::Api.config.region = ''\nDynamodb::Api.config.table_name_prefix = ''\nDynamodb::Api.config.index_name_prefix = ''\n```\n\n## How to use\ne.g.\n\ncars table.\n\n| id | maker_id(Partition key) | model | release_date(Sort key) | status |\n|:---|:---|:---|:---|:---|\n|1 |1 |Accord |0.19760508e8 |0 |\n|2 |2 |CROWN |0.19550101e8 |0 |\n|3 |3 |Model S |0.20120601e8 |0 |\n|4 |1 |S2000 |0.19980101e8 |1 |\n\n### Scan\n\nScan returns items in random order.\n\n```ruby\nscan = Dynamodb::Api.scan\nscan.from('cars')\nitems = scan.all.items\n```\n\n| id | maker_id(Partition key) | model | release_date(Sort key) | status |\n|:---|:---|:---|:---|:---|\n|1 |1 |Accord |0.19760508e8 |0 |\n|2 |2 |CROWN |0.19550101e8 |0 |\n|3 |3 |Model S |0.20120601e8 |0 |\n|4 |1 |S2000 |0.19980101e8 |1 |\n\n#### Filter\n\n```ruby\nscan = Dynamodb::Api.scan\nscan.from('cars').\n  filter('model = :model', ':model': 'S2000')\nitems = scan.all.items\n```\n\n| id | maker_id(Partition key) | model | release_date(Sort key) | status |\n|:---|:---|:---|:---|:---|\n|4 |1 |S2000 |0.19980101e8 |1 |\n\n#### Limit\n\n```ruby\nscan = Dynamodb::Api.scan\nscan.from('cars').\n  limit(1)\nitems = scan.all.items\n```\n\n| id | maker_id(Partition key) | model | release_date(Sort key) | status |\n|:---|:---|:---|:---|:---|\n|1 |1 |Accord |0.19760508e8 |0 |\n\n#### Next(Paging)\n\n```ruby\nscan = Dynamodb::Api.scan\nscan.from('cars').\n  limit(1)\n_items = scan.all.items\nitems = scan.next.items\n```\n\n| id | maker_id(Partition key) | model | release_date(Sort key) | status |\n|:---|:---|:---|:---|:---|\n|2 |2 |CROWN |0.19550101e8 |0 |\n\n\n### Query\nhttps://docs.aws.amazon.com/sdkforruby/api/Aws/DynamoDB/Client.html#query-instance_method\n\n#### Partition(Hash) key\n\n```ruby\nquery = Dynamodb::Api.query\nquery.from('cars').index('index_maker_id_release_date').\n  where(['maker_id', '=', 1])\nitems = query.all.items\n```\n\n| id | maker_id(Partition key) | model | release_date(Sort key) | status |\n|:---|:---|:---|:---|:---|\n|4 |1 |S2000 |0.19980101e8 |1 |\n|1 |1 |Accord |0.19760508e8 |0 |\n\n#### Partition key and Sort(Range) key\n\n```ruby\nquery = Dynamodb::Api.query\nquery.from('cars').index('index_maker_id_release_date').\n  where([['maker_id', '=', 1], ['release_date', '\u003e=', 19_980_101]])\nitems = query.all.items\n```\n\n| id | maker_id(Partition key) | model | release_date(Sort key) | status |\n|:---|:---|:---|:---|:---|\n|4 |1 |S2000 |0.19980101e8 |1 |\n\n#### Sorting\n\n```ruby\nquery = Dynamodb::Api.query\nquery.from('cars').index('index_maker_id_release_date').\n  where(['maker_id', '=', 1]).\n  order('asc') # default: 'desc'\nitems = query.all.items\n```\n\n| id | maker_id(Partition key) | model | release_date(Sort key) | status |\n|:---|:---|:---|:---|:---|\n|1 |1 |Accord |0.19760508e8 |0 |\n|4 |1 |S2000 |0.19980101e8 |1 |\n\n#### Filter\n\n```ruby\nquery = Dynamodb::Api.query\nquery.from('cars').index('index_maker_id_release_date').\n  where(['maker_id', '=', 1]).\n  filter('model = :model', ':model': 'S2000')\nitems = query.all.items\n```\n\n| id | maker_id(Partition key) | model | release_date(Sort key) | status |\n|:---|:---|:---|:---|:---|\n|4 |1 |S2000 |0.19980101e8 |1 |\n\n#### Limit\n\n```ruby\nquery = Dynamodb::Api.query\nquery.from('cars').index('index_maker_id_release_date').\n  where(['maker_id', '=', 1]).\n  order('asc'). # default: 'desc'\n  limit(1)\nitems = query.all.items\n```\n\n| id | maker_id(Partition key) | model | release_date(Sort key) | status |\n|:---|:---|:---|:---|:---|\n|1 |1 |Accord |0.19760508e8 |0 |\n\n####  Next(Paging)\n\n```ruby\nquery = Dynamodb::Api.query\nquery.from('cars').index('index_maker_id_release_date').\n  where(['maker_id', '=', 1]).\n  order('asc'). # default: 'desc'\n  limit(1)\n_items = query.all.items\nitems = query.next.items\n```\n\n| id | maker_id(Partition key) | model | release_date(Sort key) | status |\n|:---|:---|:---|:---|:---|\n|4 |1 |S2000 |0.19980101e8 |1 |\n\n#### Expression Attribute Names\n\nWords reserved in DynamoDB can not be used without special processing.\nIn `dynamodb-api` , you can omit the special processing by putting `#` at the beginning of the word.\nRefer to the list of reserved words from [here](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/ReservedWords.html).\n\n```ruby\nquery = Dynamodb::Api.query\nquery.from('cars').index('index_maker_id_release_date').\n  where(['maker_id', '=', 1]).\n  filter('#status = :status', ':status': 1)\nitems = query.all.items\n```\n\n| id | maker_id(Partition key) | model | release_date(Sort key) | status |\n|:---|:---|:---|:---|:---|\n|4 |1 |S2000 |0.19980101e8 |1 |\n\nIf you don't add `#` to a reserved word, the following error will occur:\n\n    Aws::DynamoDB::Errors::ValidationException:\n      Invalid FilterExpression: Attribute name is a reserved keyword; reserved keyword: [reserved word]\n\n### Insert\n\n```ruby\nitem = { id: '5', maker_id: 1, maker: 'Honda', model: 'NSX', release_date: 19900914 }\nDynamodb::Api.insert('cars', item)\n```\n\n### Update\n\n```ruby\nkey = { id: '5' }\nvalue = { new_col: 'new' }\nDynamodb::Api.update('cars', key, value)\n```\n\n### Delete\n\n```ruby\nkey = { id: '5' }\nDynamodb::Api.delete('cars', key)\n```\n\n### Remove attributes\n\n```ruby\nkey = { id: '3' }\nattributes = ['status']\nDynamodb::Api.remove_attributes('cars', key, attributes)\n\nquery = Dynamodb::Api.query\nquery.from('cars').index('index_maker_id_release_date').\n  where(['maker_id', '=', 3])\nitems = query.all.items\n```\n\n| id | maker_id(Partition key) | model | release_date(Sort key) |\n|:---|:---|:---|:---|\n|3 |3 |Model S |0.20120601e8 |\n\n### Other API operations\n\n`client` returns the `\u003cAws::DynamoDB::Client\u003e` .\nSo, you can use all [API operations](https://docs.aws.amazon.com/sdkforruby/api/Aws/DynamoDB/Client.html).\n\n```ruby\nclient = Dynamodb::Api::Adapter.client # \u003cAws::DynamoDB::Client\u003e\n\n# e.g.\nclient.create_backup(\n  table_name: 'TableName', # required\n  backup_name: 'BackupName', # required\n)\n```\n\n## Development\n\n- Run `docker-compose up` to run the dynamodb_local.\n- 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.\n- You can also run `docker-compose run ruby bin/console` for an interactive prompt that will allow you to experiment.\n\nTo 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](https://rubygems.org).\n\n## Contributing\n\nBug 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](http://contributor-covenant.org) code of conduct.\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).\n\n## Code of Conduct\n\nEveryone interacting in the Dynamodb::Api project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/dynamodb-api/blob/master/CODE_OF_CONDUCT.md).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwalkersumida%2Fdynamodb-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwalkersumida%2Fdynamodb-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwalkersumida%2Fdynamodb-api/lists"}