Skip to content

Commit

Permalink
Store an optional value on deletions.
Browse files Browse the repository at this point in the history
  • Loading branch information
hackergrrl committed Feb 19, 2017
1 parent 650bb4f commit 971adf8
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ function DB (opts) {
map: function (row, next) {
if (!row.value) return null
var v = row.value.v, d = row.value.d
if (v && v.lat !== undefined && v.lon !== undefined) {
var k = row.value.k
if (k && v.lat !== undefined && v.lon !== undefined) {
next(null, { type: 'put', point: ptf(v) })
} else if (d && Array.isArray(row.value.points)) {
next(null, { type: 'del', points: row.value.points.map(ptf) })
Expand Down Expand Up @@ -166,6 +167,7 @@ DB.prototype.del = function (key, opts, cb) {
cb = once(cb || noop)
self._del(key, opts, function (err, rows) {
if (err) return cb(err)

self.batch(rows, opts, function (err, nodes) {
if (err) cb(err)
else cb(null, nodes[0])
Expand Down Expand Up @@ -198,6 +200,14 @@ DB.prototype._del = function (key, opts, cb) {
fields.refs.push.apply(fields.refs, v.refs)
}
})

// Use opts.value to set a value on hyperkv deletions.
if (opts.value) {
fields = xtend(fields, {
v: opts.value
})
}

cb(null, [ { type: 'del', key: key, links: links, fields: fields } ])
})
}
Expand Down

0 comments on commit 971adf8

Please sign in to comment.