Skip to content
This repository has been archived by the owner on Mar 23, 2023. It is now read-only.

Commit

Permalink
fix: key handling
Browse files Browse the repository at this point in the history
  • Loading branch information
dignifiedquire committed Mar 15, 2017
1 parent c1f1dce commit 682f8b3
Show file tree
Hide file tree
Showing 10 changed files with 462 additions and 82 deletions.
13 changes: 8 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "datastore-level",
"version": "1.0.0",
"version": "0.0.1",
"description": "Datastore implementation with level(up|down) backend",
"main": "src/index.js",
"scripts": {
Expand All @@ -10,11 +10,12 @@
"flow": "flow",
"test:node": "aegir-test --env node",
"test:browser": "aegir-test --env browser",
"release": "aegir-release",
"release-minor": "aegir-release --type minor",
"release-major": "aegir-release --type major",
"release": "aegir-release --docs",
"release-minor": "aegir-release --type minor --docs",
"release-major": "aegir-release --type major --docs",
"coverage": "aegir-coverage",
"coverage-publish": "aegir-coverage publish"
"coverage-publish": "aegir-coverage publish",
"docs": "aegir-docs"
},
"repository": {
"type": "git",
Expand All @@ -36,6 +37,8 @@
},
"homepage": "https://github.com/ipfs/js-datastore-level#readme",
"dependencies": {
"datastore-core": "^0.1.0",
"interface-datastore": "^0.1.1",
"level-js": "^2.2.4",
"leveldown": "^1.6.0",
"levelup": "^1.3.5",
Expand Down
13 changes: 6 additions & 7 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,20 @@ class LevelDatastore {
this.db = levelup(path, Object.assign({}, {
compression: false // same default as go
}, opts, {
keyEncoding: 'binary',
valueEncoding: 'binary'
}))
}

put (key /* : Key */, value /* : Buffer */, callback /* : Callback<void> */) /* : void */ {
this.db.put(key.toBuffer(), value, callback)
this.db.put(key.toString(), value, callback)
}

get (key /* : Key */, callback /* : Callback<Buffer> */) /* : void */ {
this.db.get(key.toBuffer(), callback)
this.db.get(key.toString(), callback)
}

has (key /* : Key */, callback /* : Callback<bool> */) /* : void */ {
this.db.get(key.toBuffer(), (err, res) => {
this.db.get(key.toString(), (err, res) => {
if (err) {
if (err.notFound) {
callback(null, false)
Expand All @@ -56,7 +55,7 @@ class LevelDatastore {
}

delete (key /* : Key */, callback /* : Callback<void> */) /* : void */ {
this.db.del(key.toBuffer(), callback)
this.db.del(key.toString(), callback)
}

close (callback /* : Callback<void> */) /* : void */ {
Expand All @@ -69,14 +68,14 @@ class LevelDatastore {
put: (key /* : Key */, value /* : Buffer */) /* : void */ => {
ops.push({
type: 'put',
key: key.toBuffer(),
key: key.toString(),
value: value
})
},
delete: (key /* : Key */) /* : void */ => {
ops.push({
type: 'del',
key: key.toBuffer()
key: key.toString()
})
},
commit: (callback /* : Callback<void> */) /* : void */ => {
Expand Down
6 changes: 3 additions & 3 deletions test/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
'use strict'

const each = require('async/each')
const MountStore = require('interface-datastore').MountDatastore
const MountStore = require('datastore-core').MountDatastore
const Key = require('interface-datastore').Key
const leveljs = require('level-js')

const LevelStore = require('../src')

describe('LevelDatastore', () => {
describe('interface-datastore (leveljs)', () => {
require('interface-datastore/test/interface')({
require('interface-datastore/src/tests')({
setup (callback) {
callback(null, new LevelStore('hello', {db: leveljs}))
},
Expand All @@ -22,7 +22,7 @@ describe('LevelDatastore', () => {
})

describe('interface-datastore (mount(leveljs, leveljs, leveljs))', () => {
require('interface-datastore/test/interface')({
require('interface-datastore/src/tests')({
setup (callback) {
callback(null, new MountStore([{
prefix: new Key('/a'),
Expand Down
2 changes: 1 addition & 1 deletion test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const LevelStore = require('../src')

describe('LevelDatastore', () => {
describe('interface-datastore (memdown)', () => {
require('interface-datastore/test/interface')({
require('interface-datastore/src/tests')({
setup (callback) {
callback(null, new LevelStore('hello', {db: memdown}))
},
Expand Down
6 changes: 3 additions & 3 deletions test/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const path = require('path')
const utils = require('interface-datastore').utils
const rimraf = require('rimraf')
const each = require('async/each')
const MountStore = require('interface-datastore').MountDatastore
const MountStore = require('datastore-core').MountDatastore
const Key = require('interface-datastore').Key
const expect = require('chai').expect
const CID = require('cids')
Expand All @@ -17,7 +17,7 @@ const LevelStore = require('../src')
describe('LevelDatastore', () => {
describe('interface-datastore (leveldown)', () => {
const dir = utils.tmpdir()
require('interface-datastore/test/interface')({
require('interface-datastore/src/tests')({
setup (callback) {
callback(null, new LevelStore(dir))
},
Expand All @@ -33,7 +33,7 @@ describe('LevelDatastore', () => {
utils.tmpdir(),
utils.tmpdir()
]
require('interface-datastore/test/interface')({
require('interface-datastore/src/tests')({
setup (callback) {
callback(null, new MountStore([{
prefix: new Key('/a'),
Expand Down
2 changes: 1 addition & 1 deletion test/test-repo/datastore/CURRENT
Original file line number Diff line number Diff line change
@@ -1 +1 @@
MANIFEST-000036
MANIFEST-000054
6 changes: 3 additions & 3 deletions test/test-repo/datastore/LOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
2017/03/13-13:52:56.574311 70000f009000 Recovering log #35
2017/03/13-13:52:56.575960 70000f009000 Delete type=0 #35
2017/03/13-13:52:56.576081 70000f009000 Delete type=3 #34
2017/03/15-14:58:36.441989 70000b29f000 Recovering log #53
2017/03/15-14:58:36.443168 70000b29f000 Delete type=0 #53
2017/03/15-14:58:36.443262 70000b29f000 Delete type=3 #52
6 changes: 3 additions & 3 deletions test/test-repo/datastore/LOG.old
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
2017/03/13-13:52:16.502220 70000f6c7000 Recovering log #33
2017/03/13-13:52:16.503900 70000f6c7000 Delete type=0 #33
2017/03/13-13:52:16.504085 70000f6c7000 Delete type=3 #32
2017/03/15-14:57:31.986982 700010d11000 Recovering log #51
2017/03/15-14:57:31.990378 700010d11000 Delete type=0 #51
2017/03/15-14:57:31.990492 700010d11000 Delete type=3 #50
Binary file not shown.
Loading

0 comments on commit 682f8b3

Please sign in to comment.