@kedem/okdb 1.1.3 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/docs/http-api.md CHANGED
@@ -449,6 +449,7 @@ DELETE /api/:env/type/:type → drop a type
449
449
 
450
450
  POST /api/:env/type/:type/indexes → register an index
451
451
  DELETE /api/:env/type/:type/index/:idx → drop an index
452
+ GET /api/:env/type/:type/index/:idx/count?start=<json>&end=<json> → count index entries in range
452
453
  ```
453
454
 
454
455
  ---
package/docs/indexes.md CHANGED
@@ -100,6 +100,28 @@ The trailing `null` sentinel in the LMDB key format ensures that a prefix scan o
100
100
 
101
101
  ---
102
102
 
103
+ ## Counting without loading records
104
+
105
+ `countByIndex` counts matching index entries without touching the data store:
106
+
107
+ ```javascript
108
+ await okdb.registerIndex('orders', ['status']);
109
+
110
+ const pending = okdb.countByIndex('orders', ['status'], {
111
+ start: ['pending'],
112
+ end: ['pending', OKDBEnv.HIGH_SENTINEL],
113
+ });
114
+
115
+ // Compound index
116
+ await okdb.registerIndex('orders', ['status', 'createdAt']);
117
+ const open = okdb.countByIndex('orders', ['status', 'createdAt'], {
118
+ start: ['open'],
119
+ end: ['open', OKDBEnv.HIGH_SENTINEL],
120
+ });
121
+ ```
122
+
123
+ ---
124
+
103
125
  ## Dot-notation for nested fields
104
126
 
105
127
  Field paths can use dots to reach nested properties:
package/docs/querying.md CHANGED
@@ -161,6 +161,35 @@ for (const { key, value } of okdb.byIndex('articles', ['author', 'publishedAt'],
161
161
  | `offset` | number | Skip this many entries |
162
162
  | `includeViolations` | boolean | For unique indexes: include all violating entries |
163
163
 
164
+ `getIndex` returns primary keys from the index sub-database (not full records) as a **lazy iterable**. Spread to an array if you need `.length`: `[...env.getIndex(...)]`.
165
+
166
+ ---
167
+
168
+ ## Counting index entries
169
+
170
+ `countByIndex` counts entries in an index range without loading any record data. It reads only the index sub-database — O(matching index entries), no record loads.
171
+
172
+ Pass `{start, end}` directly, same as `byIndex`. Use `OKDBEnv.HIGH_SENTINEL` as the end bound for prefix scans:
173
+
174
+ ```javascript
175
+ // Count orders with status === 'pending'
176
+ const n = okdb.countByIndex('orders', ['status'], {
177
+ start: ['pending'],
178
+ end: ['pending', OKDBEnv.HIGH_SENTINEL],
179
+ });
180
+
181
+ // Compound index — count by first field prefix
182
+ const open = okdb.countByIndex('orders', ['status', 'createdAt'], {
183
+ start: ['open'],
184
+ end: ['open', OKDBEnv.HIGH_SENTINEL],
185
+ });
186
+ ```
187
+
188
+ **`countByIndex` vs `getCount`:**
189
+
190
+ - `getCount(type)` — O(1), total count, no filtering.
191
+ - `countByIndex(type, index, {start, end})` — O(matching index entries), filtered count, no record loads.
192
+
164
193
  ---
165
194
 
166
195
  ## Geo query