|
1 | 1 | var level = require('level')
|
2 |
| -var hypercore = require('hypercore') |
3 |
| -var createImportPipeline = require('./lib/import.js') |
| 2 | + |
| 3 | +var hyperkv = require('hyperkv') |
| 4 | +var hyperlog = require('hyperlog') |
| 5 | +var sub = require('subleveldown') |
| 6 | + |
| 7 | +// var createImportPipeline = require('./lib/import.js') |
| 8 | +var addRow = require('./lib/add.js') |
| 9 | +var deleteRow = require('./lib/delete.js') |
4 | 10 |
|
5 | 11 | module.exports = Jawn
|
6 | 12 |
|
7 | 13 | function Jawn (opts) {
|
8 | 14 | if (!opts) opts = {}
|
9 |
| - this.core = initializeHypercore(opts) |
| 15 | + this.core = initializeHyperkv(opts) |
10 | 16 | this.db = this.core.db
|
11 | 17 | }
|
12 | 18 |
|
| 19 | +/* |
13 | 20 | Jawn.prototype.createImportPipeline = function (opts) {
|
14 | 21 | return createImportPipeline(this, opts)
|
15 | 22 | }
|
| 23 | +*/ |
| 24 | + |
| 25 | +Jawn.prototype.addRow = function (value, key) { |
| 26 | + return addRow(this, value, key) |
| 27 | +} |
| 28 | + |
| 29 | +Jawn.prototype.deleteRow = function (key) { |
| 30 | + return deleteRow(this, key) |
| 31 | +} |
16 | 32 |
|
17 | 33 | // Initializes hypercore and its database
|
18 | 34 | // @default Creates a leveldb database called `data.jawn` and initializes hypercore using that db
|
19 | 35 | // @option 'core' the hypercore instance to use
|
20 | 36 | // @option 'db' the db instace (leveldb) to initialize hypercore with. This is ignored if you use the `core` option
|
21 |
| -function initializeHypercore (opts) { |
| 37 | +function initializeHyperkv (opts) { |
22 | 38 | var core
|
23 | 39 | if (opts.hasOwnProperty('core')) {
|
24 | 40 | core = opts.core
|
25 | 41 | } else {
|
26 | 42 | var db = opts.db || level('data.jawn')
|
27 |
| - core = hypercore(db) |
| 43 | + core = hyperkv({ |
| 44 | + log: hyperlog(sub(db, 'log'), { valueEncoding: 'json' }), |
| 45 | + db: sub(db, 'kv') |
| 46 | + }) |
28 | 47 | }
|
29 | 48 | return core
|
30 | 49 | }
|
0 commit comments