0.3.9 • Published 7 years ago

universql v0.3.9

Weekly downloads
3
License
MIT
Repository
github
Last release
7 years ago

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.

ParamTypeDescription
queryStringStringThe 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).

ParamTypeDescription
adapterAdapterThe adapter to be added.

UniversQL.removeAdapter ⇒ UniversQL

Removes an adapter.

Returns: UniversQL - The adapter that was removed.

ParamTypeDescription
adapterAdapterThe 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).

ParamTypeDescription
TheAdapter | Stringdefault 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.

ParamTypeDescription
nameStringOptional name of adapter to get.

UniversQL.setAdapter(The) ⇒ UniversQL

Sets the adapter.

Returns: UniversQL - The instance (for chaining).

ParamTypeDescription
TheAdapter | Stringadapter (or name of installed adapter).

UniversQL.compile(name, recompile) ⇒ *

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

Returns: * - Translated form of query.

ParamTypeDefaultDescription
nameStringName of the adapter to use (falls back to default).
recompileBooleanfalseIf true, forces re-translation.

UniversQL.translate(name, context) ⇒ *

Translate query using context (and compiles if necessary).

Returns: * - Query with templates compiled.

ParamTypeDefaultDescription
nameStringName of the adapter to use (falls back to default).
contextObject{}Context for templating.

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

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

Returns: * - Query with templates compiled.

ParamTypeDefaultDescription
nameStringName of the adapter to use (falls back to default).
dataArrayThe data on which to run the query.
contextObject{}Context for templating.

createTemplate(str, pattern) ⇒ function

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

Returns: function - Template function: fn(context)

ParamTypeDescription
strStringThe template to precompile.
patternRegExpThe template pattern to replace.

templater(data, fn)

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

ParamTypeDescription
data*The data to preprocess.
fnfunctionThe subsequent function to call.

License

MIT Licensed

0.3.9

7 years ago

0.3.8

7 years ago

0.3.7

7 years ago

0.3.6

7 years ago

0.3.5

7 years ago

0.3.4

7 years ago

0.3.3

7 years ago

0.3.2

7 years ago

0.3.1

7 years ago

0.3.0

7 years ago

0.1.4

8 years ago

0.1.3

8 years ago

0.1.2

8 years ago

0.1.1

8 years ago

0.1.0

8 years ago