baslr / arangochair

🥑 arangochair is a Node.js module that adds changefeed capability to ArangoDB and make it realtime push ready
91 stars 18 forks source link

Differenciate insert and update events #10

Open matcho opened 6 years ago

matcho commented 6 years ago

Hello,

We're currently using arangochair (@voondo 's fork in fact, because of authentication issues) and are rather happy with it ! Nevertheless, it would be great to be able to subscribe to insert and update events separately.

This page says that "Separate events for insert and update are currently not possible but will be part of a future update."

Any roadmap for this please ?

Thanks

yerboogieman commented 5 years ago

I have been going through the arangochair code to see how it works and I think I see how it's possible to do this. If you look at the code inside index.js, you will see that it is polling the database change log every second or so by making a call to the logger-follow REST API endpoint. If you call this API within a REST client like Postman, or some such, you will see that inserts generally have a transaction ID (tid) of "0" and updates generally have a tid > 0. I can see how I could probably make this change seamlessly and I'm considering creating a pull request to add this functionality, but I'm posting the comment here first just in case the author has any advice to tell me that things are not as I have stated them herein.

yerboogieman commented 5 years ago

Okay, I have now completed the aforementioned enhancement and created a pull request.

So now, instead of:

// explicit no4.subscribe({collection:'users', events:['insert/update', 'delete']});

You can listen for 'insert' and 'update' changes separately, as in:

// explicit no4.subscribe({collection:'users', events:['insert', 'update', 'delete']});

or just:

// subscribe to all events in the users collection no4.subscribe('users');

I also fixed some field parsing bugs I found. If you want to use the enhancement before the pull request gets merged, just go grab it from my forked arangochair project:

https://github.com/yerboogieman/arangochair

Cheers!