https://github.com/miniql/miniql-inline
A MiniQL query resolver for inline data.
https://github.com/miniql/miniql-inline
data query query-language
Last synced: 16 days ago
JSON representation
A MiniQL query resolver for inline data.
- Host: GitHub
- URL: https://github.com/miniql/miniql-inline
- Owner: miniql
- License: mit
- Created: 2020-07-27T04:15:47.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2022-05-30T09:20:32.000Z (about 4 years ago)
- Last Synced: 2025-12-03T10:49:43.875Z (6 months ago)
- Topics: data, query, query-language
- Language: TypeScript
- Homepage:
- Size: 319 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# @miniql/inline
A [MiniQL](https://github.com/miniql/miniql) query resolver to query inline data.
Any problems? Please log an issue on this repo.
Love this? Please [star the repo](https://github.com/miniql/miniql) and [support my work](https://www.codecapers.com.au/about#support-my-work)
## Using it
Install the modules in your Node.js project:
```bash
npm install --save miniql
npm install --save @miniql/inline
```
Import the modules (JavaScript):
```javascript
const { miniql } = require("miniql");
const { createQueryResolver } = require("@miniql/inline");
```
Import the modules (TypeScript):
```typescript
import { miniql } from "miniql";
import { createQueryResolver } from "@miniql/inline";
```
Configure and create an inline data query resolver:
```javascript
//
// Configures the inline query resolver.
//
const inlineQueryConfig = {
species: {
primaryKey: "name",
nested: {
homeworld: {
parentKey: "homeworld",
from: "planet",
},
},
},
planet: {
primaryKey: "name",
nested: {
species: {
foreignKey: "homeworld",
},
},
},
};
//
// The data that we'd like to query.
//
const data = {
species: [
{
name: "Hutt",
classification: "gastropod",
designation: "sentient",
language: "Huttese",
homeworld: "Nal Hutta",
},
// ... more data goes here ..
],
planet: [
{
name: "Nal Hutta",
rotation_period: 87,
orbital_period: 413,
diameter: 12150,
climate: "temperate",
terrain: "urban, oceans, swamps, bogs",
population: 7000000000
}
// ... more data goes here ..
],
// ... more data goes here ..
};
//
// Creates a query resolver for inline data.
//
const queryResolver = await createQueryResolver(inlineQueryConfig);
```
Now you can make queries against the dataset, for example:
```javascript
const query = {
get: {
species: { // Query for "species" entity.
// No arguments gets all entities.
resolve: {
homeworld: { // Resolves the homeworld of each species as a nested lookup.
},
}
},
},
};
// Invokes MiniQL.
const result = await miniql(query, queryResolver, {});
// Displays the query result.
console.log(JSON.stringify(result, null, 4));
```
Please see [MiniQL](https://github.com/miniql/miniql) for more information on how to make queries.
Don't forget to [star the repo](https://github.com/miniql/miniql) and [follow the developer on Twitter](https://twitter.com/codecapers).