Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds postopen, prewrite and newsub hooks that allow userland "hook functions" to customize behavior of the database. See README for details. A quick example: ```js db.hooks.prewrite.add(function (op, batch) { if (op.type === 'put') { batch.add({ type: 'put', key: op.value.foo, value: op.key, sublevel: fooIndex }) } }) ``` More generally, this is a move towards "renewed modularity". Our ecosystem is old and many modules no longer work because they had no choice but to monkeypatch database methods, of which the signature has changed since then. So in addition to hooks, this: - Introduces a new `write` event that is emitted on `db.batch()`, `db.put()` and `db.del()` and has richer data: userland options, encoded data, keyEncoding and valueEncoding. The `batch`, `put` and `del` events are now deprecated and will be removed in a future version. Related to Level/level#222. - Restores support of userland options on batch operations. In particular, to copy options in `db.batch(ops, options)` to ops, allowing for code like `db.batch(ops, { ttl: 123 })` to apply a default userland `ttl` option to all ops. No breaking changes, yet. Using hooks means opting-in to new behaviors (like the new write event) and disables some old behaviors (like the deprecated events). Later on we can make those the default behavior, regardless of whether hooks are used. TODO: benchmarks, tests and optionally some light refactoring. Closes Level/community#44.
- Loading branch information