rom-dynamodb 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.github/issue_template.md +15 -0
- data/.github/pull_request_template.md +18 -0
- data/.gitignore +10 -0
- data/.rspec +3 -0
- data/.travis.yml +26 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Dockerfile.development +5 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +40 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/docker-compose.yml +20 -0
- data/lib/rom/dynamodb.rb +16 -0
- data/lib/rom/dynamodb/commands.rb +10 -0
- data/lib/rom/dynamodb/commands/create.rb +19 -0
- data/lib/rom/dynamodb/commands/delete.rb +18 -0
- data/lib/rom/dynamodb/commands/update.rb +18 -0
- data/lib/rom/dynamodb/dataset.rb +162 -0
- data/lib/rom/dynamodb/functions.rb +8 -0
- data/lib/rom/dynamodb/gateway.rb +25 -0
- data/lib/rom/dynamodb/relation.rb +36 -0
- data/lib/rom/dynamodb/version.rb +5 -0
- data/rom-dynamodb.gemspec +34 -0
- metadata +223 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a0da22a3017f31bebe16ada8db10a7982e371c3a
|
4
|
+
data.tar.gz: f44db0e880f8f2f202f40635b2100b39c4992525
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 78170caf3e8c7a69dcc71be5c1c4dacfbb3208653ca2bf013b6e7d46dd40273665b8ba09040f12a2d8d21b098e6ba5cc2d38efde6141f5dc6737b04bfdb18d38
|
7
|
+
data.tar.gz: f617f07236589e7fcc6a30e501aa3507b7fced12484b85310f7f8ef56d89b324cbc1eb73fda0e538a21b25ba2eca24ffe3abbc945786345ddd99e3618a9bf584
|
@@ -0,0 +1,15 @@
|
|
1
|
+
### Steps to reproduce
|
2
|
+
|
3
|
+
(Guidelines for creating a bug report are [available
|
4
|
+
here](https://github.com/davidkelley/rom-dynamodb/blob/master/CONTRIBUTING.md))
|
5
|
+
|
6
|
+
### Expected behavior
|
7
|
+
Describe what should happen
|
8
|
+
|
9
|
+
### Actual behavior
|
10
|
+
Describe what happens instead
|
11
|
+
|
12
|
+
### System configuration
|
13
|
+
**Drumbeat version**:
|
14
|
+
|
15
|
+
**Ruby version**:
|
@@ -0,0 +1,18 @@
|
|
1
|
+
### Summary
|
2
|
+
|
3
|
+
Provide a general description of the code changes in your pull
|
4
|
+
request... were there any bugs you had fixed? If so, mention them. If
|
5
|
+
these bugs have open GitHub issues, be sure to tag them here as well,
|
6
|
+
to keep the conversation linked together.
|
7
|
+
|
8
|
+
### Other Information
|
9
|
+
|
10
|
+
If there's anything else that's important and relevant to your pull
|
11
|
+
request, mention that information here. This could include
|
12
|
+
benchmarks, or other information.
|
13
|
+
|
14
|
+
Finally, if your pull request affects documentation or any non-code
|
15
|
+
changes, guidelines for those changes are [available
|
16
|
+
here](https://github.com/davidkelley/rom-dynamodb/blob/master/CONTRIBUTING.md)
|
17
|
+
|
18
|
+
Thanks for contributing to Drumbeat!
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
sudo: false
|
2
|
+
|
3
|
+
language: ruby
|
4
|
+
|
5
|
+
rvm:
|
6
|
+
- 2.0.0
|
7
|
+
|
8
|
+
sudo: required
|
9
|
+
|
10
|
+
before_install:
|
11
|
+
- docker-compose pull
|
12
|
+
- docker-compose build
|
13
|
+
|
14
|
+
script: docker-compose run rom bundle exec rspec
|
15
|
+
|
16
|
+
env:
|
17
|
+
global:
|
18
|
+
# - secure: "YAQCL2ZQNY6vpK0BsYpzorrex/kTCShfXpE7d3j9VTi8qkcbPRXf9Me/grgiogYuq14/cbxEIT9Awh4SKxaJbsVmCDd7FM9dvM2O8mUCuTmno1AxKExpY7TmfW/ARUHwtiOMI1kxgCqScXawPYIsBFHxXhmuF4woPAB7L6n9EzzQUUBwKB/LZIaZV5glT/6QlQH16MAzj5+UgjZm2hgIvBIdaumi1F6A8kHlG/Gr6z5rNTVooMSbN9Xt8RlNhIpR07xSirYMb9Baq7GnWjiXryiUP30F42mOEucNgNBiQdfti9WAw+u6dJNmWv+pB15YicmntYOHCbtq4WyTpkCOmcF6Ry6GZTs+5qvOzvZSCgaNAwGjHJT07X8SabUIS+9IcHqrxmeYsDFyXEF44Oh9KGNHhy66z5vAwl/FcfKL+DkvjY18oZ0FZGGEky4OOb/M/B0IWlx5+ARuo3P1l14It4zmFpGeGUqbTKOCAlQDvMbTxe2wmcieOCz6ZkbhwFcf5GIsA2gXk37p0hGBnQat/dwJwJWvDxMfNLKqk9m9YVp69sSE8elixvc15XLb3jsmom50sRNVYPuPlo556rjByzEPPU+TeXJp5sYdXW4Z5BgcOKx6BX964WI6CR67EqgyCmvsLTQoX7r/JuDL/vtrGG6uxsf96+/y7zLKTexB3A8="
|
19
|
+
|
20
|
+
addons:
|
21
|
+
code_climate:
|
22
|
+
repo_token:
|
23
|
+
secure: "AL3aOEHyWvXkXGne+U3n6ToU0Ubp8yiy3y6gqo/IF2DsN133ynEwcUsif81eIeMTYa+LH4PfDV4iImbwrawhJdyr1ghAqC98k2xfzD5oBSOO8b6gj5k3fRLGRIlGcFwrSSZm9t3F3J3teU3QeaeOW5QhJrtGtlApVvMRzUQPmPbFKjSbzg9oXnl6rWpghUGPjkJZ1zJARZqYx6yJ5JYoRFX7xPcwmwvMa3tCnLh3wfpVCexsa33gssFCGUuh/qU2aLO9f/EyLV95nkxNoXdNoMAajuddDAUK2GQSBLuGijyydUl+x9ZLEsfMJbW3xFqeYVQzMiRXMku0kp7NuzSF9TfPP4TSv5EIJAuVujB3u7sc+jRGEy+m+WawUunu8BmX1l9vjBMcMUonqcsToTBHf9u1nLBdJMhwk0WQkvcJ31g4lrc5y4wut/mRdylBTrplAJAwcHfXnM7ADWL4DN3Yx+Vo+lPgkCrtnsMST2PUcyW2v+hln/BR9qB9PGPC121o7D+BNNuT4oLrw7tebnl3CWI9cpb2jaZl1cVrINhOnApukO1oqxOE2xGVCkNIZ4RIDLlj1WVbbLBN/C/dREjf6n/jNT5LylWEULHofYpit2+1o8KSHjT7aCMLwWlyIuAyYz45WSPviy4oyrjeLUGUo3u15EjJeGcKhXtrtreVdvk="
|
24
|
+
|
25
|
+
services:
|
26
|
+
- docker
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at david.james.kelley@gmail.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 David Kelley
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
# ROM DynamoDB Adapter
|
2
|
+
|
3
|
+
[![Code Climate](https://codeclimate.com/github/davidkelley/rom-dynamodb/badges/gpa.svg)](https://codeclimate.com/github/davidkelley/rom-dynamodb) [![Test Coverage](https://codeclimate.com/github/davidkelley/rom-dynamodb/badges/coverage.svg)](https://codeclimate.com/github/davidkelley/rom-dynamodb/coverage) [![Dependency Status](https://gemnasium.com/badges/github.com/davidkelley/rom-dynamodb.svg)](https://gemnasium.com/github.com/davidkelley/rom-dynamodb)
|
4
|
+
[![Build Status](https://travis-ci.org/davidkelley/rom-dynamodb.svg?branch=master)](https://travis-ci.org/davidkelley/rom-dynamodb) [![Inline docs](http://inch-ci.org/github/davidkelley/rom-dynamodb.svg?branch=master)](http://inch-ci.org/github/davidkelley/rom-dynamodb)
|
5
|
+
|
6
|
+
---
|
7
|
+
|
8
|
+
TODO: Delete this and the text above, and describe your gem
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
Add this line to your application's Gemfile:
|
13
|
+
|
14
|
+
```ruby
|
15
|
+
gem 'rom-dynamodb'
|
16
|
+
```
|
17
|
+
|
18
|
+
And then execute:
|
19
|
+
|
20
|
+
$ bundle
|
21
|
+
|
22
|
+
Or install it yourself as:
|
23
|
+
|
24
|
+
$ gem install rom-dynamodb
|
25
|
+
|
26
|
+
## Usage
|
27
|
+
|
28
|
+
TODO
|
29
|
+
|
30
|
+
## Development
|
31
|
+
|
32
|
+
TODO
|
33
|
+
|
34
|
+
## Contributing
|
35
|
+
|
36
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/davidkelley/rom-dynamo. 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.
|
37
|
+
|
38
|
+
## License
|
39
|
+
|
40
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "rom/dynamodb"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/docker-compose.yml
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
version: '2'
|
2
|
+
|
3
|
+
services:
|
4
|
+
dynamo:
|
5
|
+
image: deangiberson/aws-dynamodb-local
|
6
|
+
expose:
|
7
|
+
- "8000"
|
8
|
+
ports:
|
9
|
+
- "8000:8000"
|
10
|
+
rom:
|
11
|
+
build:
|
12
|
+
context: .
|
13
|
+
dockerfile: Dockerfile.development
|
14
|
+
command: rspec
|
15
|
+
environment:
|
16
|
+
DYNAMO_ENDPOINT: 'http://dynamo:8000'
|
17
|
+
volumes:
|
18
|
+
- .:/app
|
19
|
+
links:
|
20
|
+
- dynamo
|
data/lib/rom/dynamodb.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'rom'
|
2
|
+
require 'aws-sdk-core'
|
3
|
+
require 'deep_merge'
|
4
|
+
|
5
|
+
require 'rom/dynamodb/functions'
|
6
|
+
require 'rom/dynamodb/dataset'
|
7
|
+
require 'rom/dynamodb/gateway'
|
8
|
+
require 'rom/dynamodb/commands'
|
9
|
+
require 'rom/dynamodb/relation'
|
10
|
+
|
11
|
+
module ROM
|
12
|
+
module DynamoDB
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
ROM.register_adapter(:dynamodb, ROM::DynamoDB)
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module ROM
|
2
|
+
module DynamoDB
|
3
|
+
module Commands
|
4
|
+
class Create < ROM::Commands::Create
|
5
|
+
adapter :dynamodb
|
6
|
+
|
7
|
+
def execute(tuples)
|
8
|
+
tuples = tuples.is_a?(Array) ? tuples : [tuples]
|
9
|
+
tuples.collect(&method(:with_tuple))
|
10
|
+
end
|
11
|
+
|
12
|
+
def with_tuple(tuple)
|
13
|
+
data = tuple.is_a?(Hash) ? tuple : tuple.to_h
|
14
|
+
source.create(data)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module ROM
|
2
|
+
module DynamoDB
|
3
|
+
module Commands
|
4
|
+
class Delete < ROM::Commands::Delete
|
5
|
+
adapter :dynamodb
|
6
|
+
|
7
|
+
def execute
|
8
|
+
relation.to_a.collect(&method(:with_tuple))
|
9
|
+
end
|
10
|
+
|
11
|
+
def with_tuple(tuple)
|
12
|
+
data = tuple.is_a?(Hash) ? tuple : tuple.to_h
|
13
|
+
source.delete(input[data])
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module ROM
|
2
|
+
module DynamoDB
|
3
|
+
module Commands
|
4
|
+
class Update < ROM::Commands::Update
|
5
|
+
adapter :dynamodb
|
6
|
+
|
7
|
+
def execute(attributes)
|
8
|
+
relation.to_a.collect { |tuple| with_tuple(tuple, attributes) }
|
9
|
+
end
|
10
|
+
|
11
|
+
def with_tuple(tuple, attributes)
|
12
|
+
data = tuple.is_a?(Hash) ? tuple : tuple.to_h
|
13
|
+
relation.update(input[data], attributes.to_h)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,162 @@
|
|
1
|
+
module ROM
|
2
|
+
module DynamoDB
|
3
|
+
class Dataset
|
4
|
+
attr_reader :name, :operation, :config
|
5
|
+
|
6
|
+
attr_accessor :queries
|
7
|
+
|
8
|
+
def initialize(name:, operation: :query, config: {}, queries: [])
|
9
|
+
@name = name
|
10
|
+
@operation = operation
|
11
|
+
@config = config
|
12
|
+
@queries = queries
|
13
|
+
end
|
14
|
+
|
15
|
+
def index(name)
|
16
|
+
restrict(index_name: name)
|
17
|
+
end
|
18
|
+
|
19
|
+
def ascending
|
20
|
+
restrict(scan_index_forward: true)
|
21
|
+
end
|
22
|
+
|
23
|
+
def descending
|
24
|
+
restrict(scan_index_forward: false)
|
25
|
+
end
|
26
|
+
|
27
|
+
def limit(num = nil)
|
28
|
+
append { { limit: num } unless num.nil? }
|
29
|
+
end
|
30
|
+
|
31
|
+
def offset(key)
|
32
|
+
append { { exclusive_start_key: key } unless key.nil? }
|
33
|
+
end
|
34
|
+
|
35
|
+
def select(keys)
|
36
|
+
restrict(select: "SPECIFIC_ATTRIBUTES", attributes_to_get: keys.collect(&:to_s))
|
37
|
+
end
|
38
|
+
|
39
|
+
def equal(key, val, predicate = :eq)
|
40
|
+
restrict_by(key, predicate, [val])
|
41
|
+
end
|
42
|
+
|
43
|
+
def between(key, after, before, predicate = :between)
|
44
|
+
restrict_by(key, predicate, [after, before])
|
45
|
+
end
|
46
|
+
|
47
|
+
def after(key, after, predicate = :ge)
|
48
|
+
restrict_by(key, predicate, [after])
|
49
|
+
end
|
50
|
+
|
51
|
+
def before(key, before, predicate = :le)
|
52
|
+
restrict_by(key, predicate, [before])
|
53
|
+
end
|
54
|
+
|
55
|
+
def batch_get(query = nil)
|
56
|
+
append(:batch_get) { query }
|
57
|
+
end
|
58
|
+
|
59
|
+
def restrict(query = nil)
|
60
|
+
append(:query) { query }
|
61
|
+
end
|
62
|
+
|
63
|
+
def retrieve(query = nil)
|
64
|
+
append(:get_item) { query }
|
65
|
+
end
|
66
|
+
|
67
|
+
def scan(query = nil)
|
68
|
+
append(:scan) { query }
|
69
|
+
end
|
70
|
+
|
71
|
+
def build(parts = queries)
|
72
|
+
parts.inject(:deep_merge).merge(table_name: name)
|
73
|
+
end
|
74
|
+
|
75
|
+
def update(key, hash, action = 'PUT')
|
76
|
+
data = hash.delete_if { |k, _| key.keys.include?(k) }
|
77
|
+
update = to_update_structure(data)
|
78
|
+
payload = build([update, { key: key }])
|
79
|
+
connection.update_item(payload).data
|
80
|
+
end
|
81
|
+
|
82
|
+
def create(hash)
|
83
|
+
payload = build([{ item: hash }])
|
84
|
+
connection.put_item(payload).attributes
|
85
|
+
end
|
86
|
+
|
87
|
+
def delete(hash)
|
88
|
+
payload = build([{ key: hash }])
|
89
|
+
connection.delete_item(payload).data
|
90
|
+
end
|
91
|
+
|
92
|
+
def information
|
93
|
+
payload = build([{}])
|
94
|
+
connection.describe_table(payload).table
|
95
|
+
end
|
96
|
+
|
97
|
+
def each(&block)
|
98
|
+
each_item(build, &block)
|
99
|
+
end
|
100
|
+
|
101
|
+
def connection
|
102
|
+
@connection ||= Aws::DynamoDB::Client.new(config)
|
103
|
+
end
|
104
|
+
|
105
|
+
def execute(query)
|
106
|
+
@response ||= case operation
|
107
|
+
when :batch_get
|
108
|
+
connection.send(operation, { request_items: { name => query } })
|
109
|
+
else
|
110
|
+
connection.send(operation, query).data
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
private
|
115
|
+
|
116
|
+
def restrict_by(key, verb, list)
|
117
|
+
restrict(key_conditions: {
|
118
|
+
key => {
|
119
|
+
comparison_operator: verb.to_s.upcase,
|
120
|
+
attribute_value_list: list
|
121
|
+
}
|
122
|
+
})
|
123
|
+
end
|
124
|
+
|
125
|
+
def each_item(body, &block)
|
126
|
+
case operation
|
127
|
+
when :get_item
|
128
|
+
block.call execute(body).item
|
129
|
+
when :batch_get
|
130
|
+
execute(body).responses[name.to_s].each(&block)
|
131
|
+
else
|
132
|
+
execute(body).items.each(&block)
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
def append(operation = :query, &block)
|
137
|
+
result = block.call
|
138
|
+
if result
|
139
|
+
args = { name: name, config: config, operation: operation }
|
140
|
+
self.class.new(args.merge(queries: queries + [result].flatten))
|
141
|
+
else
|
142
|
+
self
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
def to_update_structure(hash)
|
147
|
+
values = {}
|
148
|
+
maps = {}
|
149
|
+
expr = 'SET ' + hash.map do |key, val|
|
150
|
+
values[":#{key}"] = val
|
151
|
+
maps["##{key}"] = key
|
152
|
+
"##{key}=:#{key}"
|
153
|
+
end.join(', ')
|
154
|
+
{
|
155
|
+
expression_attribute_values: values,
|
156
|
+
expression_attribute_names: maps,
|
157
|
+
update_expression: expr
|
158
|
+
}
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|
162
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module ROM
|
2
|
+
module DynamoDB
|
3
|
+
class Gateway < ROM::Gateway
|
4
|
+
attr_reader :datasets, :config
|
5
|
+
|
6
|
+
def initialize(config = {})
|
7
|
+
@config = config
|
8
|
+
@datasets ||= {}
|
9
|
+
end
|
10
|
+
|
11
|
+
def dataset(name)
|
12
|
+
datasets[name] ||= Dataset.new(name: name, config: config)
|
13
|
+
end
|
14
|
+
|
15
|
+
def dataset?(name)
|
16
|
+
list = connection.list_tables
|
17
|
+
list.table_names.include?(name)
|
18
|
+
end
|
19
|
+
|
20
|
+
def connection
|
21
|
+
@connection ||= Aws::DynamoDB::Client.new(@config)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module ROM
|
2
|
+
module DynamoDB
|
3
|
+
class Relation < ROM::Relation
|
4
|
+
adapter :dynamodb
|
5
|
+
|
6
|
+
# retrieval
|
7
|
+
forward :restrict, :scan, :retrieve, :batch_get, :equal, :index,
|
8
|
+
:before, :after, :between, :select, :offset, :limit
|
9
|
+
|
10
|
+
# operations
|
11
|
+
forward :create, :delete, :update
|
12
|
+
|
13
|
+
# storing
|
14
|
+
forward :ascending, :descending
|
15
|
+
|
16
|
+
# def initialize(*r)
|
17
|
+
# super *r
|
18
|
+
# puts schema.inspect
|
19
|
+
# end
|
20
|
+
|
21
|
+
def info
|
22
|
+
dataset.information
|
23
|
+
end
|
24
|
+
|
25
|
+
def count
|
26
|
+
dataset.information.item_count
|
27
|
+
end
|
28
|
+
|
29
|
+
def status
|
30
|
+
dataset.information.table_status.downcase.to_sym
|
31
|
+
rescue
|
32
|
+
:unknown
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'rom/dynamodb/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "rom-dynamodb"
|
8
|
+
spec.version = ROM::DynamoDB::VERSION
|
9
|
+
spec.authors = ["davidkelley"]
|
10
|
+
spec.email = ["david.james.kelley@gmail.com"]
|
11
|
+
spec.summary = 'DynamoDB adapter for Ruby Object Mapper'
|
12
|
+
spec.homepage = "https://github.com/davidkelley/rom-dynamo"
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
16
|
+
f.match(%r{^(test|spec|features)/})
|
17
|
+
end
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_runtime_dependency "rom", "~> 3.0.0.beta1"
|
23
|
+
spec.add_runtime_dependency "aws-sdk-core", ">= 2.1"
|
24
|
+
spec.add_runtime_dependency "deep_merge", ">= 1.1.1"
|
25
|
+
|
26
|
+
spec.add_development_dependency "json", "~> 2.0"
|
27
|
+
spec.add_development_dependency "faker", "~> 1.7"
|
28
|
+
spec.add_development_dependency "coveralls-ruby", "~> 0.8"
|
29
|
+
spec.add_development_dependency "bigdecimal", "~> 1.3"
|
30
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
31
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
32
|
+
spec.add_development_dependency "coveralls", "~> 0.8"
|
33
|
+
spec.add_development_dependency "factory_girl", "~> 4.5"
|
34
|
+
end
|
metadata
ADDED
@@ -0,0 +1,223 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rom-dynamodb
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 2.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- davidkelley
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-01-18 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rom
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 3.0.0.beta1
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 3.0.0.beta1
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: aws-sdk-core
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2.1'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '2.1'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: deep_merge
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 1.1.1
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 1.1.1
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: json
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '2.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '2.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: faker
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ~>
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.7'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ~>
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.7'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: coveralls-ruby
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ~>
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0.8'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ~>
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0.8'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: bigdecimal
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ~>
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '1.3'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ~>
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '1.3'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rake
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ~>
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '10.0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ~>
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '10.0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: rspec
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ~>
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '3.0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ~>
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '3.0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: coveralls
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ~>
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0.8'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ~>
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0.8'
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: factory_girl
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - ~>
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '4.5'
|
160
|
+
type: :development
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - ~>
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '4.5'
|
167
|
+
description:
|
168
|
+
email:
|
169
|
+
- david.james.kelley@gmail.com
|
170
|
+
executables: []
|
171
|
+
extensions: []
|
172
|
+
extra_rdoc_files: []
|
173
|
+
files:
|
174
|
+
- .github/issue_template.md
|
175
|
+
- .github/pull_request_template.md
|
176
|
+
- .gitignore
|
177
|
+
- .rspec
|
178
|
+
- .travis.yml
|
179
|
+
- CODE_OF_CONDUCT.md
|
180
|
+
- Dockerfile.development
|
181
|
+
- Gemfile
|
182
|
+
- LICENSE.txt
|
183
|
+
- README.md
|
184
|
+
- Rakefile
|
185
|
+
- bin/console
|
186
|
+
- bin/setup
|
187
|
+
- docker-compose.yml
|
188
|
+
- lib/rom/dynamodb.rb
|
189
|
+
- lib/rom/dynamodb/commands.rb
|
190
|
+
- lib/rom/dynamodb/commands/create.rb
|
191
|
+
- lib/rom/dynamodb/commands/delete.rb
|
192
|
+
- lib/rom/dynamodb/commands/update.rb
|
193
|
+
- lib/rom/dynamodb/dataset.rb
|
194
|
+
- lib/rom/dynamodb/functions.rb
|
195
|
+
- lib/rom/dynamodb/gateway.rb
|
196
|
+
- lib/rom/dynamodb/relation.rb
|
197
|
+
- lib/rom/dynamodb/version.rb
|
198
|
+
- rom-dynamodb.gemspec
|
199
|
+
homepage: https://github.com/davidkelley/rom-dynamo
|
200
|
+
licenses:
|
201
|
+
- MIT
|
202
|
+
metadata: {}
|
203
|
+
post_install_message:
|
204
|
+
rdoc_options: []
|
205
|
+
require_paths:
|
206
|
+
- lib
|
207
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
208
|
+
requirements:
|
209
|
+
- - '>='
|
210
|
+
- !ruby/object:Gem::Version
|
211
|
+
version: '0'
|
212
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
213
|
+
requirements:
|
214
|
+
- - '>='
|
215
|
+
- !ruby/object:Gem::Version
|
216
|
+
version: '0'
|
217
|
+
requirements: []
|
218
|
+
rubyforge_project:
|
219
|
+
rubygems_version: 2.0.14.1
|
220
|
+
signing_key:
|
221
|
+
specification_version: 4
|
222
|
+
summary: DynamoDB adapter for Ruby Object Mapper
|
223
|
+
test_files: []
|