dynomite 1.2.6 → 1.2.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6f80bf11d2121217d52d8ceac89defcd4e738b3ff220847f7421b1337fbc104f
4
- data.tar.gz: cd1a4fb8c66678458c8e08b3222064ea3153129f31d1a81ff7ee6d25f1ac3928
3
+ metadata.gz: 8a0639976cc739134d6670945d099f3584b39f88f058e056678591a42c09be84
4
+ data.tar.gz: 6ad8c28d9147a175cf940ec756d808b66a948c27be74239ab95dc3b589dd9d74
5
5
  SHA512:
6
- metadata.gz: 890d2960cd53cec65a93b81b31fb61da535f123f4718d5e870eb2983813811352e2bbf93043007389ee85224590e2484ec0f2b0c5f377b384c5cf886923a87fd
7
- data.tar.gz: 1e2ab49bfc684afe96927971d2a57544b9d4898bb1271b920b88969e267b79f5271c4bf71ed07f45b4b160c5f27ef7ff943250c62e42eb1ce1c1c81d720e78ab
6
+ metadata.gz: 3f7f4e2dcb3163c4cc60065c3d0f74b835bd4763f6295ae00d8f92576f2c57afcc969a5b4bf0c727d9b8a45ab17e52ae573319a819cf3f7c0974cf29a91b19ac
7
+ data.tar.gz: c37b011a90f943e6e04fbdfa248dee7b8bcf1dae762ae5175c976e02325e462118715d8340f5d42022e62a40ab1b77aa80af532544e255eed2c2fec89ecd6aa8
data/CHANGELOG.md CHANGED
@@ -3,6 +3,12 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  This project *tries* to adhere to [Semantic Versioning](http://semver.org/), even before v1.0.
5
5
 
6
+ ## [1.2.7] - 2022-06-12
7
+ - [#23](https://github.com/tongueroo/dynomite/pull/23) #where method refactor to allow Model.index_name('index').where(...)
8
+ - [#24](https://github.com/tongueroo/dynomite/pull/24) Add get_endpoint_ip to db_config.rb
9
+ - [#26](https://github.com/tongueroo/dynomite/pull/26) change pay_per_use to pay_per_request
10
+ - [#27](https://github.com/tongueroo/dynomite/pull/27) Fixed message that tells how to install dynamodb-local
11
+
6
12
  ## [1.2.6]
7
13
  - Implement the `PAY_PER_USE` billing mode for table creations and updates. See [DynamoDB On Demand](https://aws.amazon.com/blogs/aws/amazon-dynamodb-on-demand-no-capacity-planning-and-pay-per-request-pricing/).
8
14
 
data/README.md CHANGED
@@ -2,7 +2,9 @@
2
2
 
3
3
  [![BoltOps Badge](https://img.boltops.com/boltops/badges/boltops-badge.png)](https://www.boltops.com)
4
4
 
5
- NOTE: Am looking for maintainers to help with this gem. Send me an email! Also [dynamoid](https://github.com/Dynamoid/dynamoid) seems like a good option that should be considered delegating to or straight using. Learning on delegation so we can have better default behavior for a DynamoDB model layer for Jets.
5
+ NOTE: Am looking for maintainers to help with this gem. Send me an email!
6
+
7
+ IMPORTANT: The next major version of Dynomite will be ActiveModel compatible. A POC is in the [edge](https://github.com/tongueroo/dynomite/tree/edge) branch. It's still very rough and experimental. Would not recommend using it yet, but wanted to note it.
6
8
 
7
9
  A simple wrapper library to make DynamoDB usage a little more friendly. The modeling is ActiveRecord-ish but not exactly because DynamoDB is a different type of database. Examples below explain it best:
8
10
 
@@ -57,7 +57,7 @@ class CreateCommentsMigration < Dynomite::Migration
57
57
  # )
58
58
 
59
59
  # set the billing mode to on-demand (NOTE: this overrides provisioned_throughput)
60
- # t.billing_mode(:pay_per_use)
60
+ # t.billing_mode(:pay_per_request)
61
61
  end
62
62
  end
63
63
  end
@@ -66,7 +66,7 @@ class UpdateCommentsMigration < Dynomite::Migration
66
66
  def up
67
67
  update_table :comments do |t|
68
68
  # You can update from provisioned_throughput to on-demand pricing
69
- # t.billing_mode(:pay_per_use)
69
+ # t.billing_mode(:pay_per_request)
70
70
 
71
71
  # t.global_secondary_index do
72
72
  # t.gsi(METHOD, INDEX_NAME) do
@@ -42,10 +42,24 @@ module Dynomite::DbConfig
42
42
  # This wastes less of the users time.
43
43
  def check_dynamodb_local!(endpoint)
44
44
  return unless endpoint && endpoint.include?("8000")
45
-
46
- open = port_open?("127.0.0.1", 8000, 0.2)
45
+
46
+ host, port = endpoint.gsub("http://", "").split(":")
47
+ ip = get_endpoint_ip(host)
48
+ unless ip
49
+ raise "You have configured your app to use DynamoDB local, but it is not running on the host: #{host}."
50
+ end
51
+
52
+ open = port_open?(ip, 8000, 0.2)
47
53
  unless open
48
- raise "You have configured your app to use DynamoDB local, but it is not running. Please start DynamoDB local. Example: brew cask install dynamodb-local && dynamodb-local"
54
+ raise "You have configured your app to use DynamoDB local, but it is not running. Please start DynamoDB local. Example: brew install --cask dynamodb-local && dynamodb-local"
55
+ end
56
+ end
57
+
58
+ def get_endpoint_ip(host)
59
+ begin
60
+ IPSocket.getaddress(host)
61
+ rescue SocketError
62
+ false # Can return anything you want here
49
63
  end
50
64
  end
51
65
 
data/lib/dynomite/item.rb CHANGED
@@ -4,6 +4,7 @@ require "digest"
4
4
  require "yaml"
5
5
 
6
6
  require "dynomite/reserved_words"
7
+ require "dynomite/query"
7
8
 
8
9
  # The modeling is ActiveRecord-ish but not exactly because DynamoDB is a
9
10
  # different type of database.
@@ -170,9 +171,17 @@ module Dynomite
170
171
  resp.items.map {|i| self.new(i) }
171
172
  end
172
173
 
174
+ # Creates a new chainable ActiveRecord Query-style instance with a certain index_name.
175
+ #
176
+ # Post.index_name("category-index").where(category: "Drama")
177
+ #
178
+ def self.index_name(name)
179
+ _new_query.index_name(name)
180
+ end
181
+
173
182
  # Translates simple query searches:
174
183
  #
175
- # Post.where({category: "Drama"}, index_name: "category-index")
184
+ # Post.index_name("category-index").where(category: "Drama")
176
185
  #
177
186
  # translates to
178
187
  #
@@ -183,34 +192,8 @@ module Dynomite
183
192
  # expression_attribute_values: { ":category_value" => category },
184
193
  # key_condition_expression: "#category_name = :category_value",
185
194
  # )
186
- #
187
- # TODO: Implement nicer where syntax with index_name as a chained method.
188
- #
189
- # Post.where({category: "Drama"}, {index_name: "category-index"})
190
- # VS
191
- # Post.where(category: "Drama").index_name("category-index")
192
- def self.where(attributes, options={})
193
- raise "attributes.size == 1 only supported for now" if attributes.size != 1
194
-
195
- attr_name = attributes.keys.first
196
- attr_value = attributes[attr_name]
197
-
198
- # params = {
199
- # expression_attribute_names: { "#category_name" => "category" },
200
- # expression_attribute_values: { ":category_value" => "Entertainment" },
201
- # key_condition_expression: "#category_name = :category_value",
202
- # }
203
- name_key, value_key = "##{attr_name}_name", ":#{attr_name}_value"
204
- params = {
205
- expression_attribute_names: { name_key => attr_name },
206
- expression_attribute_values: { value_key => attr_value },
207
- key_condition_expression: "#{name_key} = #{value_key}",
208
- }
209
- # Allow direct access to override params passed to dynamodb query options.
210
- # This is is how index_name is passed:
211
- params = params.merge(options)
212
-
213
- query(params)
195
+ def self.where(attributes)
196
+ _new_query.where(attributes)
214
197
  end
215
198
 
216
199
  def self.replace(attrs)
@@ -343,5 +326,9 @@ module Dynomite
343
326
  @attrs[name.to_s] = value
344
327
  end
345
328
  end
329
+
330
+ def self._new_query
331
+ Dynomite::Query.new(self, {})
332
+ end
346
333
  end
347
334
  end
@@ -0,0 +1,48 @@
1
+ module Dynomite
2
+ class Query
3
+ include Enumerable
4
+
5
+ def initialize(item, params)
6
+ @item = item
7
+ @params = params
8
+ end
9
+
10
+ def <<(item)
11
+ raise NotImplementedError
12
+ end
13
+
14
+ def inspect
15
+ "#<Dynomite::Query [#{first(2).map(&:inspect).join(', ')}, ...]>"
16
+ end
17
+
18
+ def each(&block)
19
+ run_query.each(&block)
20
+ end
21
+
22
+ def index_name(name)
23
+ self.class.new(@item, @params.merge(index_name: name))
24
+ end
25
+
26
+ def where(attributes)
27
+ raise "attributes.size == 1 only supported for now" if attributes.size != 1
28
+
29
+ attr_name = attributes.keys.first
30
+ attr_value = attributes[attr_name]
31
+
32
+ name_key, value_key = "##{attr_name}_name", ":#{attr_name}_value"
33
+ params = {
34
+ expression_attribute_names: { name_key => attr_name },
35
+ expression_attribute_values: { value_key => attr_value },
36
+ key_condition_expression: "#{name_key} = #{value_key}",
37
+ }
38
+
39
+ self.class.new(@item, @params.merge(params))
40
+ end
41
+
42
+ private
43
+
44
+ def run_query
45
+ @query ||= @item.query(@params)
46
+ end
47
+ end
48
+ end
@@ -1,3 +1,3 @@
1
1
  module Dynomite
2
- VERSION = "1.2.6"
2
+ VERSION = "1.2.7"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dynomite
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.6
4
+ version: 1.2.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tung Nguyen
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-05-28 00:00:00.000000000 Z
11
+ date: 2022-06-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -129,6 +129,7 @@ files:
129
129
  - lib/dynomite/migration/generator.rb
130
130
  - lib/dynomite/migration/templates/create_table.rb
131
131
  - lib/dynomite/migration/templates/update_table.rb
132
+ - lib/dynomite/query.rb
132
133
  - lib/dynomite/reserved_words.rb
133
134
  - lib/dynomite/version.rb
134
135
  homepage: https://github.com/tongueroo/dynomite
@@ -149,7 +150,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
149
150
  - !ruby/object:Gem::Version
150
151
  version: '0'
151
152
  requirements: []
152
- rubygems_version: 3.1.2
153
+ rubygems_version: 3.3.12
153
154
  signing_key:
154
155
  specification_version: 4
155
156
  summary: ActiveRecord-ish Dynamodb Model