dynamodb-api 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cd5e78de7acd36a9196ea3945ce66a12e7b98c66485847b3f5727d04a044f783
4
- data.tar.gz: 05450b5257f17ef9e3dd6d4e9ec523652dd8747c11df1859b5c3c93fd29fbf19
3
+ metadata.gz: 4061c168a73225d611dccc1a6e22aefcc7db228c0ea943f9a043f1a55113dad0
4
+ data.tar.gz: c01601e30d038fdd7454ba554c517470cb229fab94576de46986e0fe5ff92dba
5
5
  SHA512:
6
- metadata.gz: 14d765ffb21e1140e51f6e27046a0da0da877969c0bdd9d6668eb568bfc114f918159ecbf88ad51532d02bded873019fd018f4a1cdee081d9f7ece3ffe9e8e5e
7
- data.tar.gz: cc76aa8ffe6e9422b9c53832bf723536abcb28aa07ed018f98a23f73a10cd7780950527986fa9d81070a8b89746df4357dbf5c53704beed46d0bf0f368ad4c3b
6
+ metadata.gz: b393488340105ee19749dc58c6f15c6e90fbb83c42b16f7f115be3ef6dd8422f2b688b852d76ae933e05c64762f0ad595b9b1b39b77e80c67529659ef40f0b55
7
+ data.tar.gz: 18f26f3209871a606ec1193c85d8f8a8b30b3875858b7090fbb5488aa6f15dae96ceead389bd52807dccb768895e8f4965a3debad010150c8297319417952713
@@ -3,3 +3,9 @@ language: ruby
3
3
  rvm:
4
4
  - 2.5.1
5
5
  before_install: gem install bundler -v 1.16.2
6
+
7
+ before_script:
8
+ - docker-compose up -d
9
+
10
+ after_script:
11
+ - docker-compose down
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- dynamodb-api (0.4.0)
4
+ dynamodb-api (0.4.1)
5
5
  activesupport (>= 4)
6
6
  aws-sdk (~> 2)
7
7
 
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # Dynamodb::Api
2
2
 
3
+ [![Build Status](https://travis-ci.org/walkersumida/dynamodb-api.svg?branch=master)](https://travis-ci.org/walkersumida/dynamodb-api)
4
+
3
5
  Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/dynamodb/api`. To experiment with that code, run `bin/console` for an interactive prompt.
4
6
 
5
7
  TODO: Delete this and the text above, and describe your gem
@@ -26,8 +28,8 @@ Or install it yourself as:
26
28
 
27
29
  ```
28
30
  Dynamodb::Api.config do |config|
29
- config.access_key = ''
30
- config.secret_key = ''
31
+ config.access_key_id = ''
32
+ config.secret_access_key = ''
31
33
  config.region = ''
32
34
  config.table_name_prefix = ''
33
35
  config.index_name_prefix = ''
@@ -36,7 +38,10 @@ end
36
38
 
37
39
  ## Development
38
40
 
39
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
41
+ - Run `docker-compose up` to run the dynamodb_local.
42
+ - After checking out the repo, run `bin/setup` to install dependencies.
43
+ - Run `rake spec` to run the tests.
44
+ - You can also run `bin/console` for an interactive prompt that will allow you to experiment.
40
45
 
41
46
  To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `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).
42
47
 
@@ -0,0 +1,6 @@
1
+ version: '3'
2
+ services:
3
+ dynamodb:
4
+ image: cnadiminti/dynamodb-local:2018-04-11
5
+ ports:
6
+ - 8000:8000
@@ -14,6 +14,8 @@ require 'dynamodb/api/relation/where_clause'
14
14
  require 'dynamodb/api/relation/filter_clause'
15
15
  require 'dynamodb/api/relation/global_secondary_index'
16
16
  require 'dynamodb/api/relation/expression_attribute_names'
17
+ require 'dynamodb/api/put/item'
18
+ require 'dynamodb/api/delete/tables'
17
19
 
18
20
  module Dynamodb
19
21
  module Api # :nodoc:
@@ -26,5 +28,14 @@ module Dynamodb
26
28
  def adapter
27
29
  @adapter ||= Dynamodb::Api::Adapter.new
28
30
  end
31
+
32
+ def drop_tables
33
+ Delete::Tables.delete_tables
34
+ end
35
+
36
+ def insert(table_name, value)
37
+ # TODO: BatchWriteItem
38
+ Put::Item.put_item(value, table_name)
39
+ end
29
40
  end
30
41
  end
@@ -1,26 +1,21 @@
1
1
  module Dynamodb
2
2
  module Api
3
3
  class Adapter # :nodoc:
4
- attr_reader :client
4
+ attr_reader :_client
5
5
 
6
- def initialize
7
- @client = Aws::DynamoDB::Client.new(connect_config)
6
+ def self.client
7
+ @_client ||= Aws::DynamoDB::Client.new(connect_config)
8
8
  end
9
9
 
10
- def connect_config
10
+ def self.connect_config
11
+ config_keys = %w[endpoint access_key_id secret_access_key region]
11
12
  @connect_hash = {}
12
13
 
13
- if Dynamodb::Api::Config.endpoint?
14
- @connect_hash[:endpoint] = Dynamodb::Api::Config.endpoint
15
- end
16
- if Dynamodb::Api::Config.access_key?
17
- @connect_hash[:access_key_id] = Dynamodb::Api::Config.access_key
18
- end
19
- if Dynamodb::Api::Config.secret_key?
20
- @connect_hash[:secret_access_key] = Dynamodb::Api::Config.secret_key
21
- end
22
- if Dynamodb::Api::Config.region?
23
- @connect_hash[:region] = Dynamodb::Api::Config.region
14
+ config_keys.each do |config_key|
15
+ if Dynamodb::Api::Config.send("#{config_key}?")
16
+ @connect_hash[config_key.to_sym] =
17
+ Dynamodb::Api::Config.send(config_key)
18
+ end
24
19
  end
25
20
 
26
21
  @connect_hash
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'dynamodb/api/config/options'
2
4
 
3
5
  module Dynamodb
@@ -6,8 +8,8 @@ module Dynamodb
6
8
  extend self
7
9
  extend Options
8
10
 
9
- option :access_key, default: nil
10
- option :secret_key, default: nil
11
+ option :access_key_id, default: nil
12
+ option :secret_access_key, default: nil
11
13
  option :region, default: nil
12
14
  option :endpoint, default: nil
13
15
  option :table_name_prefix, default: ''
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Dynamodb
4
+ module Api
5
+ module Delete
6
+ class Tables # :nodoc:
7
+ def self.delete_tables
8
+ client = Adapter.client
9
+ table_names = client.list_tables[:table_names]
10
+ table_names.each do |table_name|
11
+ client.delete_table(table_name: table_name)
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Dynamodb
4
+ module Api
5
+ module Put
6
+ class Item # :nodoc:
7
+ def self.put_item(item, table_name)
8
+ client = Adapter.client
9
+ client.put_item(item: item, table_name: table_name)
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -6,14 +6,9 @@ module Dynamodb
6
6
  module Api
7
7
  class Query # :nodoc:
8
8
  include Relation
9
- attr_reader :client
10
-
11
- def initialize
12
- @client = Adapter.new.client
13
- end
14
9
 
15
10
  def all
16
- @client.query(build_query)
11
+ Adapter.client.query(build_query)
17
12
  end
18
13
 
19
14
  private
@@ -22,17 +17,26 @@ module Dynamodb
22
17
  build_params = {
23
18
  table_name: from_clause.name,
24
19
  index_name: index_clause.name,
25
- select: select_clause.name,
26
- scan_index_forward: order_clause.direct,
27
20
  key_conditions: where_clause.key_conditions
28
21
  }.merge(build_filter_clause)
22
+ build_params[:scan_index_forward] = order_direct(order_clause)
23
+ build_params[:select] = select_name(select_clause)
29
24
  if expression_attribute&.names
30
25
  build_params[:expression_attribute_names] = expression_attribute.names
31
26
  end
32
27
  build_params
33
28
  end
34
29
 
30
+ def order_direct(clause)
31
+ clause&.direct ? clause.direct : OrderClause.new.direct
32
+ end
33
+
34
+ def select_name(clause)
35
+ clause&.name ? clause.name : SelectClause.new.name
36
+ end
37
+
35
38
  def build_filter_clause
39
+ return {} unless filter_clause&.expression
36
40
  {
37
41
  filter_expression: filter_clause.expression,
38
42
  expression_attribute_values: filter_clause.values
@@ -17,13 +17,24 @@ module Dynamodb
17
17
  private
18
18
 
19
19
  def build(key_conditions)
20
- key_conditions.each_with_object({}) do |c, h|
20
+ conditions = format_conditions(key_conditions)
21
+ conditions.each_with_object({}) do |c, h|
21
22
  h[c[KEY]] = {
22
- attribute_value_list: c[VALUE],
23
+ attribute_value_list: format_value(c[VALUE]),
23
24
  comparison_operator: c[OPERATOR]
24
25
  }
25
26
  end
26
27
  end
28
+
29
+ def format_conditions(conditions)
30
+ return [conditions] unless conditions[0].is_a?(Array)
31
+ conditions
32
+ end
33
+
34
+ def format_value(value)
35
+ return [value] unless value.is_a?(Array)
36
+ value
37
+ end
27
38
  end
28
39
  end
29
40
  end
@@ -1,5 +1,5 @@
1
1
  module Dynamodb
2
2
  module Api
3
- VERSION = '0.4.0'.freeze
3
+ VERSION = '0.4.1'.freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dynamodb-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - WalkerSumida
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-08-06 00:00:00.000000000 Z
11
+ date: 2018-08-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk
@@ -113,11 +113,14 @@ files:
113
113
  - Rakefile
114
114
  - bin/console
115
115
  - bin/setup
116
+ - docker-compose.yml
116
117
  - dynamodb-api.gemspec
117
118
  - lib/dynamodb/api.rb
118
119
  - lib/dynamodb/api/adapter.rb
119
120
  - lib/dynamodb/api/config.rb
120
121
  - lib/dynamodb/api/config/options.rb
122
+ - lib/dynamodb/api/delete/tables.rb
123
+ - lib/dynamodb/api/put/item.rb
121
124
  - lib/dynamodb/api/query.rb
122
125
  - lib/dynamodb/api/relation.rb
123
126
  - lib/dynamodb/api/relation/expression_attribute_names.rb