Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add hooks and deprecate batch, put & del events #45

Merged
merged 15 commits into from
Nov 5, 2022
Merged

Add hooks and deprecate batch, put & del events #45

merged 15 commits into from
Nov 5, 2022

Commits on Oct 30, 2022

  1. Add hooks

    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.
    vweevers committed Oct 30, 2022
    Configuration menu
    Copy the full SHA
    80e98c0 View commit details
    Browse the repository at this point in the history

Commits on Nov 1, 2022

  1. Configuration menu
    Copy the full SHA
    75c75e2 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    b2ac91f View commit details
    Browse the repository at this point in the history

Commits on Nov 2, 2022

  1. Configuration menu
    Copy the full SHA
    abafd87 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    ab8b7fb View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    141da9e View commit details
    Browse the repository at this point in the history
  4. Add more prewrite tests

    vweevers committed Nov 2, 2022
    Configuration menu
    Copy the full SHA
    59ed91f View commit details
    Browse the repository at this point in the history

Commits on Nov 3, 2022

  1. Add more write event tests

    vweevers committed Nov 3, 2022
    Configuration menu
    Copy the full SHA
    9036d3f View commit details
    Browse the repository at this point in the history
  2. Add postopen tests

    vweevers committed Nov 3, 2022
    Configuration menu
    Copy the full SHA
    0e2aacb View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    0fdfb67 View commit details
    Browse the repository at this point in the history
  4. Add more prewrite tests

    And simplify existing tests by first checking when the hook function
    is called, i.e. after db has opened.
    vweevers committed Nov 3, 2022
    Configuration menu
    Copy the full SHA
    94279fb View commit details
    Browse the repository at this point in the history
  5. Add newsub test

    vweevers committed Nov 3, 2022
    Configuration menu
    Copy the full SHA
    58239b0 View commit details
    Browse the repository at this point in the history

Commits on Nov 5, 2022

  1. Configuration menu
    Copy the full SHA
    712c990 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    aa9bdab View commit details
    Browse the repository at this point in the history
  3. Fix typos and grammar

    vweevers committed Nov 5, 2022
    Configuration menu
    Copy the full SHA
    88c3861 View commit details
    Browse the repository at this point in the history