Add write transaction
Add transaction write feature to DynamoId.
- Currently only works for adding multiple write operations
Looks pretty good 👍 .
The only issue I see is that transact method works just for the one model/table but DynamoDB's transaction can involve different tables in one call. I would like to have only one flexible API for write transactions. That's why I would like transact to work with several tables.
The only reason why transactions aren't added yet is that I am not sure what API should be.
I have following thoughts:
- API should be high-level and operate model classes instead of table names
- operations are hight-level and names match already existing methods like
update_attributes/update_fields/upsert/... - callbacks should be called, at least some of them (e.g. for creation/deletion)
I considered following interface:
# Dyhamoid::Document.transaction or User.transaction
Dynamoid::Document.transaction do |txn|
txn.create(User, attributes)
txn.update(User, attributes)
txn.update_fields(User, attributes, conditions)
txn.upsert(User, attributes)
txn.delete(User, id)
end
So please let me know what do you think about it.
Looks pretty good 👍 .
The only issue I see is that
transactmethod works just for the one model/table but DynamoDB's transaction can involve different tables in one call. I would like to have only one flexible API for write transactions. That's why I would liketransactto work with several tables.The only reason why transactions aren't added yet is that I am not sure what API should be.
I have following thoughts:
- API should be high-level and operate model classes instead of table names
- operations are hight-level and names match already existing methods like
update_attributes/update_fields/upsert/...- callbacks should be called, at least some of them (e.g. for creation/deletion)
I considered following interface:
# Dyhamoid::Document.transaction or User.transaction Dynamoid::Document.transaction do |txn| txn.create(User, attributes) txn.update(User, attributes) txn.update_fields(User, attributes, conditions) txn.upsert(User, attributes) txn.delete(User, id) end So please let me know what do you think about it.
Hey thanks for the response. I admit i did this PR with a specific business case in mind. I like your suggestion for the new api design. Will work on it over the next few days.
Great.
I believe that proposed above approach isn't as good and consistent as it could be so there is room for improvement. For instance txn.create(User, attributes) seems ugly to me but I don't see better alternative.
@andrykonchin what's the status on transact write support, is it planned? any help needed?
Transactions aren't supported right now. The main issue is that it isn't clear to me how the transactions API should look. Any opinion/proposition is welcomed.
Have there been any more thoughts on this? Below is an alternate API idea using an array of arrays. An array of hashes could work too. Personally I prefer single table usage of DynamoDB so don't have a need to span tables but I see why it should be supported.
Dynamoid::Document.transaction([
[User, :create, attributes],
[User, :update, attributes],
[User, :update_fields, attributes, conditions],
[User, :upsert, attributes],
[User, :delete, id]
])