Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save stefl/955469 to your computer and use it in GitHub Desktop.
Save stefl/955469 to your computer and use it in GitHub Desktop.
Nested postgres transactions in datamapper?
#untested - does this work?
module DataMapper
class Transaction
module DataObjectsAdapter
def nested_transaction_primitive
DataObjects::SavePoint.create_for_uri(normalized_uri, current_connection)
end
end
# Override to use savepoints for nested transactions
def connect_adapter(adapter)
if @transaction_primitives.key?(adapter)
raise "Already a primitive for adapter #{adapter}"
end
primitive = if adapter.current_transaction
self.state = :none
adapter.nested_transaction_primitive
else
adapter.transaction_primitive
end
@transaction_primitives[adapter] = validate_primitive(primitive)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment