-
Notifications
You must be signed in to change notification settings - Fork 31
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
added onlyIfChanged opt #98
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -62,6 +62,7 @@ Make a new Hyperbee instance. `core` should be a [Hypercore](https://github.com/ | |
{ | ||
keyEncoding: 'binary', // "binary" (default), "utf-8", "ascii", "json", or an abstract-encoding | ||
valueEncoding: 'binary' // Same options as keyEncoding like "json", etc | ||
onlyIfChanged: true // put a value only if it means a change in the db | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should say |
||
} | ||
``` | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
const sameData = require('same-data') | ||
const codecs = require('codecs') | ||
const { Readable } = require('streamx') | ||
const mutexify = require('mutexify/promise') | ||
|
@@ -287,6 +288,7 @@ class Hyperbee extends ReadyResource { | |
this.sep = opts.sep || SEP | ||
this.readonly = !!opts.readonly | ||
this.prefix = opts.prefix || null | ||
this.onlyIfChanged = !!opts.onlyIfChanged | ||
|
||
this._unprefixedKeyEncoding = this.keyEncoding | ||
this._sub = !!this.prefix | ||
|
@@ -669,7 +671,7 @@ class Batch { | |
async put (key, value, opts) { | ||
const release = this.batchLock ? await this.batchLock() : null | ||
|
||
const cas = (opts && opts.cas) || null | ||
const cas = (opts && opts.cas) || (this.tree.onlyIfChanged ? sameData : null) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's a tricky one in terms of API. What's the intended behaviour if a user specified ATM it will ignore Also in terms of API: I would also allow passing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I think the intended behavior is that I think There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. API is ok because method option overrides constructor option, just like with Hypercore timeout options, etc |
||
const encoding = this._getEncoding(opts) | ||
|
||
if (!this.locked) await this.lock() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ | |
"protocol-buffers-encodings": "^1.2.0", | ||
"ready-resource": "^1.0.0", | ||
"safety-catch": "^1.0.2", | ||
"same-data": "^1.0.0", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In which case would Just asking because people might use the option to later realize that there are duplicated inserts due |
||
"streamx": "^2.12.4" | ||
}, | ||
"devDependencies": { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alternative name:
changeOnly
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or
casChanges
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the boolean option, but just maybe a different API could be a
cas
option in the constructor, so user can pass its global comparator