Skip to content

miniql/miniql-inline

Folders and files

NameName
Last commit message
Last commit date

Latest commit

290b4b6 · May 30, 2022

History

18 Commits
Aug 2, 2020
Jul 27, 2020
Aug 12, 2020
Jul 27, 2020
Jul 27, 2020
Jul 27, 2020
May 30, 2022
Jul 27, 2020
Jul 27, 2020
Aug 12, 2020
Aug 12, 2020
Jul 27, 2020
Jul 27, 2020
Jul 27, 2020

Repository files navigation

@miniql/inline

A MiniQL query resolver to query inline data.

Any problems? Please log an issue on this repo.

Love this? Please star the repo and support my work

Using it

Install the modules in your Node.js project:

npm install --save miniql
npm install --save @miniql/inline

Import the modules (JavaScript):

const { miniql } = require("miniql");
const { createQueryResolver } = require("@miniql/inline");

Import the modules (TypeScript):

import { miniql } from "miniql";
import { createQueryResolver } from "@miniql/inline";

Configure and create an inline data query resolver:

    //
    // 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:

    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 for more information on how to make queries.

Don't forget to star the repo and follow the developer on Twitter.