gsandf / rethinkdb-elasticsearch-stream

🔄 sync RethinkDB tables to Elasticsearch using changefeeds
9 stars 4 forks source link

#31 Adds handling for deleted documents in Rethink #32

Closed sunnyzanchi closed 6 years ago

sunnyzanchi commented 6 years ago

If a document is deleted in Rethink while there's a changefeed watching, it will return:

{
new_val: null,
old_val: { someData... }
}

This isn't particularly useful to our transform function because it would only receive null. This PR updates saveDocument and watchTable so user-specified transform functions now receive document and oldDocument.

This PR also adds the ability to specify a deleteTransform, which runs specifically when new_val is null, meaning a delete took place in Rethink. This is a breaking change. When a deleteTransform is not specified, this library will default to just deleting the document from Elasticsearch, using the id (with respect to the id field) from oldDocument. Previously, the document would've just been passed to transform as null.