UniversQL
A JavaScript implementation of the UniversQL spec.
Installation
$ npm install universql
Example
var UniversQL = ;UniversQL;
API
UniversQL
.adapters
.addAdapter ⇒ UniversQL
.removeAdapter ⇒ UniversQL
.getDefaultAdapter ⇒ Adapter
.setDefaultAdapter ⇒ UniversQL
.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
UniversQL.addAdapter ⇒ 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
UniversQL.removeAdapter ⇒ Removes an adapter.
Returns: UniversQL
- The adapter that was removed.
Param | Type | Description |
---|---|---|
adapter | Adapter |
The adapter to be removed. |
Adapter
UniversQL.getDefaultAdapter ⇒ Gets the default adapter.
Returns: Adapter
- The default adapter.
UniversQL
UniversQL.setDefaultAdapter ⇒ 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.
Adapter
UniversQL.getAdapter([name]) ⇒ Gets the adapter.
Returns: Adapter
- The adapter.
Param | Type | Description |
---|---|---|
[name] | String |
Optional name of adapter to get. |
UniversQL
UniversQL.setAdapter(The) ⇒ 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. |
function
createTemplate(str, pattern) ⇒ 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