All Projects → miniql → miniql

miniql / miniql

Licence: MIT license
A tiny JSON-based query language inspired by GraphQL

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to miniql

vaultaire
Query DSL and data access utilities for Corda developers.
Stars: ✭ 14 (-88.43%)
Mutual labels:  query, query-language
kql
Kirby's Query Language API combines the flexibility of Kirby's data structures, the power of GraphQL and the simplicity of REST.
Stars: ✭ 120 (-0.83%)
Mutual labels:  query, query-language
Rapidql
Query multiple APIs and DBs and join them in a single query
Stars: ✭ 91 (-24.79%)
Mutual labels:  query, query-language
m-custom-functions
This library contains created mostly pure M-functions without any other languages.
Stars: ✭ 24 (-80.17%)
Mutual labels:  query, query-language
typeql
TypeQL: the query language of TypeDB - a strongly-typed database
Stars: ✭ 157 (+29.75%)
Mutual labels:  query, query-language
Purescript Selda
A type-safe, high-level SQL library for PureScript
Stars: ✭ 72 (-40.5%)
Mutual labels:  query, query-language
Ldflex
A JavaScript DSL for querying Linked Data on the Web
Stars: ✭ 123 (+1.65%)
Mutual labels:  query, query-language
rx-query
timdeschryver.github.io/rx-query/
Stars: ✭ 195 (+61.16%)
Mutual labels:  query
GB-html5-respond
移动端响应式布局解决方案(JavaScript + REM)
Stars: ✭ 34 (-71.9%)
Mutual labels:  queries
py-jsonq
A simple Python package to Query over Json Data
Stars: ✭ 100 (-17.36%)
Mutual labels:  query
powerorm
A very simple but effective php orm
Stars: ✭ 21 (-82.64%)
Mutual labels:  query
chartjs-plugin-datasource-prometheus
Chart.js plugin for Prometheus data loading
Stars: ✭ 77 (-36.36%)
Mutual labels:  query
graph-client
light zero dependency graphql-client, supporting cache and SSR
Stars: ✭ 27 (-77.69%)
Mutual labels:  query
micro-query
Simple query string parser for Vercel's Micro
Stars: ✭ 23 (-80.99%)
Mutual labels:  query
Gridify
Easy and optimized way to apply Filtering, Sorting, and Pagination using text-based data.
Stars: ✭ 372 (+207.44%)
Mutual labels:  query
qcert
Compilation and Verification of Data-Centric Languages
Stars: ✭ 50 (-58.68%)
Mutual labels:  query-language
aarbac
An Automated Role Based Access Control .NET framework with T-SQL Query Parser which automatically parse select, insert, update, delete queries based on the logged in user role
Stars: ✭ 18 (-85.12%)
Mutual labels:  query
Queries
SQLite queries
Stars: ✭ 57 (-52.89%)
Mutual labels:  queries
LDflex-Comunica
Comunica query engine support for the LDflex language
Stars: ✭ 15 (-87.6%)
Mutual labels:  query
freebase-mql
A review of the deprecated Freebase knowledge base and Metaweb Query Language (MQL). A brief comparison of MQL and GraphQL.
Stars: ✭ 41 (-66.12%)
Mutual labels:  query-language

MiniQL

A tiny JSON-based query language inspired by GraphQL

Pronounced "miniquel", similar to "miniscule".

New to this? Check out the examples below or jump to getting started.

For a quick idea of what queries look like and how they work, jump straight into the interactive example.

Click here to support my work

Love this? Please star this repo!

MiniQL in a nutshell

Diagram of MiniQL

Examples

Interactive example

There's an interactive browser-only example of MiniQL here:

https://miniql.github.io/miniql-interactive-example/

You fnd find the code for it here:

https://github.com/miniql/miniql-interactive-example

Node.js + CSV files

Here is an example of making MiniQL queries against a CSV file dataset under Node.js:

https://github.com/miniql/miniql-csv-example

Node.js + JSON files

Here is an example of making MiniQL queries against a JSON file dataset under Node.js:

https://github.com/miniql/miniql-json-example

JavaScript notebook

Here is an easy to read MiniQL example in a JavaScript notebook

https://miniql.github.io/notebook-example/

Frontend + Express REST API + MongoDB

Here is an example of using MiniQL to make queries against a MongoDB database through an Express REST API to display query results in the frontend.

https://github.com/miniql/miniql-express-mongodb-example

Motivation

GraphQL is awesome, but sometimes the following can be annoying...

  • It is big and complicated.
  • It introduces a new language into your stack.
  • I don't want to define a "schema".
    • Schemaless is the best way to prototype an MVP when you don't know what the data is yet.
  • It's tedious to have to specify everything you want returned.
    • Sometimes you just want everything returned! Especially when you are exploring your data!

Aims

  • To be tiny, yet flexible.
  • To easily create queries.
  • To easily implement the backend.
  • To have a single query end point where auth can be implemented.
  • To avoid having many separate REST APIs.
  • To be able to retreive aggregate and optimized data to the front end.
  • To be able to easily explore data.
  • To not impose unecessary structure or rules on your data!
  • Make the most of the backend capabilities (eg search and filtering capability in the database)

Features

  • The query language is JSON and can easily be sent over the weire.
  • The results are JSON and can easiy be received over the wire.
  • MiniQL works in both Node.js and the browser.
    • MiniQL can potentially work in other programming languages, if someone wants to create an implementation for their own fav language.
  • Decouples the query engine from entity resolution ([separation of concerns](https://
  • There is no enforced schema, just like MongoDB.
    • But you can easily make your own JSON schema for validation and intellisense in the frontend. en.wikipedia.org/wiki/Separation_of_concerns)).
  • There is no built-in type system - use your programming language for that! (e.g. TypeScript)
  • Follows relationships and resolves nested entities.
    • You control how the relationships in your data are defined.
  • Aggregates query results from different data sources.
  • Supports arbitrary user-defined types of operations:
    • The MiniQL convertion is have "get" or "update" operations.
    • But use whatever names you like.
    • You can have any other operations as well with whatever names you like.
  • Optionally alias entities in the output. You control the field names that returned in the query result.
  • The "query" is passed through to the resolver, you can build your own resolver or use one of the existing plugins:

Bring your own

MiniQL delegates queries for entities to the query resolver.

The query resolver is something that you implmenent or is provided by a MiniQL plugin (such as the JSON plugin, the CSV plugin or the Inline data plugin).

Implementing your own resolver means you can have what ever features you like in the backend.

Adding features like these is completely under your control:

  • Pagination
  • Retrieving total entities
  • Entity search and filtering
  • Included fields
  • Excluded fields
  • Or anthing else you can think of!

You can manage how data is returned, e.g:

  • Blacklisted fields
  • Whitelisted fields
  • All data, partial data, whatever you want!

Future

  • Add a configurable MongoDB resolver.
  • Caching and aggregation (wishlist)
  • Hooks - be notifed when particular entities/fields have been updated.
  • Optimisation to do queries in parallel.
  • Built-in filtering?
  • How to retreieve a count after search/filtering is applied.

Getting started

Install MiniQL:

npm install --save miniql

Import MiniQL (JavaScript):

const { miniql } = require("miniql");

Import MiniQL (TypeScript):

import { miniql } from "miniql";

Now we must create a query resolver. For this example we'll use a character entity (see the Star Wars data in the interactive example).

We need to define functions for retrieving and updating our character entity:

const queryResolver = {
    get: {
        character: {
            invoke: async (args: any, context: any) => { // Handles a 'get' query.
                if (args.name !== undefined) {
                    // Asking for a particular named character.
                    // Look up the single named character in your database and return it.
                    const theCharacter = ...;
                    return theCharacter;
                }
                else {
                    // Asking for all characters.
                    // Look up all characters in your database and return them.
                    const allCharacters = ...;
                    return allCharacters;
                }
            }
        }
    },

    update: {
        character: {
            invoke: async (args: any, context: any) => { // Handles an 'update' query.
                if (args.name !== undefined) {
                    const updateParams = args.params;
                    // Store `updateParams` against the single 
                    // named character in your database.
                }
                else {
                    const updateParams = args.params;
                    // Add a new named character with 
                    // `updateParams` in your database.
                }
            },
        },
    },
};

There's various plugins that can create a query resolver for us depending on our data source:

A MonogDB query resolver is coming soon! If you'd like to implement a resolver for your own favorite database please let me know.

Now that we have a query resolver we can execute queries against it with MiniQL.

First we need a query, let's create one to get the character called "Darth Vader":

const getQuery = {
    get: { // This is a 'get' operation.
        character: {
            args: {
                name: "Darth Vader", // We are retrieving the record for Mr Vader.
            },
        },
    },
};

Now we can execute the get query to retreive the record for Mr Vader:

const context = {}; // Global context passed to our resolver.
const queryResult = await miniql(getQuery, queryResolver, {}); // Executes the query.
console.log(queryResult);

Here's the output of the query:

{
    "character": {
        "name": "Darth Vader",
        "height": 202,
        "mass": 136,
        "hair_color": "none",
        "skin_color": "white",
        "eye_color": "yellow",
        "birth_year": "41.9BBY",
        "gender": "male",
        "homeworld": "Tatooine",
        "species": "Human"
    }
}

Now let's execute an update query to modify mr Vader's record:

const updateQuery = {
    update: { // This is an 'update' operation.
        character: {
            args: {
                name: "Darth Vader",
                params: {
                    // Sets Mr Vaders hair color.
                    hair_color: "brown", // At least it was brown back when he had hair.
                },
            },
        },
    },
};

Now we execute the update query against our query resolver:

const context = {};
await miniql(updateQuery, queryResolver, {});

Mr Vader's hair color is now set to "brown".

Have fun with MiniQL!

More advanced documentation is coming soon! Follow for updates.

Wishlist

  • Parallelise complex queries over multiple nodes.

Support the developer

See the ways you can support the developer.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].