MistQL Documentation
website·Indexed 31 days ago
https://www.mistql.com/A miniature language for performing computations on JSON-like structures. MistQL provides implementations for JavaScript (via npm) and Python (via pip, supporting Python 3.8+), featuring contextualized expressions, core datatypes corresponding to JSON, and support for custom functions in the JS implementation.
What's inside MistQL
- MistQL is a domain-specific expression language designed for performing computations on JSON-like objects. It is built for high readability and is specifically optimized for size-restricted frontends (the NPM implementation is 5.5kB gzipped with 0 dependencies). It is available in both JavaScript and Python, allowing developers to share logic between the client and server.
Understand and use Contextualized Expressions in MistQL
Contextualized Expressions in MistQL function similarly to lambdas in other languages. Every expression is executed within a specific context, represented by the@variable. MistQL uses a context stack; functions that modify the context push a new context onto this stack. When a function executes an expression multiple times (e.g., iterating over an array), it pushes the current element to the@variable for each execution. In documentation, functions that push to the context stack are denoted with the signature@: SomeContextType -> SomeReturnType.Understand the MistQL Initial Context and @ symbol
In MistQL, the@symbol refers to the current context. Initially, this context is set to thedatapassed into the engine, making@an identity query that returns the input data exactly as it was provided.Query: @ Data: ["arbitrary", "data"] Result: ["arbitrary", "data"]Understand the MistQL Initial Context and @ symbol
In MistQL, the@symbol refers to the current context. Initially, this context is set to thedatapassed into MistQL, making@an identity query that returns the input data structure exactly as it was provided.Query: @ Data: ["arbitrary", "data"] Result: ["arbitrary", "data"]Understand the MistQL Initial Context and @ symbol
In MistQL, the@symbol refers to the current context. Initially, this context is set to the_datapassed into the engine. Therefore, a query consisting only of@acts as an identity query, returning the input data exactly as it was provided.Query: @ Data: ["arbitrary", "data"] Result: ["arbitrary", "data"]Understand and use Contextualized Expressions in MistQL
Contextualized Expressions in MistQL act as lambdas. Every expression is executed within a specific context, represented by the@variable. MistQL uses a context stack; functions that modify the context push new values onto this stack. When a function (likefilterormap) iterates over a collection, it pushes the current element to the context stack, making the element's properties available as variables in the expression scope.Understand the MistQL Initial Context and @ symbol
The@symbol refers to the current context. Initially, this context is set to thedatapassed into MistQL, making@an identity query that returns the input data exactly as provided.Query: @ Data: ["arbitrary", "data"] Result: ["arbitrary", "data"]Understand the MistQL Initial Context and @ symbol
In MistQL, the@symbol refers to the current context. Initially, this context is set to thedatapassed into the engine. The simplest query@acts as an identity query, returning the input data exactly as it was provided.Query: @ Data: ["arbitrary", "data"] Result: ["arbitrary", "data"]Understand and use Contextualized Expressions in MistQL
Contextualized Expressions in MistQL act as lambdas. Every expression is executed within a specific context, and the
@variable refers to the current context at the time of execution. MistQL manages contexts using a stack; functions that modify the context push a new context onto this stack.When a function (like
filterormap) executes an expression multiple times over a collection, it pushes the current element to the context stack as@. Any properties of the object assigned to@are automatically populated into the scope, allowing you to reference fields directly by name without explicitly prefixing them with@.-- Filter an array for even numbers filter (@ % 2 == 0) [1, 2, 3, 4, 5, 6, 7] -- Result: [2, 4, 6] -- Map over objects, incrementing the 'foo' property of each map (foo + 1) [{"foo": 10}, {"foo": 20}] -- Result: [11, 21] -- Pipeline: filter events by type and map to the email field events | filter type == "page_shown" | map emailInstall MistQL for JavaScript or Python
MistQL is a miniature language for performing computations on JSON-like structures. The JavaScript implementation is dependency-free and optimized for client-side browser applications (5.3kB gzipped).# For JavaScript npm install --save mistql # For Python pip install mistqlInstall MistQL for Python
The MistQL Python implementation requires Python 3.8 or higher and can be installed using pip.pip install mistqlInstall and use MistQL in JavaScript
The MistQL JavaScript implementation allows you to execute MistQL queries against JS data structures. Install the package via npm and use thequeryfunction to process data.npm install mistqlimport {query} from 'mistql'; const len = query('count @', [1, 2, 3]); console.log(len);