You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Dec 2, 2024. It is now read-only.
Copy file name to clipboardexpand all lines: README.md
+7-6
Original file line number
Diff line number
Diff line change
@@ -40,31 +40,32 @@ Your data is discarded when the process ends or you release a reference to the s
40
40
41
41
## Data types
42
42
43
-
Unlike [`leveldown`], `memdown` does not stringify keys or values. This means that in addition to Buffers, you can store any JS type without the need for [`encoding-down`]. For keys for example, you could use Buffers or strings, which sort lexicographically, or numbers, even Dates, which sort naturally. The only exceptions are `null` and `undefined`. Keys and values of that type are rejected.
43
+
Keys can be strings or Buffers. Any other key type will be irreversibly stringified. Unlike [`leveldown`] though, `memdown` does not stringify values. This means that in addition to Buffers, you can store any JS value without the need for [`encoding-down`]. The only exceptions are `null` and `undefined`. Keys and values of that type are rejected.
44
44
45
45
```js
46
46
constdb=levelup(memdown())
47
47
48
-
db.put(12, true, (err) => {
48
+
db.put('example', 123, (err) => {
49
49
if (err) throw err
50
50
51
51
db.createReadStream({
52
52
keyAsBuffer:false,
53
53
valueAsBuffer:false
54
54
}).on('data', (entry) => {
55
-
console.log(typeofentry.key) // 'number'
56
-
console.log(typeofentry.value) // 'boolean'
55
+
console.log(typeofentry.key) // 'string'
56
+
console.log(typeofentry.value) // 'number'
57
57
})
58
58
})
59
59
```
60
60
61
-
If you desire normalization for keys and values (e.g. to stringify numbers), wrap `memdown` with [`encoding-down`]. Alternatively install [`level-mem`] which conveniently bundles [`levelup`], `memdown` and [`encoding-down`]. Such an approach is also recommended if you want to achieve universal (isomorphic) behavior. For example, you could have [`leveldown`] in a backend and `memdown` in the frontend.
61
+
If you desire normalization for values (e.g. to stringify numbers), wrap `memdown` with [`encoding-down`]. Alternatively install [`level-mem`] which conveniently bundles [`levelup`], `memdown` and [`encoding-down`]. Such an approach is also recommended if you want to achieve universal (isomorphic) behavior. For example, you could have [`leveldown`] in a backend and `memdown` in the frontend.
62
62
63
63
```js
64
64
constencode=require('encoding-down')
65
65
constdb=levelup(encode(memdown()))
66
66
67
-
db.put(12, true, (err) => {
67
+
// The default value encoding is utf8, which stringifies input.
Copy file name to clipboardexpand all lines: UPGRADING.md
+4
Original file line number
Diff line number
Diff line change
@@ -2,6 +2,10 @@
2
2
3
3
This document describes breaking changes and how to upgrade. For a complete list of changes including minor and patch releases, please refer to the [`CHANGELOG`][changelog].
4
4
5
+
## v5 (unreleased)
6
+
7
+
Support of keys other than strings and Buffers has been dropped. Internally `memdown` now stores keys as Buffers which solves a number of compatibility issues ([#186](https://github.com/Level/memdown/issues/186)). If you pass in a key that isn't a string or Buffer, it will be irreversibly stringified.
8
+
5
9
## v4
6
10
7
11
This is an upgrade to `abstract-leveldown@6` which solves long-standing issues around serialization and type support.
0 commit comments