Package Exports
- @thi.ng/oquery
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@thi.ng/oquery) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
This project is part of the @thi.ng/umbrella monorepo.
About
Datalog-inspired, optimized pattern/predicate query engine for JS objects.
Currently, there're 125 possible query approaches, which can be collapsed into 27 unique query implementations. Each query is based on RDF-style Subject-Predicate-Object patterns (only without requiring query terms to be URIs), with each term one of:
null
- wildcard, any non-null value in that position will be selected- Predicate function - called with all possible terms in that position
- Literal value - for subjects and predicates, this can only be a string or number. For "object" position any value type is allowed
- Array or
Set
- multiple choices (literals) for given query term
See basic query examples below...
Status
ALPHA - bleeding edge / work-in-progress
Related packages
- @thi.ng/rstream-query - @thi.ng/rstream based triple store & reactive query engine
Installation
yarn add @thi.ng/oquery
// ES module
<script type="module" src="https://unpkg.com/@thi.ng/oquery?module" crossorigin></script>
// UMD
<script src="https://unpkg.com/@thi.ng/oquery/lib/index.umd.js" crossorigin></script>
Package sizes (gzipped, pre-treeshake): ESM: 823 bytes / CJS: 883 bytes / UMD: 957 bytes
Dependencies
API
TODO - Please see extensive tests for now...
import { defQuery } from "@thi.ng/oquery";
// object to query
const DB = {
alice: {
age: 33,
knows: ["bob", "charlie", "dori"],
type: "person",
},
bob: {
age: 32,
knows: ["alice"],
type: "person",
spouse: "alice",
},
charlie: {
parent: "alice",
knows: ["alice", "bob", "dori"],
},
};
// init w/ default opts
// (uses @thi.ng/equiv for equality checks)
const query = defQuery();
// find all subjects with `type = "person"` relationship
query(DB, null, "type", "person");
// { alice: { type: 'person' }, bob: { type: 'person' } }
// find all who know bob or charlie
query(DB, null, "knows", ["bob", "charlie"])
// { alice: { knows: [ 'bob', 'charlie' ] }, charlie: { knows: [ 'bob' ] } }
// everyone w/ given min age
query(DB, null, "age", (age) => age >= 33)
// { alice: { age: 33 } }
// select only subjects with A/B initials
query(DB, (id) => id > "a" && id < "c", null, null)
// {
// alice: { age: 33, knows: [ 'bob', 'charlie', 'dori' ], type: 'person' },
// bob: { age: 32, knows: [ 'alice' ], type: 'person', spouse: 'alice' }
// }
Authors
Karsten Schmidt
License
© 2020 Karsten Schmidt // Apache Software License 2.0