{"action":"created","issue":{"url":"https://api.github.com/repos/johnbywater/eventsourcing/issues/27","repository_url":"https://api.github.com/repos/johnbywater/eventsourcing","labels_url":"https://api.github.com/repos/johnbywater/eventsourcing/issues/27/labels{/name}","comments_url":"https://api.github.com/repos/johnbywater/eventsourcing/issues/27/comments","events_url":"https://api.github.com/repos/johnbywater/eventsourcing/issues/27/events","html_url":"https://github.com/johnbywater/eventsourcing/issues/27","id":184537264,"number":27,"title":"storage layer abstraction propose","user":{"login":"renou","id":1410559,"avatar_url":"https://avatars.githubusercontent.com/u/1410559?v=3","gravatar_id":"","url":"https://api.github.com/users/renou","html_url":"https://github.com/renou","followers_url":"https://api.github.com/users/renou/followers","following_url":"https://api.github.com/users/renou/following{/other_user}","gists_url":"https://api.github.com/users/renou/gists{/gist_id}","starred_url":"https://api.github.com/users/renou/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/renou/subscriptions","organizations_url":"https://api.github.com/users/renou/orgs","repos_url":"https://api.github.com/users/renou/repos","events_url":"https://api.github.com/users/renou/events{/privacy}","received_events_url":"https://api.github.com/users/renou/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":4,"created_at":"2016-10-21T17:49:09Z","updated_at":"2016-10-24T13:33:43Z","closed_at":null,"body":"Hi John!\r\n\r\nI'm working on a new storage layer for the library using Django ORM for easy django integration. However, I find it hard to do in the current setup.\r\n\r\nCurrently when we save a domain event we go through DomainEvent -> StoredEvent -> DB implementation. it works great if all DB implementation uses schema that follows StoredEvent schema. However, if I'd like to have a different schema I need to somehow \"deserialize\" back to domain event since many DomainEvent fields are combined into one in StoredEvent.\r\n\r\nMy proposal is to move the abstraction a layer up from StoredEventRepository to EventStore(and maybe rename \"EventStore\" to \"EventRepo\" to follow the repo pattern). And the developer can have the flexibility of transcode the Domain event to whatever schema they like. And the downstream can be the default implementation of the repo.\r\n\r\nThe lib works great in most cases as long as we use it as is and not caring about the actual storage. However, there are cases, we do care about how the data is stored. \r\n\r\nLet me know what you think, thank you!\r\n\r\nHere is an example of the code I have to write to implement a different schema:\r\n```python\r\n    def write_version_and_event(self, new_stored_event, new_entity_version=None, max_retries=3, artificial_failure_rate=0):\r\n        domain_event = self.deserialize(new_stored_event) # :(\r\n        dt = datetime.datetime.fromtimestamp(timestamp_from_uuid(new_stored_event.event_id))\r\n        Event.objects.create(\r\n            event_id=domain_event.event_id,\r\n            event_type=type(domain_event).__name__,\r\n            event_data=new_stored_event.event_attrs,\r\n            aggregate_id=domain_event.entity_id,\r\n            aggregate_type=id_prefix_from_event(domain_event),\r\n            aggregate_version=new_entity_version,\r\n            create_date=make_aware_if_needed(dt),\r\n        )\r\n```\r\n\r\nI think the EventStore is a good line of abstraction. It takes in domain events on write and returns domain events on read.\r\nBo"},"comment":{"url":"https://api.github.com/repos/johnbywater/eventsourcing/issues/comments/255741487","html_url":"https://github.com/johnbywater/eventsourcing/issues/27#issuecomment-255741487","issue_url":"https://api.github.com/repos/johnbywater/eventsourcing/issues/27","id":255741487,"user":{"login":"renou","id":1410559,"avatar_url":"https://avatars.githubusercontent.com/u/1410559?v=3","gravatar_id":"","url":"https://api.github.com/users/renou","html_url":"https://github.com/renou","followers_url":"https://api.github.com/users/renou/followers","following_url":"https://api.github.com/users/renou/following{/other_user}","gists_url":"https://api.github.com/users/renou/gists{/gist_id}","starred_url":"https://api.github.com/users/renou/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/renou/subscriptions","organizations_url":"https://api.github.com/users/renou/orgs","repos_url":"https://api.github.com/users/renou/repos","events_url":"https://api.github.com/users/renou/events{/privacy}","received_events_url":"https://api.github.com/users/renou/received_events","type":"User","site_admin":false},"created_at":"2016-10-24T13:33:43Z","updated_at":"2016-10-24T13:33:43Z","body":"Hi John!\r\n1. Oh, I see. It's not very obvious, may be some explicit abstraction would make it clear to developers?\r\n2. The reason is we are having multiple backends of different languages of event sourced services. We use events for reactive inter-service communication through kafka. It's easier to have a common event \"data structure\" so that all service will understand it. And we have come up with a standard structure that we liked most described in the code I post above.\r\n3. Yes, we are calling eventsourcing application from view classes. What's ur thought on that?"}}
{"actor":{"display_login":"renou"}}