dynamoid_advanced_where 1.6.0 → 1.7.0

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: a830c51235f4fec181d2c9b6a5308f55015c23aea40be329dfecaa023f561b37
4
- data.tar.gz: 95af2de8d86ad0de5ff9925591d5d161bdc3226c5b955544cfce32595c7297c6
3
+ metadata.gz: 239094fa5509e994cefa186a296b6f00bbc7a13913ea67803f82f173e6aea82a
4
+ data.tar.gz: cb46ded36d28fc09b54ea3b1598c34e2172232824056c9b6462f846f491e9673
5
5
  SHA512:
6
- metadata.gz: 9f90439b8db774d0aae74bd08ee096b9a9fbd091b61e07e01d4b470b77f6f8de78fc52b296cf2625fd42c40b81be0b230402c378c46f1358459ffd6ddfe58036
7
- data.tar.gz: c6f26e04f8be1dab29bc4f909fe04ae0afeaf27abc2f60515102822c13ac7690708545d1d43f14f9487acc860b77162e4618da9542d86be8f4e0d7bee289e947
6
+ metadata.gz: bce42bfde6205d3a63ea557b0624391170f586220247fc3c7ab17a1203eb6876d4356b6758a41df0756ea9de07ee06b29ce84ba4c40b516143a803d2d361a9cc
7
+ data.tar.gz: 633267b36adc9112e67aa8c541946d4ce9a56821d68aa339af211c5ffa400c6b6491b188e33f1dcda01ebd4ea32842fffcde432a783687d14080fc589beecb52
@@ -6,15 +6,16 @@ require_relative './batched_updater'
6
6
 
7
7
  module DynamoidAdvancedWhere
8
8
  class QueryBuilder
9
- attr_accessor :klass, :root_node, :start_hash, :record_limit
9
+ attr_accessor :klass, :root_node, :start_hash, :record_limit, :projected_fields
10
10
 
11
11
  delegate :all, :each_page, :each, to: :query_materializer
12
12
 
13
- def initialize(klass:, record_limit: nil, start_hash: nil, root_node: nil, &blk)
13
+ def initialize(klass:, projected_fields: [], record_limit: nil, start_hash: nil, root_node: nil, &blk)
14
14
  self.klass = klass
15
15
  self.root_node = root_node || Nodes::RootNode.new(klass: klass, &blk)
16
16
  self.start_hash = start_hash
17
17
  self.record_limit = record_limit
18
+ self.projected_fields = projected_fields
18
19
 
19
20
  freeze
20
21
  end
@@ -49,6 +50,10 @@ module DynamoidAdvancedWhere
49
50
  end
50
51
  alias and where
51
52
 
53
+ def project(*fields)
54
+ dup_with_changes(projected_fields: projected_fields + fields)
55
+ end
56
+
52
57
  def limit(value)
53
58
  dup_with_changes(record_limit: value)
54
59
  end
@@ -68,6 +73,7 @@ module DynamoidAdvancedWhere
68
73
  klass: klass,
69
74
  start_hash: start_hash,
70
75
  root_node: root_node,
76
+ projected_fields: projected_fields,
71
77
  }.merge(changes))
72
78
  end
73
79
  end
@@ -44,11 +44,13 @@ module DynamoidAdvancedWhere
44
44
  end
45
45
  end
46
46
 
47
- def each_page_via_query
48
- query = {
49
- table_name: table_name,
50
- index_name: selected_index_for_query,
51
- }.merge(filter_builder.to_query_filter)
47
+ def enumerate_results(starting_query)
48
+ query = starting_query.dup
49
+
50
+ unless query_builder.projected_fields.empty?
51
+ query[:select] = 'SPECIFIC_ATTRIBUTES'
52
+ query[:projection_expression] = query_builder.projected_fields.map(&:to_s).join(',')
53
+ end
52
54
 
53
55
  query[:limit] = query_builder.record_limit if query_builder.record_limit
54
56
 
@@ -56,7 +58,8 @@ module DynamoidAdvancedWhere
56
58
 
57
59
  Enumerator.new do |yielder|
58
60
  loop do
59
- results = client.query(query.merge(exclusive_start_key: page_start))
61
+ query[:exclusive_start_key] = page_start
62
+ results = yield(query)
60
63
 
61
64
  items = (results.items || []).map do |item|
62
65
  klass.from_database(item.symbolize_keys)
@@ -73,32 +76,25 @@ module DynamoidAdvancedWhere
73
76
  end.lazy
74
77
  end
75
78
 
76
- def each_page_via_scan
79
+ def each_page_via_query
77
80
  query = {
78
81
  table_name: table_name,
79
- }.merge(filter_builder.to_scan_filter)
80
-
81
- query[:limit] = query_builder.record_limit if query_builder.record_limit
82
-
83
- page_start = start_hash
84
-
85
- Enumerator.new do |yielder|
86
- loop do
87
- results = client.scan(query.merge(exclusive_start_key: page_start))
88
-
89
- items = (results.items || []).map do |item|
90
- klass.from_database(item.symbolize_keys)
91
- end
92
-
93
- yielder.yield(items, results)
82
+ index_name: selected_index_for_query,
83
+ }.merge(filter_builder.to_query_filter)
94
84
 
95
- query[:limit] = query[:limit] - results.items.length if query[:limit]
85
+ enumerate_results(query) do |q|
86
+ client.query(q)
87
+ end
88
+ end
96
89
 
97
- break if results.last_evaluated_key.nil? || query[:limit]&.zero?
90
+ def each_page_via_scan
91
+ query = {
92
+ table_name: table_name,
93
+ }.merge(filter_builder.to_scan_filter)
98
94
 
99
- (page_start = results.last_evaluated_key)
100
- end
101
- end.lazy
95
+ enumerate_results(query) do |q|
96
+ client.scan(q)
97
+ end
102
98
  end
103
99
 
104
100
  def filter_builder
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DynamoidAdvancedWhere
4
- VERSION = '1.6.0'
4
+ VERSION = '1.7.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dynamoid_advanced_where
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.0
4
+ version: 1.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Malinconico
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-04-07 00:00:00.000000000 Z
11
+ date: 2023-04-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dynamoid