thenativeweb / node-cqrs-eventdenormalizer

Node-cqrs-eventdenormalizer is a node.js module that implements the cqrs pattern. It can be very useful as eventdenormalizer component if you work with (d)ddd, cqrs, domain, host, etc.
http://cqrs.js.org/pages/eventdenormalizer.html
MIT License
38 stars 27 forks source link

Create a custom repository to store data into a relational database #57

Open Heucles opened 7 years ago

Heucles commented 7 years ago

I am having some trouble placing a custom repository wiich would store data in a relational database which for the purposes of my system I have to keep updated the same way that I want to maintain the "mongo" repository updated, the best place for it to be set should be at the viewBuilder, using the callback?

Something like that?

module.exports = require('cqrs-eventdenormalizer').defineViewBuilder({
  name: 'itemCreated',
  id: 'payload.id'
}, function (data, vm, callback) {
  // assync logic to record data elsewhere
  //updating mongo database
  vm.set(data);

  recordOnRelationalDatabase(data).then(function (recordedData) {
    //...
    return callback();
  }),catch(function(err) {
    callback(err)
  });
});
nanov commented 7 years ago

vm.set is not updating the database ( still ), just the viewmodel object, the database is updated on commit internally.

Do you want to maintain two databases with exactly the same data ( RDBMS and NoSQL ), or just a RDBMS one?

For RDMS databases, one will have to write an own DB implementation for the wanted database like those here, for maintaining both you might want to write an implementation that does that internally, or run two denormalizers, one for each database ( again after having some RDBMS implementation ).

May I ask why would you want two databases with exactly the same viewmodel data, and why would you store such data in a relational database?