Skip to content

Commit 9275973

Browse files
committed
Update documentation comments for transactional methods and document difference between them and non-transactional ones
1 parent 180f675 commit 9275973

File tree

1 file changed

+146
-1
lines changed

1 file changed

+146
-1
lines changed

lib/dynamoid/transaction_write.rb

Lines changed: 146 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,23 @@ def rollback
178178
# When a model is not persisted - its id should have unique value.
179179
# Otherwise a transaction will be rolled back.
180180
#
181+
# Raises +Dynamoid::Errors::MissingHashKey+ if a model is already persisted
182+
# and a partition key has value +nil+ and raises
183+
# +Dynamoid::Errors::MissingRangeKey+ if a sort key is required but has
184+
# value +nil+.
185+
#
186+
# There are the following differences between transactional and
187+
# non-transactional +#save!+:
188+
# - transactional +#save!+ doesn't support the +:touch+ option
189+
# - transactional +#save!+ doesn't support +lock_version+ attribute so it
190+
# will not be incremented and will not be checked to detect concurrent
191+
# modification of a model and +Dynamoid::Errors::StaleObjectError+
192+
# exception will not be raised
193+
# - transactional +#save!+ doesn't raise +Dynamoid::Errors::RecordNotUnique+
194+
# at saving new model when primary key is already used. A generic
195+
# +Aws::DynamoDB::Errors::TransactionCanceledException+ is raised instead.
196+
# - a table isn't created lazily if it doesn't exist yet
197+
#
181198
# @param model [Dynamoid::Document] a model
182199
# @param options [Hash] (optional)
183200
# @option options [true|false] :validate validate a model or not - +true+ by default (optional)
@@ -216,6 +233,23 @@ def save!(model, **options)
216233
# When a model is not persisted - its id should have unique value.
217234
# Otherwise a transaction will be rolled back.
218235
#
236+
# Raises +Dynamoid::Errors::MissingHashKey+ if a model is already persisted
237+
# and a partition key has value +nil+ and raises
238+
# +Dynamoid::Errors::MissingRangeKey+ if a sort key is required but has
239+
# value +nil+.
240+
#
241+
# There are the following differences between transactional and
242+
# non-transactional +#save+:
243+
# - transactional +#save+ doesn't support the +:touch+ option
244+
# - transactional +#save+ doesn't support +lock_version+ attribute so it
245+
# will not be incremented and will not be checked to detect concurrent
246+
# modification of a model and +Dynamoid::Errors::StaleObjectError+
247+
# exception will not be raised
248+
# - transactional +#save+ doesn't raise +Dynamoid::Errors::RecordNotUnique+
249+
# at saving new model when primary key is already used. A generic
250+
# +Aws::DynamoDB::Errors::TransactionCanceledException+ is raised instead.
251+
# - a table isn't created lazily if it doesn't exist yet
252+
#
219253
# @param model [Dynamoid::Document] a model
220254
# @param options [Hash] (optional)
221255
# @option options [true|false] :validate validate a model or not - +true+ by default (optional)
@@ -248,6 +282,20 @@ def save(model, **options)
248282
#
249283
# Validates model and runs callbacks.
250284
#
285+
# Raises +Dynamoid::Errors::MissingRangeKey+ if a sort key is required but
286+
# not specified or has value +nil+.
287+
#
288+
# There are the following differences between transactional and
289+
# non-transactional +#create+:
290+
# - transactional +#create!+ doesn't support +lock_version+ attribute so it
291+
# will not be incremented and will not be checked to detect concurrent
292+
# modification of a model and +Dynamoid::Errors::StaleObjectError+
293+
# exception will not be raised
294+
# - transactional +#create!+ doesn't raise +Dynamoid::Errors::RecordNotUnique+
295+
# at saving new model when primary key is already used. A generic
296+
# +Aws::DynamoDB::Errors::TransactionCanceledException+ is raised instead.
297+
# - a table isn't created lazily if it doesn't exist yet
298+
#
251299
# @param model_class [Class] a model class which should be instantiated
252300
# @param attributes [Hash|Array<Hash>] attributes of a model
253301
# @param block [Proc] a block to process a model after initialization
@@ -287,6 +335,20 @@ def create!(model_class, attributes = {}, &block)
287335
#
288336
# Validates model and runs callbacks.
289337
#
338+
# Raises +Dynamoid::Errors::MissingRangeKey+ if a sort key is required but
339+
# not specified or has value +nil+.
340+
#
341+
# There are the following differences between transactional and
342+
# non-transactional +#create+:
343+
# - transactional +#create+ doesn't support +lock_version+ attribute so it
344+
# will not be incremented and will not be checked to detect concurrent
345+
# modification of a model and +Dynamoid::Errors::StaleObjectError+
346+
# exception will not be raised
347+
# - transactional +#create+ doesn't raise +Dynamoid::Errors::RecordNotUnique+
348+
# at saving new model when primary key is already used. A generic
349+
# +Aws::DynamoDB::Errors::TransactionCanceledException+ is raised instead.
350+
# - a table isn't created lazily if it doesn't exist yet
351+
#
290352
# @param model_class [Class] a model class which should be instantiated
291353
# @param attributes [Hash|Array<Hash>] attributes of a model
292354
# @param block [Proc] a block to process a model after initialization
@@ -322,6 +384,17 @@ def create(model_class, attributes = {}, &block)
322384
# Raises a +Dynamoid::Errors::UnknownAttribute+ exception if any of the
323385
# attributes is not declared in the model class.
324386
#
387+
# Raises +Dynamoid::Errors::MissingHashKey+ if a partition key has value
388+
# +nil+ and +Dynamoid::Errors::MissingRangeKey+ if a sort key is required
389+
# but has value +nil+.
390+
#
391+
# There are the following differences between transactional and
392+
# non-transactional +#upsert+:
393+
# - transactional +#upsert+ doesn't support conditions (that's +if+ and
394+
# +unless_exists+ options)
395+
# - transactional +#upsert+ doesn't return a document that was updated or
396+
# created
397+
#
325398
# @param model_class [Class] a model class
326399
# @param hash_key [Scalar value] hash key value
327400
# @param range_key [Scalar value] range key value (optional)
@@ -395,6 +468,17 @@ def upsert(model_class, hash_key, range_key = nil, attributes) # rubocop:disable
395468
# Raises a +Dynamoid::Errors::UnknownAttribute+ exception if any of the
396469
# attributes is not declared in the model class.
397470
#
471+
# Raises +Dynamoid::Errors::MissingHashKey+ if a partition key has value
472+
# +nil+ and +Dynamoid::Errors::MissingRangeKey+ if a sort key is required
473+
# but has value +nil+.
474+
#
475+
# There are the following differences between transactional and
476+
# non-transactional +#update_fields+:
477+
# - transactional +#update_fields+ doesn't support conditions (that's +if+
478+
# and +unless_exists+ options)
479+
# - transactional +#update_fields+ doesn't return a document that was
480+
# updated or created
481+
#
398482
# @param model_class [Class] a model class
399483
# @param hash_key [Scalar value] hash key value
400484
# @param range_key [Scalar value] range key value (optional)
@@ -420,6 +504,18 @@ def update_fields(model_class, hash_key, range_key = nil, attributes = nil, &blo
420504
# Returns +true+ if saving is successful and +false+
421505
# otherwise.
422506
#
507+
# Raises +Dynamoid::Errors::MissingHashKey+ if a partition key has value
508+
# +nil+ and raises +Dynamoid::Errors::MissingRangeKey+ if a sort key is
509+
# required but has value +nil+.
510+
#
511+
# There are the following differences between transactional and
512+
# non-transactional +#update_attributes+:
513+
# - transactional +#update_attributes+ doesn't support +lock_version+ attribute so it
514+
# will not be incremented and will not be checked to detect concurrent
515+
# modification of a model and +Dynamoid::Errors::StaleObjectError+
516+
# exception will not be raised
517+
# - a table isn't created lazily if it doesn't exist yet
518+
#
423519
# @param model [Dynamoid::Document] a model
424520
# @param attributes [Hash] a hash of attributes to update
425521
# @return [true|false] Whether updating successful or not
@@ -440,6 +536,18 @@ def update_attributes(model, attributes)
440536
# Raises a +Dynamoid::Errors::DocumentNotValid+ exception if some vaidation
441537
# fails.
442538
#
539+
# Raises +Dynamoid::Errors::MissingHashKey+ if a partition key has value
540+
# +nil+ and raises +Dynamoid::Errors::MissingRangeKey+ if a sort key is
541+
# required but has value +nil+.
542+
#
543+
# There are the following differences between transactional and
544+
# non-transactional +#update_attributes!+:
545+
# - transactional +#update_attributes!+ doesn't support +lock_version+
546+
# attribute so it will not be incremented and will not be checked to detect
547+
# concurrent modification of a model and
548+
# +Dynamoid::Errors::StaleObjectError+ exception will not be raised
549+
# - a table isn't created lazily if it doesn't exist yet
550+
#
443551
# @param model [Dynamoid::Document] a model
444552
# @param attributes [Hash] a hash of attributes to update
445553
def update_attributes!(model, attributes)
@@ -461,7 +569,18 @@ def update_attributes!(model, attributes)
461569
# t.delete(User, user_id)
462570
# end
463571
#
464-
# Raise +MissingRangeKey+ if a range key is declared but not passed as argument.
572+
# Raises +Dynamoid::Errors::MissingHashKey+ if a partition key has value
573+
# +nil+ and raises +Dynamoid::Errors::MissingRangeKey+ if a sort key is
574+
# required but has value +nil+.
575+
#
576+
# There are the following differences between transactional and
577+
# non-transactional +#delete+: TBD
578+
# - transactional +#delete+ doesn't support +lock_version+ attribute so it
579+
# will not be incremented and will not be checked to detect concurrent
580+
# modification of a model and +Dynamoid::Errors::StaleObjectError+
581+
# exception will not be raised
582+
# - transactional +#delete+ doesn't disassociate a model from associated ones
583+
# if there is any
465584
#
466585
# @param model_or_model_class [Class|Dynamoid::Document] either model or model class
467586
# @param hash_key [Scalar value] hash key value
@@ -483,6 +602,19 @@ def delete(model_or_model_class, hash_key = nil, range_key = nil)
483602
# Raises +Dynamoid::Errors::RecordNotDestroyed+ exception if model deleting
484603
# failed (e.g. aborted by a callback).
485604
#
605+
# Raises +Dynamoid::Errors::MissingHashKey+ if a partition key has value
606+
# +nil+ and raises +Dynamoid::Errors::MissingRangeKey+ if a sort key is
607+
# required but has value +nil+.
608+
#
609+
# There are the following differences between transactional and
610+
# non-transactional +#destroy!+:
611+
# - transactional +#destroy!+ doesn't support +lock_version+ attribute so it
612+
# will not be incremented and will not be checked to detect concurrent
613+
# modification of a model and +Dynamoid::Errors::StaleObjectError+
614+
# exception will not be raised
615+
# - transactional +#destroy!+ doesn't disassociate a model from associated ones
616+
# if there are association declared in the model class
617+
#
486618
# @param model [Dynamoid::Document] a model
487619
# @return [Dynamoid::Document|false] returns self if destoying is succefull, +false+ otherwise
488620
def destroy!(model)
@@ -494,6 +626,19 @@ def destroy!(model)
494626
#
495627
# Runs callbacks.
496628
#
629+
# Raises +Dynamoid::Errors::MissingHashKey+ if a partition key has value
630+
# +nil+ and raises +Dynamoid::Errors::MissingRangeKey+ if a sort key is
631+
# required but has value +nil+.
632+
#
633+
# There are the following differences between transactional and
634+
# non-transactional +#destroy+:
635+
# - transactional +#destroy+ doesn't support +lock_version+ attribute so it
636+
# will not be incremented and will not be checked to detect concurrent
637+
# modification of a model and +Dynamoid::Errors::StaleObjectError+
638+
# exception will not be raised
639+
# - transactional +#destroy+ doesn't disassociate a model from associated ones
640+
# if there are association declared in the model class
641+
#
497642
# @param model [Dynamoid::Document] a model
498643
# @return [Dynamoid::Document] self
499644
def destroy(model)

0 commit comments

Comments
 (0)