universql

0.3.9 • Public • Published

UniversQL

A JavaScript implementation of the UniversQL spec.

Installation

$ npm install universql

Example

var UniversQL = require("universql");
UniversQL.addAdapter(require("universql-json"));
 
 

API

UniversQL
.adapters
.addAdapterUniversQL
.removeAdapterUniversQL
.getDefaultAdapterAdapter
.setDefaultAdapterUniversQL
.templateRE
.getAdapter([name])Adapter
.setAdapter(The)UniversQL
.compile([name], [recompile])*
.translate([name], [context])*
.run([name], data, [context])*

UniversQL

The UniversQL class: parses a query string and attaches to this.query.

Param Type Description
queryString String The query string to parse.

UniversQL.adapters

Adapters allow conversion between a UniversQL JSON-object, and their specific language. An Adapter should contain name, translate and optionally run.

The prototypes share a common adapter list. Furthermore, we make #addAdapter both an Instance and Static method (to facilitate additions).

UniversQL.addAdapter ⇒ UniversQL

Adds an adapter: sets as default if no current default.

Returns: UniversQL - The instance (for chaining).

Param Type Description
adapter Adapter The adapter to be added.

UniversQL.removeAdapter ⇒ UniversQL

Removes an adapter.

Returns: UniversQL - The adapter that was removed.

Param Type Description
adapter Adapter The adapter to be removed.

UniversQL.getDefaultAdapter ⇒ Adapter

Gets the default adapter.

Returns: Adapter - The default adapter.

UniversQL.setDefaultAdapter ⇒ UniversQL

Sets the default adapter.

Returns: UniversQL - The instance (for chaining).

Param Type Description
The Adapter | String default adapter (or name of installed adapter).

UniversQL.templateRE

Basic templating, inspired by doT.js. Only includes basic interpolation.

UniversQL.getAdapter([name]) ⇒ Adapter

Gets the adapter.

Returns: Adapter - The adapter.

Param Type Description
[name] String Optional name of adapter to get.

UniversQL.setAdapter(The) ⇒ UniversQL

Sets the adapter.

Returns: UniversQL - The instance (for chaining).

Param Type Description
The Adapter | String adapter (or name of installed adapter).

UniversQL.compile([name], [recompile]) ⇒ *

Compiles the query into another query language. Stores into compiled.

Returns: * - Translated form of query.

Param Type Default Description
[name] String Name of the adapter to use (falls back to default).
[recompile] Boolean false If true, forces re-translation.

UniversQL.translate([name], [context]) ⇒ *

Translate query using context (and compiles if necessary).

Returns: * - Query with templates compiled.

Param Type Default Description
[name] String Name of the adapter to use (falls back to default).
[context] Object {} Context for templating.

UniversQL.run([name], data, [context]) ⇒ *

Runs query (translates, templatizes and compiles if necessary).

Returns: * - Query with templates compiled.

Param Type Default Description
[name] String Name of the adapter to use (falls back to default).
data Array The data on which to run the query.
[context] Object {} Context for templating.

createTemplate(str, pattern) ⇒ function

Creates a template function (that renders when called with context).

Returns: function - Template function: fn(context)

Param Type Description
str String The template to precompile.
pattern RegExp The template pattern to replace.

templater(data, fn)

Runs data through template engine, then calls fn with results.

Param Type Description
data * The data to preprocess.
fn function The subsequent function to call.

License

MIT Licensed

Readme

Keywords

Package Sidebar

Install

npm i universql

Weekly Downloads

0

Version

0.3.9

License

MIT

Last publish

Collaborators

  • brandoncarl