@thi.ng/oquery 2.3.27 → 2.3.28
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/CHANGELOG.md +1 -1
- package/README.md +34 -10
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -139,7 +139,7 @@ Object queries expect an object of the following structure:
|
|
|
139
139
|
|
|
140
140
|
A concrete example:
|
|
141
141
|
|
|
142
|
-
```ts
|
|
142
|
+
```ts id:db
|
|
143
143
|
const DB = {
|
|
144
144
|
alice: {
|
|
145
145
|
age: 33,
|
|
@@ -167,11 +167,16 @@ To find all answers for the question: Who knows Bob?
|
|
|
167
167
|
```ts tangle:export/readme.ts
|
|
168
168
|
import { defQuery } from "@thi.ng/oquery";
|
|
169
169
|
|
|
170
|
+
// include above DB definition
|
|
171
|
+
<<db>>
|
|
172
|
+
|
|
170
173
|
// create query w/ custom options
|
|
171
174
|
// (options explained further below...)
|
|
172
175
|
const q = defQuery({ partial: true });
|
|
173
176
|
|
|
174
|
-
console.log(
|
|
177
|
+
console.log(
|
|
178
|
+
q(DB, null, "knows", "bob")
|
|
179
|
+
);
|
|
175
180
|
// {
|
|
176
181
|
// alice: { knows: [ 'bob' ] },
|
|
177
182
|
// charlie: { knows: [ 'bob' ] },
|
|
@@ -205,7 +210,9 @@ table above.
|
|
|
205
210
|
|
|
206
211
|
```ts tangle:export/readme.ts
|
|
207
212
|
// Who does Alice know?
|
|
208
|
-
|
|
213
|
+
console.log(
|
|
214
|
+
q(DB, "alice", "knows", null)
|
|
215
|
+
);
|
|
209
216
|
// { alice: { knows: [ 'bob', 'charlie', 'dori' ] } }
|
|
210
217
|
```
|
|
211
218
|
|
|
@@ -215,7 +222,9 @@ terms).
|
|
|
215
222
|
|
|
216
223
|
```ts tangle:export/readme.ts
|
|
217
224
|
// Anyone with initial "A" knows Charlie?
|
|
218
|
-
|
|
225
|
+
console.log(
|
|
226
|
+
q(DB, (s) => s[0] === "a", "knows", "charlie")
|
|
227
|
+
);
|
|
219
228
|
// { alice: { knows: [ 'charlie' ] } }
|
|
220
229
|
```
|
|
221
230
|
|
|
@@ -232,7 +241,9 @@ const DBALT: Person[] = [
|
|
|
232
241
|
{ id: "charlie", knows: ["alice","bob","dori"] },
|
|
233
242
|
];
|
|
234
243
|
|
|
235
|
-
|
|
244
|
+
console.log(
|
|
245
|
+
defQuery<Person[]>()(DBALT, "knows", "alice")
|
|
246
|
+
);
|
|
236
247
|
// [
|
|
237
248
|
// { id: 'bob', knows: [ 'alice' ] },
|
|
238
249
|
// { id: 'charlie', knows: [ 'alice', 'bob', 'dori' ] }
|
|
@@ -247,19 +258,28 @@ above](#query-patterns)...
|
|
|
247
258
|
```ts tangle:export/readme2.ts
|
|
248
259
|
import { defQuery } from "@thi.ng/oquery";
|
|
249
260
|
|
|
261
|
+
// include above DB definition
|
|
262
|
+
<<db>>
|
|
263
|
+
|
|
250
264
|
// using partial result objects option for brevity here
|
|
251
265
|
const q = defQuery({ partial: true });
|
|
252
266
|
|
|
253
267
|
// find all subjects with `type = "person"` relationship
|
|
254
|
-
|
|
268
|
+
console.log(
|
|
269
|
+
q(DB, null, "type", "person")
|
|
270
|
+
);
|
|
255
271
|
// { alice: { type: 'person' }, bob: { type: 'person' } }
|
|
256
272
|
|
|
257
273
|
// everyone w/ given min age
|
|
258
|
-
|
|
274
|
+
console.log(
|
|
275
|
+
q(DB, null, "age", (age: number) => age >= 33)
|
|
276
|
+
);
|
|
259
277
|
// { alice: { age: 33 } }
|
|
260
278
|
|
|
261
279
|
// select only subjects with A/B initials
|
|
262
|
-
|
|
280
|
+
console.log(
|
|
281
|
+
q(DB, (id) => id >= "a" && id < "c", null, null)
|
|
282
|
+
);
|
|
263
283
|
// {
|
|
264
284
|
// alice: { age: 33, knows: [ 'bob', 'charlie', 'dori' ], type: 'person' },
|
|
265
285
|
// bob: { age: 32, knows: [ 'alice' ], type: 'person', spouse: 'alice' }
|
|
@@ -272,7 +292,9 @@ Union vs. intersection queries:
|
|
|
272
292
|
const union = defQuery();
|
|
273
293
|
|
|
274
294
|
// who knows bob OR charlie?
|
|
275
|
-
|
|
295
|
+
console.log(
|
|
296
|
+
union(DB, null, "knows", ["bob", "charlie"])
|
|
297
|
+
);
|
|
276
298
|
// {
|
|
277
299
|
// alice: { age: 33, knows: [ 'bob', 'charlie', 'dori' ], type: 'person' },
|
|
278
300
|
// charlie: { parent: 'alice', knows: [ 'alice', 'bob', 'dori' ] },
|
|
@@ -282,7 +304,9 @@ union(DB, null, "knows", ["bob", "charlie"]);
|
|
|
282
304
|
const isec = defQuery({ intersect: true });
|
|
283
305
|
|
|
284
306
|
// who knows bob AND charlie?
|
|
285
|
-
|
|
307
|
+
console.log(
|
|
308
|
+
isec(DB, null, "knows", ["bob", "charlie"])
|
|
309
|
+
);
|
|
286
310
|
// {
|
|
287
311
|
// alice: { age: 33, knows: [ 'bob', 'charlie', 'dori' ], type: 'person' }
|
|
288
312
|
// }
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thi.ng/oquery",
|
|
3
|
-
"version": "2.3.
|
|
3
|
+
"version": "2.3.28",
|
|
4
4
|
"description": "Datalog-inspired, optimized pattern/predicate query engine for JS objects & arrays of objects",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -99,5 +99,5 @@
|
|
|
99
99
|
],
|
|
100
100
|
"year": 2020
|
|
101
101
|
},
|
|
102
|
-
"gitHead": "
|
|
102
|
+
"gitHead": "4e98c38a817045d0e9a5b8bb6da23c00a721c3e0\n"
|
|
103
103
|
}
|