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

Improve get_multi interface (breaking change) #10

Merged
merged 1 commit into from
Feb 11, 2020
Merged

Conversation

lucaong
Copy link
Owner

@lucaong lucaong commented Jan 30, 2020

Before, get_multi/3 was returning a list of value corresponding to the
given keys, or the default value when the key was not in the database.

This API had a number of drawbacks, like the difficulty to distinguish
between a missing key from a key associated to the default value, or the
inconvenience of matching keys to values. Also, it is not consistent
with the argument of the function passed to get_and_update_multi.

The new version solves these problems (at the cost of breaking backward
compatibility) by returning a map of keys to values fro the selected
keys. When a key is not present in the database, it is omitted from the
result map.

Example:

CubDB.put_multi(db, a: 1, b: 2, c: nil)

# Before:
CubDB.get_multi(db, [:a, :b, :c, :x])
# => [1, 2, nil, nil]

# Now:
CubDB.get_multi(db, [:a, :b, :c, :x])
# => %{a: 1, b: 2, c: nil}

Before, get_multi/3 was returning a list of value corresponding to the
given keys, or the default value when the key was not in the database.

This API had a number of drawbacks, like the difficulty to distinguish
between a missing key from a key associated to the default value, or the
inconvenience of matching keys to values. Also, it is not consistent
with the argument of the function passed to get_and_update_multi.

The new version solves these problems (at the cost of breaking backward
compatibility) by returning a map of keys to values fro the selected
keys. When a key is not present in the database, it is omitted from the
result map.

Example:

    # Assuming that the database contains a: 1, b: 2, c: nil

    # Before:
    CubDB.get_multi(db, [:a, :b, :c, :x])
    # => [1, 2, nil, nil]

    # Now:
    CubDB.get_multi(db, [:a, :b, :c, :x])
    # => %{a: 1, b: 2, c: nil}
@lucaong lucaong merged commit 82334c1 into master Feb 11, 2020
@lucaong lucaong deleted the better_get_multi branch February 11, 2020 16:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant