dynamoid 3.5.0 → 3.6.0
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 +4 -4
- data/CHANGELOG.md +35 -4
- data/README.md +24 -18
- data/lib/dynamoid.rb +1 -0
- data/lib/dynamoid/adapter.rb +7 -4
- data/lib/dynamoid/adapter_plugin/aws_sdk_v3.rb +14 -11
- data/lib/dynamoid/adapter_plugin/aws_sdk_v3/batch_get_item.rb +1 -0
- data/lib/dynamoid/adapter_plugin/aws_sdk_v3/create_table.rb +8 -7
- data/lib/dynamoid/adapter_plugin/aws_sdk_v3/item_updater.rb +3 -2
- data/lib/dynamoid/adapter_plugin/aws_sdk_v3/middleware/backoff.rb +1 -0
- data/lib/dynamoid/adapter_plugin/aws_sdk_v3/middleware/limit.rb +1 -0
- data/lib/dynamoid/adapter_plugin/aws_sdk_v3/middleware/start_key.rb +1 -0
- data/lib/dynamoid/adapter_plugin/aws_sdk_v3/query.rb +1 -0
- data/lib/dynamoid/adapter_plugin/aws_sdk_v3/scan.rb +1 -0
- data/lib/dynamoid/adapter_plugin/aws_sdk_v3/table.rb +1 -0
- data/lib/dynamoid/adapter_plugin/aws_sdk_v3/until_past_table_status.rb +1 -0
- data/lib/dynamoid/application_time_zone.rb +1 -0
- data/lib/dynamoid/associations.rb +182 -19
- data/lib/dynamoid/associations/association.rb +4 -2
- data/lib/dynamoid/associations/belongs_to.rb +2 -1
- data/lib/dynamoid/associations/has_and_belongs_to_many.rb +2 -1
- data/lib/dynamoid/associations/has_many.rb +2 -1
- data/lib/dynamoid/associations/has_one.rb +2 -1
- data/lib/dynamoid/associations/many_association.rb +65 -22
- data/lib/dynamoid/associations/single_association.rb +28 -1
- data/lib/dynamoid/components.rb +1 -0
- data/lib/dynamoid/config.rb +3 -2
- data/lib/dynamoid/config/backoff_strategies/constant_backoff.rb +1 -0
- data/lib/dynamoid/config/backoff_strategies/exponential_backoff.rb +1 -0
- data/lib/dynamoid/config/options.rb +1 -0
- data/lib/dynamoid/criteria.rb +1 -0
- data/lib/dynamoid/criteria/chain.rb +353 -33
- data/lib/dynamoid/criteria/ignored_conditions_detector.rb +1 -0
- data/lib/dynamoid/criteria/key_fields_detector.rb +10 -1
- data/lib/dynamoid/criteria/nonexistent_fields_detector.rb +1 -0
- data/lib/dynamoid/criteria/overwritten_conditions_detector.rb +1 -0
- data/lib/dynamoid/dirty.rb +71 -16
- data/lib/dynamoid/document.rb +123 -42
- data/lib/dynamoid/dumping.rb +9 -0
- data/lib/dynamoid/dynamodb_time_zone.rb +1 -0
- data/lib/dynamoid/fields.rb +189 -16
- data/lib/dynamoid/finders.rb +65 -28
- data/lib/dynamoid/identity_map.rb +6 -0
- data/lib/dynamoid/indexes.rb +74 -15
- data/lib/dynamoid/log/formatter.rb +26 -0
- data/lib/dynamoid/middleware/identity_map.rb +1 -0
- data/lib/dynamoid/persistence.rb +452 -106
- data/lib/dynamoid/persistence/import.rb +1 -0
- data/lib/dynamoid/persistence/save.rb +1 -0
- data/lib/dynamoid/persistence/update_fields.rb +1 -0
- data/lib/dynamoid/persistence/upsert.rb +1 -0
- data/lib/dynamoid/primary_key_type_mapping.rb +1 -0
- data/lib/dynamoid/railtie.rb +1 -0
- data/lib/dynamoid/tasks/database.rb +1 -0
- data/lib/dynamoid/type_casting.rb +12 -0
- data/lib/dynamoid/undumping.rb +8 -0
- data/lib/dynamoid/validations.rb +2 -0
- data/lib/dynamoid/version.rb +1 -1
- metadata +7 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 26990dd042447eeba355601d0c7eb3657bcc482e80d00c1da5602d2f82765504
|
4
|
+
data.tar.gz: 76e1778155fb8a7a1d3135d4886d9e7caf1a07b72263fc38d9162ae946d5dab1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2aadf93639577566ed5dd9dadff596316f3d22384f5d7dabd0e06aa49992d3a58e824a8c150002c3a39d6e42f7b2b17c4f383bda2c145f4d05e1d56bf21a5e54
|
7
|
+
data.tar.gz: 14801f95c8cd1a241d2b1522b05a1e7af307822cef50e4515502f641027ade16aaf750a099801a2f2e4e379b15a4cd96e78f84754278db37d2e6fcdaab57b242
|
data/CHANGELOG.md
CHANGED
@@ -1,18 +1,49 @@
|
|
1
1
|
# HEAD
|
2
2
|
|
3
|
-
##
|
3
|
+
## Features
|
4
|
+
|
5
|
+
## Improvements
|
6
|
+
|
7
|
+
## Fixes
|
8
|
+
|
9
|
+
|
10
|
+
---
|
11
|
+
|
12
|
+
|
13
|
+
|
14
|
+
# 3.6.0 / 2020-07-13
|
15
|
+
|
4
16
|
|
5
17
|
## Features
|
6
18
|
|
19
|
+
* [#458](https://github.com/Dynamoid/dynamoid/pull/458) Added `binary` field type
|
20
|
+
* [#459](https://github.com/Dynamoid/dynamoid/pull/459) Added `log_formatter` config option and changed default logging format
|
21
|
+
|
7
22
|
## Improvements
|
8
23
|
|
24
|
+
* [#423](https://github.com/Dynamoid/dynamoid/pull/423) Added warning when generated for a field methods override existing ones
|
25
|
+
* [#429](https://github.com/Dynamoid/dynamoid/pull/429) Added `raise_error` option for `find` method
|
26
|
+
* [#440](https://github.com/Dynamoid/dynamoid/pull/440) Optimized performance of `first` method when there are only conditions on key attribute in a query (@mrkamel)
|
27
|
+
* [#445](https://github.com/Dynamoid/dynamoid/pull/445) Support `limit` parameter in `first` method (@mrkamel)
|
28
|
+
* [#450](https://github.com/Dynamoid/dynamoid/pull/450) Got rid of `null-logger` gem to make Dynamoid dependencies license suitable for commercial use (@yakjuly)
|
29
|
+
* [#454](https://github.com/Dynamoid/dynamoid/pull/454) Added block argument to `create`/`create!` methods
|
30
|
+
* [#456](https://github.com/Dynamoid/dynamoid/pull/456) Detect when `find` method requires a range key argument and raise `Dynamoid::Errors::MissingRangeKey` exception if it's missing
|
31
|
+
* YARD documentation:
|
32
|
+
* added missing documentation so now all the public methods are documented
|
33
|
+
* hid all the private methods and classes
|
34
|
+
|
9
35
|
## Fixes
|
10
36
|
|
37
|
+
* [#425](https://github.com/Dynamoid/dynamoid/pull/425) Fixed typos in the README.md file (@omarsotillo)
|
38
|
+
* [#432](https://github.com/Dynamoid/dynamoid/pull/432) Support tables that use "hash_key" as their partition key name (@remomueller)
|
39
|
+
* [#434](https://github.com/Dynamoid/dynamoid/pull/434) Support tables that have attribute with name "range_value"
|
40
|
+
* [#453](https://github.com/Dynamoid/dynamoid/pull/453) Fixed issue with using `type` attribute as a GSI hash key
|
41
|
+
|
11
42
|
---
|
12
43
|
|
13
44
|
|
14
45
|
|
15
|
-
# 3.5 / 2020-04-04
|
46
|
+
# 3.5.0 / 2020-04-04
|
16
47
|
|
17
48
|
|
18
49
|
## Features
|
@@ -20,13 +51,13 @@
|
|
20
51
|
* Feature: [#408](https://github.com/Dynamoid/dynamoid/pull/408) Added `ActiveSupport` load hook on `Dynamoid` load (@aaronmallen)
|
21
52
|
* Feature: [#422](https://github.com/Dynamoid/dynamoid/pull/422) Added `.pluck` method
|
22
53
|
|
23
|
-
Fixes:
|
54
|
+
## Fixes:
|
24
55
|
* Fix: [#410](https://github.com/Dynamoid/dynamoid/pull/410) Fixed creating GSI when table uses on-demand capacity provisioning (@icy-arctic-fox)
|
25
56
|
* Fix: [#414](https://github.com/Dynamoid/dynamoid/pull/414) Fixed lazy table creation
|
26
57
|
* Fix: [#415](https://github.com/Dynamoid/dynamoid/pull/415) Fixed RubyDoc comment (@walkersumida)
|
27
58
|
* Fix: [#420](https://github.com/Dynamoid/dynamoid/pull/420) Fixed `#persisted?` for deleted/destroyed models
|
28
59
|
|
29
|
-
Improvements:
|
60
|
+
## Improvements:
|
30
61
|
* Improvement: [#416](https://github.com/Dynamoid/dynamoid/pull/416) Improved speed of Adapter's `truncate` method. It now uses `#batch_delete_item` method (@TheSmartnik)
|
31
62
|
* Improvement: [#421](https://github.com/Dynamoid/dynamoid/pull/421) Added `touch: false` option of the #save method
|
32
63
|
* Improvement: [#423](https://github.com/Dynamoid/dynamoid/pull/423) Added warning when generated for a field methods override existing ones
|
data/README.md
CHANGED
@@ -212,16 +212,17 @@ each field. Every field on the object must be included here; if you miss
|
|
212
212
|
any they'll be completely bypassed during DynamoDB's initialization and
|
213
213
|
will not appear on the model objects.
|
214
214
|
|
215
|
-
By default, fields are assumed to be of type
|
216
|
-
types are
|
217
|
-
`date`,
|
218
|
-
List and Map DynamoDB types respectively. `raw` type means
|
219
|
-
Ruby Array, Hash, String and numbers. If built-in types do
|
220
|
-
you can use a custom field type represented by an
|
221
|
-
provided that the class supports a compatible
|
222
|
-
The primary use case for using a custom field
|
223
|
-
business logic with high-level types, while
|
224
|
-
backward-compatibility of the serialized
|
215
|
+
By default, fields are assumed to be of type `string`. Other built-in
|
216
|
+
types are `integer`, `number`, `set`, `array`, `map`, `datetime`,
|
217
|
+
`date`, `boolean`, `binary`, `raw` and `serialized`. `array` and
|
218
|
+
`map` match List and Map DynamoDB types respectively. `raw` type means
|
219
|
+
you can store Ruby Array, Hash, String and numbers. If built-in types do
|
220
|
+
not suit you, you can use a custom field type represented by an
|
221
|
+
arbitrary class, provided that the class supports a compatible
|
222
|
+
serialization interface. The primary use case for using a custom field
|
223
|
+
type is to represent your business logic with high-level types, while
|
224
|
+
ensuring portability or backward-compatibility of the serialized
|
225
|
+
representation.
|
225
226
|
|
226
227
|
#### Note on boolean type
|
227
228
|
|
@@ -232,7 +233,7 @@ easily achieve this with `store_as_native_boolean` field option:
|
|
232
233
|
|
233
234
|
```ruby
|
234
235
|
class Document
|
235
|
-
include
|
236
|
+
include Dynamoid::Document
|
236
237
|
|
237
238
|
field :active, :boolean, store_as_native_boolean: false
|
238
239
|
end
|
@@ -246,7 +247,7 @@ strings instead then set `store_as_string` to `true`
|
|
246
247
|
|
247
248
|
```ruby
|
248
249
|
class Document
|
249
|
-
include
|
250
|
+
include Dynamoid::Document
|
250
251
|
|
251
252
|
field :sent_on, :date, store_as_string: true
|
252
253
|
end
|
@@ -261,7 +262,7 @@ as ISO-8601 formatted strings instead then set `store_as_string` to
|
|
261
262
|
|
262
263
|
```ruby
|
263
264
|
class Document
|
264
|
-
include
|
265
|
+
include Dynamoid::Document
|
265
266
|
|
266
267
|
field :sent_at, :datetime, store_as_string: true
|
267
268
|
end
|
@@ -293,7 +294,7 @@ types.
|
|
293
294
|
|
294
295
|
```ruby
|
295
296
|
class Document
|
296
|
-
include
|
297
|
+
include Dynamoid::Document
|
297
298
|
|
298
299
|
field :tags, :set, of: :integer
|
299
300
|
end
|
@@ -305,7 +306,7 @@ elements type:
|
|
305
306
|
|
306
307
|
```ruby
|
307
308
|
class Document
|
308
|
-
include
|
309
|
+
include Dynamoid::Document
|
309
310
|
|
310
311
|
field :values, :set, of: { serialized: { serializer: JSON } }
|
311
312
|
field :dates, :set, of: { date: { store_as_string: true } }
|
@@ -329,7 +330,7 @@ natively, you should specify element type with `of` option:
|
|
329
330
|
|
330
331
|
```ruby
|
331
332
|
class Document
|
332
|
-
include
|
333
|
+
include Dynamoid::Document
|
333
334
|
|
334
335
|
field :dates, :array, of: :date
|
335
336
|
end
|
@@ -762,7 +763,7 @@ for requesting documents in batches:
|
|
762
763
|
|
763
764
|
```ruby
|
764
765
|
# Do some maintenance on the entire table without flooding DynamoDB
|
765
|
-
Address.
|
766
|
+
Address.batch(100).each { |address| address.do_some_work; sleep(0.01) }
|
766
767
|
Address.record_limit(10_000).batch(100).each { … } # Batch specified as part of a chain
|
767
768
|
```
|
768
769
|
|
@@ -1068,7 +1069,7 @@ Listed below are all configuration options.
|
|
1068
1069
|
* `models_dir` - `dynamoid:create_tables` rake task loads DynamoDb
|
1069
1070
|
models from this directory. Default is `./app/models`.
|
1070
1071
|
* `application_timezone` - Dynamoid converts all `datetime` fields to
|
1071
|
-
|
1072
|
+
specified time zone when loads data from the storage.
|
1072
1073
|
Acceptable values - `:utc`, `:local` (to use system time zone) and
|
1073
1074
|
time zone name e.g. `Eastern Time (US & Canada)`. Default is `utc`
|
1074
1075
|
* `dynamodb_timezone` - When a datetime field is stored in string format
|
@@ -1088,6 +1089,11 @@ Listed below are all configuration options.
|
|
1088
1089
|
`nil`
|
1089
1090
|
* `backoff_strategies`: is a hash and contains all available strategies.
|
1090
1091
|
Default is { constant: ..., exponential: ...}
|
1092
|
+
* `log_formatter`: overrides default AWS SDK formatter. There are
|
1093
|
+
several canned formatters: `Aws::Log::Formatter.default`,
|
1094
|
+
`Aws::Log::Formatter.colored` and `Aws::Log::Formatter.short`. Please
|
1095
|
+
look into `Aws::Log::Formatter` AWS SDK documentation in order to
|
1096
|
+
provide own formatter.
|
1091
1097
|
* `http_continue_timeout`: The number of seconds to wait for a
|
1092
1098
|
100-continue HTTP response before sending the request body. Default
|
1093
1099
|
option value is `nil`. If not specified effected value is `1`
|
data/lib/dynamoid.rb
CHANGED
data/lib/dynamoid/adapter.rb
CHANGED
@@ -11,6 +11,7 @@ module Dynamoid
|
|
11
11
|
# 1) For the rest of Dynamoid, the gateway to DynamoDB.
|
12
12
|
# 2) Allows switching `config.adapter` to ease development of a new adapter.
|
13
13
|
# 3) Caches the list of tables Dynamoid knows about.
|
14
|
+
# @private
|
14
15
|
class Adapter
|
15
16
|
def initialize
|
16
17
|
@adapter_ = Concurrent::Atom.new(nil)
|
@@ -78,8 +79,8 @@ module Dynamoid
|
|
78
79
|
#
|
79
80
|
# @param [String] table the name of the table to write the object to
|
80
81
|
# @param [Array] ids to fetch, can also be a string of just one id
|
81
|
-
# @param [Hash] options
|
82
|
-
#
|
82
|
+
# @param [Hash] options Passed to the underlying query. The :range_key option is required whenever the table has a range key,
|
83
|
+
# unless multiple ids are passed in.
|
83
84
|
#
|
84
85
|
# @since 0.2.0
|
85
86
|
def read(table, ids, options = {}, &blk)
|
@@ -94,7 +95,9 @@ module Dynamoid
|
|
94
95
|
#
|
95
96
|
# @param [String] table the name of the table to write the object to
|
96
97
|
# @param [Array] ids to delete, can also be a string of just one id
|
97
|
-
# @param [Hash]
|
98
|
+
# @param [Hash] options allowed only +range_key+ - range key or array of
|
99
|
+
# range keys of the record to delete, can also be
|
100
|
+
# a string of just one range_key, and +conditions+
|
98
101
|
#
|
99
102
|
def delete(table, ids, options = {})
|
100
103
|
range_key = options[:range_key] # array of range keys that matches the ids passed in
|
@@ -115,7 +118,7 @@ module Dynamoid
|
|
115
118
|
# Scans a table. Generally quite slow; try to avoid using scan if at all possible.
|
116
119
|
#
|
117
120
|
# @param [String] table the name of the table to write the object to
|
118
|
-
# @param [Hash]
|
121
|
+
# @param [Hash] query a hash of attributes: matching records will be returned by the scan
|
119
122
|
#
|
120
123
|
# @since 0.2.0
|
121
124
|
def scan(table, query = {}, opts = {})
|
@@ -9,6 +9,7 @@ require_relative 'aws_sdk_v3/table'
|
|
9
9
|
require_relative 'aws_sdk_v3/until_past_table_status'
|
10
10
|
|
11
11
|
module Dynamoid
|
12
|
+
# @private
|
12
13
|
module AdapterPlugin
|
13
14
|
# The AwsSdkV3 adapter provides support for the aws-sdk version 2 for ruby.
|
14
15
|
class AwsSdkV3
|
@@ -64,8 +65,8 @@ module Dynamoid
|
|
64
65
|
# Build an array of values for Condition
|
65
66
|
# Is used in ScanFilter and QueryFilter
|
66
67
|
# https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_Condition.html
|
67
|
-
# @
|
68
|
-
# @
|
68
|
+
# @param [String] operator value of RANGE_MAP or FIELD_MAP hash, e.g. "EQ", "LT" etc
|
69
|
+
# @param [Object] value scalar value or array/set
|
69
70
|
def self.attribute_value_list(operator, value)
|
70
71
|
# For BETWEEN and IN operators we should keep value as is (it should be already an array)
|
71
72
|
# NULL and NOT_NULL require absence of attribute list
|
@@ -108,12 +109,14 @@ module Dynamoid
|
|
108
109
|
end
|
109
110
|
end
|
110
111
|
|
111
|
-
# https://github.com/aws/aws-sdk-ruby/blob/master/gems/aws-sdk-core/lib/aws-sdk-core/plugins/logging.rb
|
112
|
-
# https://github.com/aws/aws-sdk-ruby/blob/master/gems/aws-sdk-core/lib/aws-sdk-core/log/formatter.rb
|
113
|
-
formatter = Aws::Log::Formatter.new(':operation | Request :http_request_body | Response :http_response_body')
|
114
112
|
@connection_hash[:logger] = Dynamoid::Config.logger
|
115
113
|
@connection_hash[:log_level] = :debug
|
116
|
-
|
114
|
+
|
115
|
+
# https://github.com/aws/aws-sdk-ruby/blob/master/gems/aws-sdk-core/lib/aws-sdk-core/plugins/logging.rb
|
116
|
+
# https://github.com/aws/aws-sdk-ruby/blob/master/gems/aws-sdk-core/lib/aws-sdk-core/log/formatter.rb
|
117
|
+
if Dynamoid::Config.log_formatter
|
118
|
+
@connection_hash[:log_formatter] = Dynamoid::Config.log_formatter
|
119
|
+
end
|
117
120
|
|
118
121
|
@connection_hash
|
119
122
|
end
|
@@ -141,9 +144,9 @@ module Dynamoid
|
|
141
144
|
# end
|
142
145
|
#
|
143
146
|
# @param [String] table_name the name of the table
|
144
|
-
# @param [Array]
|
145
|
-
# @param [Hash] additional options
|
146
|
-
# @
|
147
|
+
# @param [Array] objects to be processed
|
148
|
+
# @param [Hash] options additional options
|
149
|
+
# @yield [true|false] invokes an optional block with argument - whether there are unprocessed items
|
147
150
|
#
|
148
151
|
# See:
|
149
152
|
# * http://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_BatchWriteItem.html
|
@@ -198,9 +201,9 @@ module Dynamoid
|
|
198
201
|
# end
|
199
202
|
# end
|
200
203
|
#
|
201
|
-
# @param [Hash]
|
204
|
+
# @param [Hash] table_names_with_ids the hash of tables and IDs to retrieve
|
202
205
|
# @param [Hash] options to be passed to underlying BatchGet call
|
203
|
-
# @param [Proc] optional block can be passed to handle each batch of items
|
206
|
+
# @param [Proc] block optional block can be passed to handle each batch of items
|
204
207
|
#
|
205
208
|
# @return [Hash] a hash where keys are the table names and the values are the retrieved items
|
206
209
|
#
|
@@ -3,6 +3,7 @@
|
|
3
3
|
require_relative 'until_past_table_status'
|
4
4
|
|
5
5
|
module Dynamoid
|
6
|
+
# @private
|
6
7
|
module AdapterPlugin
|
7
8
|
class AwsSdkV3
|
8
9
|
class CreateTable
|
@@ -87,9 +88,9 @@ module Dynamoid
|
|
87
88
|
# Builds aws attributes definitions based off of primary hash/range and
|
88
89
|
# secondary indexes
|
89
90
|
#
|
90
|
-
# @param
|
91
|
-
# @option
|
92
|
-
# @option
|
91
|
+
# @param key_schema
|
92
|
+
# @option key_schema [Hash] hash_key_schema - eg: {:id => :string}
|
93
|
+
# @option key_schema [Hash] range_key_schema - eg: {:created_at => :number}
|
93
94
|
# @param [Hash] secondary_indexes
|
94
95
|
# @option secondary_indexes [Array<Dynamoid::Indexes::Index>] :local_secondary_indexes
|
95
96
|
# @option secondary_indexes [Array<Dynamoid::Indexes::Index>] :global_secondary_indexes
|
@@ -130,8 +131,8 @@ module Dynamoid
|
|
130
131
|
end
|
131
132
|
|
132
133
|
# Builds an attribute definitions based on hash key and range key
|
133
|
-
# @
|
134
|
-
# @
|
134
|
+
# @param [Hash] hash_key_schema - eg: {:id => :string}
|
135
|
+
# @param [Hash] range_key_schema - eg: {:created_at => :datetime}
|
135
136
|
# @return [Array]
|
136
137
|
def build_attribute_definitions(hash_key_schema, range_key_schema = nil)
|
137
138
|
attrs = []
|
@@ -152,8 +153,8 @@ module Dynamoid
|
|
152
153
|
end
|
153
154
|
|
154
155
|
# Builds an aws attribute definition based on name and dynamoid type
|
155
|
-
# @
|
156
|
-
# @
|
156
|
+
# @param [Symbol] name - eg: :id
|
157
|
+
# @param [Symbol] dynamoid_type - eg: :string
|
157
158
|
# @return [Hash]
|
158
159
|
def attribute_definition_element(name, dynamoid_type)
|
159
160
|
aws_type = api_type(dynamoid_type)
|
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Dynamoid
|
4
|
+
# @private
|
4
5
|
module AdapterPlugin
|
5
6
|
class AwsSdkV3
|
6
7
|
# Mimics behavior of the yielded object on DynamoDB's update_item API (high level).
|
@@ -20,8 +21,8 @@ module Dynamoid
|
|
20
21
|
# Adds the given values to the values already stored in the corresponding columns.
|
21
22
|
# The column must contain a Set or a number.
|
22
23
|
#
|
23
|
-
# @param [Hash]
|
24
|
-
#
|
24
|
+
# @param [Hash] values keys of the hash are the columns to update, values
|
25
|
+
# are the values to add. values must be a Set, Array, or Numeric
|
25
26
|
#
|
26
27
|
def add(values)
|
27
28
|
@additions.merge!(sanitize_attributes(values))
|
@@ -25,12 +25,55 @@ module Dynamoid
|
|
25
25
|
end
|
26
26
|
|
27
27
|
module ClassMethods
|
28
|
-
#
|
28
|
+
# Declare a +has_many+ association for this document.
|
29
29
|
#
|
30
|
-
#
|
31
|
-
#
|
30
|
+
# class Category
|
31
|
+
# include Dynamoid::Document
|
32
|
+
#
|
33
|
+
# has_many :posts
|
34
|
+
# end
|
35
|
+
#
|
36
|
+
# Association is an enumerable collection and supports following addition
|
37
|
+
# operations:
|
38
|
+
#
|
39
|
+
# * +create+
|
40
|
+
# * +create!+
|
41
|
+
# * +destroy_all+
|
42
|
+
# * +delete_all+
|
43
|
+
# * +delete+
|
44
|
+
# * +<<+
|
45
|
+
# * +where+
|
46
|
+
# * +all+
|
47
|
+
# * +empty?+
|
48
|
+
# * +size+
|
49
|
+
#
|
50
|
+
# When a name of an associated class doesn't match an association name a
|
51
|
+
# class name should be specified explicitly either with +class+ or
|
52
|
+
# +class_name+ option:
|
53
|
+
#
|
54
|
+
# has_many :labels, class: Tag
|
55
|
+
# has_many :labels, class_name: 'Tag'
|
56
|
+
#
|
57
|
+
# When associated class has own +belongs_to+ association to
|
58
|
+
# the current class and the name doesn't match a name of the current
|
59
|
+
# class this name can be specified with +inverse_of+ option:
|
60
|
+
#
|
61
|
+
# class Post
|
62
|
+
# include Dynamoid::Document
|
63
|
+
#
|
64
|
+
# belongs_to :item, class_name: 'Tag'
|
65
|
+
# end
|
66
|
+
#
|
67
|
+
# class Tag
|
68
|
+
# include Dynamoid::Document
|
69
|
+
#
|
70
|
+
# has_many :posts, inverse_of: :item
|
71
|
+
# end
|
72
|
+
#
|
73
|
+
# @param name [Symbol] the name of the association
|
74
|
+
# @param options [Hash] options to pass to the association constructor
|
32
75
|
# @option options [Class] :class the target class of the has_many association; that is, the belongs_to class
|
33
|
-
# @option options [
|
76
|
+
# @option options [String] :class_name the name of the target class of the association; that is, the name of the belongs_to class
|
34
77
|
# @option options [Symbol] :inverse_of the name of the association on the target class; that is, if the class has a belongs_to association, the name of that association
|
35
78
|
#
|
36
79
|
# @since 0.2.0
|
@@ -38,12 +81,47 @@ module Dynamoid
|
|
38
81
|
association(:has_many, name, options)
|
39
82
|
end
|
40
83
|
|
41
|
-
#
|
84
|
+
# Declare a +has_one+ association for this document.
|
85
|
+
#
|
86
|
+
# class Image
|
87
|
+
# include Dynamoid::Document
|
42
88
|
#
|
43
|
-
#
|
44
|
-
#
|
89
|
+
# has_one :post
|
90
|
+
# end
|
91
|
+
#
|
92
|
+
# Association supports following operations:
|
93
|
+
#
|
94
|
+
# * +create+
|
95
|
+
# * +create!+
|
96
|
+
# * +delete+
|
97
|
+
#
|
98
|
+
# When a name of an associated class doesn't match an association name a
|
99
|
+
# class name should be specified explicitly either with +class+ or
|
100
|
+
# +class_name+ option:
|
101
|
+
#
|
102
|
+
# has_one :item, class: Post
|
103
|
+
# has_one :item, class_name: 'Post'
|
104
|
+
#
|
105
|
+
# When associated class has own +belong_to+ association to the current
|
106
|
+
# class and the name doesn't match a name of the current class this name
|
107
|
+
# can be specified with +inverse_of+ option:
|
108
|
+
#
|
109
|
+
# class Post
|
110
|
+
# include Dynamoid::Document
|
111
|
+
#
|
112
|
+
# belongs_to :logo, class_name: 'Image'
|
113
|
+
# end
|
114
|
+
#
|
115
|
+
# class Image
|
116
|
+
# include Dynamoid::Document
|
117
|
+
#
|
118
|
+
# has_one :post, inverse_of: :logo
|
119
|
+
# end
|
120
|
+
#
|
121
|
+
# @param name [Symbol] the name of the association
|
122
|
+
# @param options [Hash] options to pass to the association constructor
|
45
123
|
# @option options [Class] :class the target class of the has_one association; that is, the belongs_to class
|
46
|
-
# @option options [
|
124
|
+
# @option options [String] :class_name the name of the target class of the association; that is, the name of the belongs_to class
|
47
125
|
# @option options [Symbol] :inverse_of the name of the association on the target class; that is, if the class has a belongs_to association, the name of that association
|
48
126
|
#
|
49
127
|
# @since 0.2.0
|
@@ -51,25 +129,110 @@ module Dynamoid
|
|
51
129
|
association(:has_one, name, options)
|
52
130
|
end
|
53
131
|
|
54
|
-
#
|
132
|
+
# Declare a +belongs_to+ association for this document.
|
133
|
+
#
|
134
|
+
# class Post
|
135
|
+
# include Dynamoid::Document
|
55
136
|
#
|
56
|
-
#
|
57
|
-
#
|
137
|
+
# belongs_to :categories
|
138
|
+
# end
|
139
|
+
#
|
140
|
+
# Association supports following operations:
|
141
|
+
#
|
142
|
+
# * +create+
|
143
|
+
# * +create!+
|
144
|
+
# * +delete+
|
145
|
+
#
|
146
|
+
# When a name of an associated class doesn't match an association name a
|
147
|
+
# class name should be specified explicitly either with +class+ or
|
148
|
+
# +class_name+ option:
|
149
|
+
#
|
150
|
+
# belongs_to :item, class: Post
|
151
|
+
# belongs_to :item, class_name: 'Post'
|
152
|
+
#
|
153
|
+
# When associated class has own +has_many+ or +has_one+ association to
|
154
|
+
# the current class and the name doesn't match a name of the current
|
155
|
+
# class this name can be specified with +inverse_of+ option:
|
156
|
+
#
|
157
|
+
# class Category
|
158
|
+
# include Dynamoid::Document
|
159
|
+
#
|
160
|
+
# has_many :items, class_name: 'Post'
|
161
|
+
# end
|
162
|
+
#
|
163
|
+
# class Post
|
164
|
+
# include Dynamoid::Document
|
165
|
+
#
|
166
|
+
# belongs_to :categories, inverse_of: :items
|
167
|
+
# end
|
168
|
+
#
|
169
|
+
# By default a hash key attribute name is +id+. If an associated class
|
170
|
+
# uses another name for a hash key attribute it should be specified in
|
171
|
+
# the +belongs_to+ association:
|
172
|
+
#
|
173
|
+
# belongs_to :categories, foreign_key: :uuid
|
174
|
+
#
|
175
|
+
# @param name [Symbol] the name of the association
|
176
|
+
# @param options [Hash] options to pass to the association constructor
|
58
177
|
# @option options [Class] :class the target class of the has_one association; that is, the has_many or has_one class
|
59
|
-
# @option options [
|
178
|
+
# @option options [String] :class_name the name of the target class of the association; that is, the name of the has_many or has_one class
|
60
179
|
# @option options [Symbol] :inverse_of the name of the association on the target class; that is, if the class has a has_many or has_one association, the name of that association
|
180
|
+
# @option options [Symbol] :foreign_key the name of a hash key attribute in the target class
|
61
181
|
#
|
62
182
|
# @since 0.2.0
|
63
183
|
def belongs_to(name, options = {})
|
64
184
|
association(:belongs_to, name, options)
|
65
185
|
end
|
66
186
|
|
67
|
-
#
|
187
|
+
# Declare a +has_and_belongs_to_many+ association for this document.
|
188
|
+
#
|
189
|
+
# class Post
|
190
|
+
# include Dynamoid::Document
|
191
|
+
#
|
192
|
+
# has_and_belongs_to_many :tags
|
193
|
+
# end
|
194
|
+
#
|
195
|
+
# Association is an enumerable collection and supports following addition
|
196
|
+
# operations:
|
197
|
+
#
|
198
|
+
# * +create+
|
199
|
+
# * +create!+
|
200
|
+
# * +destroy_all+
|
201
|
+
# * +delete_all+
|
202
|
+
# * +delete+
|
203
|
+
# * +<<+
|
204
|
+
# * +where+
|
205
|
+
# * +all+
|
206
|
+
# * +empty?+
|
207
|
+
# * +size+
|
208
|
+
#
|
209
|
+
# When a name of an associated class doesn't match an association name a
|
210
|
+
# class name should be specified explicitly either with +class+ or
|
211
|
+
# +class_name+ option:
|
212
|
+
#
|
213
|
+
# has_and_belongs_to_many :labels, class: Tag
|
214
|
+
# has_and_belongs_to_many :labels, class_name: 'Tag'
|
215
|
+
#
|
216
|
+
# When associated class has own +has_and_belongs_to_many+ association to
|
217
|
+
# the current class and the name doesn't match a name of the current
|
218
|
+
# class this name can be specified with +inverse_of+ option:
|
219
|
+
#
|
220
|
+
# class Tag
|
221
|
+
# include Dynamoid::Document
|
222
|
+
#
|
223
|
+
# has_and_belongs_to_many :items, class_name: 'Post'
|
224
|
+
# end
|
225
|
+
#
|
226
|
+
# class Post
|
227
|
+
# include Dynamoid::Document
|
228
|
+
#
|
229
|
+
# has_and_belongs_to_many :tags, inverse_of: :items
|
230
|
+
# end
|
68
231
|
#
|
69
|
-
# @param [Symbol]
|
70
|
-
# @param [Hash] options
|
232
|
+
# @param name [Symbol] the name of the association
|
233
|
+
# @param options [Hash] options to pass to the association constructor
|
71
234
|
# @option options [Class] :class the target class of the has_and_belongs_to_many association; that is, the belongs_to class
|
72
|
-
# @option options [
|
235
|
+
# @option options [String] :class_name the name of the target class of the association; that is, the name of the belongs_to class
|
73
236
|
# @option options [Symbol] :inverse_of the name of the association on the target class; that is, if the class has a belongs_to association, the name of that association
|
74
237
|
#
|
75
238
|
# @since 0.2.0
|
@@ -81,9 +244,9 @@ module Dynamoid
|
|
81
244
|
|
82
245
|
# create getters and setters for an association.
|
83
246
|
#
|
84
|
-
# @param [Symbol]
|
85
|
-
# @param [Symbol]
|
86
|
-
# @param [Hash] options
|
247
|
+
# @param type [Symbol] the type (:has_one, :has_many, :has_and_belongs_to_many, :belongs_to) of the association
|
248
|
+
# @param name [Symbol] the name of the association
|
249
|
+
# @param options [Hash] options to pass to the association constructor; see above for all valid options
|
87
250
|
#
|
88
251
|
# @since 0.2.0
|
89
252
|
def association(type, name, options = {})
|