Skip to content

Commit 86e6cd9

Browse files
committed
Add add.js to lib
1 parent f1bdb49 commit 86e6cd9

File tree

5 files changed

+16
-65
lines changed

5 files changed

+16
-65
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
tmp
22
node_modules
33
data.jawn
4-
hyperkv-examples.js
4+
npm-debug.log

index.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ module.exports = Jawn
1212

1313
function Jawn (opts) {
1414
if (!opts) opts = {}
15-
this.core = initializeHyperkv(opts)
15+
this.kv = initializeHyperkv(opts)
1616
this.db = this.core.db
1717
}
1818

@@ -22,8 +22,8 @@ Jawn.prototype.createImportPipeline = function (opts) {
2222
}
2323
*/
2424

25-
Jawn.prototype.addRow = function (value, key) {
26-
return addRow(this, value, key)
25+
Jawn.prototype.addRow = function (key, value) {
26+
return addRow(this, key, value)
2727
}
2828

2929
Jawn.prototype.deleteRow = function (key) {
@@ -35,15 +35,15 @@ Jawn.prototype.deleteRow = function (key) {
3535
// @option 'core' the hypercore instance to use
3636
// @option 'db' the db instace (leveldb) to initialize hypercore with. This is ignored if you use the `core` option
3737
function initializeHyperkv (opts) {
38-
var core
38+
var kv
3939
if (opts.hasOwnProperty('core')) {
40-
core = opts.core
40+
kv = opts.core
4141
} else {
4242
var db = opts.db || level('data.jawn')
43-
core = hyperkv({
43+
kv = hyperkv({
4444
log: hyperlog(sub(db, 'log'), { valueEncoding: 'json' }),
4545
db: sub(db, 'kv')
4646
})
4747
}
48-
return core
48+
return kv
4949
}

lib/add.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module.exports = addRow
2+
3+
function addRow (jawn, key, value) {
4+
jawn.kv.put(key, JSON.stringify(value), function (err, node) {
5+
if (err) console.error(err)
6+
else console.log(node.key)
7+
})
8+
}

test/add.js

Whitespace-only changes.

test/hyperkv.js

Lines changed: 0 additions & 57 deletions
This file was deleted.

0 commit comments

Comments
 (0)