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
Copy file name to clipboardExpand all lines: CHANGELOG.md
+4Lines changed: 4 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
5
5
The format is based on [Keep a Changelog](http://keepachangelog.com/)
6
6
and this project adheres to [Semantic Versioning](http://semver.org/).
7
7
8
+
## 1.1.0 - 2018-03-08
9
+
10
+
* Add multi-key indexing. Multi-key reducers can return an array of keys to index per `put`, `del`, or `batch`. Thanks [@louiscenter](https://github.com/louiscenter) and [@substack](https://github.com/substack) for the idea.
11
+
8
12
## 1.0.5
9
13
10
14
* Fix index cleaning bug. Indexes should now clean up missing lookups.
posts.byTag=AutoIndex(posts, idx.tag, function (post) {
50
+
if (!post ||!post.tags||!Array.isArray(post.tags)) return
51
+
returnpost.tags.map(function (tag) {
52
+
return [tag, post.id].join('!')
53
+
})
54
+
}, { multi:true })
55
+
47
56
posts.put('1337', {
48
57
id:'1337',
49
58
title:'a title',
50
-
body:'lorem ipsum'
59
+
body:'lorem ipsum',
60
+
tags: [ 'foo', 'bar', 'baz' ]
51
61
}, function (err) {
52
62
if (err) throw err
53
63
@@ -87,7 +97,7 @@ posts.put('1337', {
87
97
88
98
## API
89
99
90
-
### AutoIndex(db, idb, reduce)
100
+
### AutoIndex(db, idb, reduce, opts)
91
101
92
102
Automatically index a `db` level into the `idb` level using a `reduce` function that creates the index key. The `db` and `idb` levels should be in isolated key namespaces, either by being two different levels or [`mafintosh/subleveldown`](https://github.com/mafintosh/subleveldown) partitions. The `db` hook is mutated by [`hypermodules/level-hookdown`](https://github.com/hypermodules/level-hookdown) to set up the prehooks used for indexing. Only `db` keys are stored as values to save space and reduce data redundancy.
93
103
@@ -102,6 +112,16 @@ function reducer (value) {
102
112
}
103
113
```
104
114
115
+
Available opts:
116
+
117
+
```js
118
+
{
119
+
multi:false// Reducer returns an array of keys to associate with the primary key
120
+
}
121
+
```
122
+
123
+
Multi-key index's are for when you you want to write multiple index entries into an index. This is useful for 'tag' fields, where a document may have `n` tags per document, and you would like to index documents by 'tag'. When creating a multi-key index, your reducer must return an array of keys to index by.
124
+
105
125
### AutoIndex#get(key, opts, cb)
106
126
107
127
Get the value that has been indexed with `key`.
@@ -129,6 +149,20 @@ function keyReducer (reducerString) {
129
149
130
150
For a higher level api for creating secondary indexes see [hypermodules/level-idx](https://github.com/hypermodules/level-idx).
131
151
152
+
### AutoIndex.keyReducer(string)
153
+
154
+
A shortcut reducer for simplistic multi-key indexing. You might need more than this.
0 commit comments