Skip to content
This repository was archived by the owner on Sep 9, 2021. It is now read-only.

Commit f58a9b2

Browse files
committed
moved out memds
1 parent b4211a8 commit f58a9b2

File tree

4 files changed

+45
-121
lines changed

4 files changed

+45
-121
lines changed

README.md

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@ Note: this is similar to [rvagg/abstract-leveldown](https://github.com/rvagg/abs
1010

1111
## Example
1212

13-
See [try.js](try.js)
13+
### Usage
14+
15+
See [datastore.memory/try.js](https://github.com/jbenet/datastore.memory/blob/master/try.js):
1416

1517
```js
16-
var memDS = require('datastore.abstract/memds')
18+
var memDS = require('datastore.memory')
1719
ds.put('foo', 'bar', function(err, val, key) {
1820
if (err) throw err
1921
console.log('put ' + key + ': ' + val)
@@ -44,6 +46,47 @@ ds.has('foo', function(err, has, key) {
4446
})
4547
```
4648

49+
### Implementation
50+
51+
See [datastore.memory/index.js](https://github.com/jbenet/datastore.memory/blob/master/index.js):
52+
53+
```js
54+
var DS = require('datastore.abstract')
55+
56+
module.exports = MemDS
57+
58+
function MemDS() {
59+
if (!(this instanceof MemDS))
60+
return new MemDS
61+
DS.call(this)
62+
this.values = {}
63+
}
64+
65+
DS.inherits(MemDS)
66+
67+
MemDS.prototype._get = function(key, cb) {
68+
var val = this.values[key.toString()]
69+
if (val !== undefined) cb(null, val, key)
70+
else cb(MemDS.errors.NotFound, null, key)
71+
}
72+
73+
MemDS.prototype._put = function(key, val, cb) {
74+
this.values[key.toString()] = val
75+
cb(null, val, key)
76+
}
77+
78+
MemDS.prototype._delete = function(key, cb) {
79+
delete this.values[key.toString()]
80+
cb(null, key)
81+
}
82+
83+
MemDS.prototype._has = function(key, cb) {
84+
var has = (this.values[key.toString()] !== undefined)
85+
cb(null, has, key)
86+
}
87+
```
88+
89+
4790
## License
4891

4992
MIT

memds.js

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

test.js

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

try.js

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

0 commit comments

Comments
 (0)