Through this function you can access all your data of the datasets you have access to within Hublify.
Basically you are building and executing dataset-retrieval-query with these functions.
- Behaves like a SQL's SELECT query
- Provide fields to retrieve
- It handles automatic connections to other datasets (SQL JOINs)
- Provide filter & segments to apply
- Returns a report-object containing all the data and head-meta informations, too.
Example
For quick dive, here an example
{# Getting data (fields "pcode","name" and "price") from dataset "product" #}
{% set myData = hublify.dataset('product').fields(['pcode','name','price']).all %}
Functions
datareport(...)
Creates a dataset-query-object.
Parameter: "<dataset>" A string containing the dataset-label.
Return: This functions returns dataset-query-object.
{# Creating a standalone query-object #}
{% set myQueryObj = hublify.datareport('product') %}
field(...)
Adds one field to the dataset-query.
Parameter: Pass a string containing the field you want to add.
{# Adding the field "firstname" to the query #}
{% set myData = hublify.dataset('person').field('firstname').all %}
You can also cascade multiple field(...) functions. But see also to directly add an array of fields, using the fields(...)-function.
{# Cascaded adding of single fields #}
{% set myData = hublify.dataset('person').field('firstname').field('lastname').field('gender').all %}
fields(...)
Adds multiple fields you want to read to the dataset-query.
Parameter: Pass an array of strings of fields you want to add.
{# Adding three fields as an array to the query #}
{% set myData = hublify.dataset('person').fields(['firstname','lastname','gender']).all %}
filter(...)
Adds a filter to your dataset-query.
{# Getting all persons "firstname" whos "lastname" is "skywalker" #}
{% set myData = hublify.dataset('person').field('firstname').filter('lastname','skywalker').all %}
filters(...)
Adds multiple filters to your dataset-query at once.
{# Getting all persons "firstname" filtered for the "firstname" and "lastname" #}
{% set myData = hublify.dataset('person').field('firstname').filters([ {'lastname':'skywalker'}, {'firstname':'luke'}]).all %}
segment(...)
Adds a filtering segment to your dataset-query.
{# Adding the segment "bday_next_within_7days" to the query #}
{% set myData = hublify.dataset('person').segment('bday_next_within_7days').all %}
Of course you can combine segments with other filters!
segments(...)
Adds multiple segments for filtering to your dataset-query at once.
{# Adding multiple segments to the query #}
{% set myData = hublify.dataset('person').segments(['bday_next_within_7days','a-customer']).all %}
orderBy(...)
Adds an ordering to your retrieved data.
This can be called multiple times. Given order-by-statements are then cascaded in the same order.
{# Enabling a ordering by field "name" in ascending order #}
{% set myData = hublify.dataset('product').fields(['pcode','name']).orderBy('name', 'ASC').all %}
Parameter: First parameter is the field name, the second the order-direction ("ASC|DESC").
limit(...)
To limit the number of returned dataset-records, use this function. It makes only really sense to use it when executing the dataset-query with all(...).
{# Limit the number to the first 5 products #}
{% set myData = hublify.dataset('product').fields(['pcode','name']).limit(5).all %}
param(...)
Add an own parameter to the query. This function can be called multiple times with same or different key/values.
Example
{# Add a parameter "viewingUser" = "kevin" to actual dataset-query. #}
{% set myData = hublify.dataset('product').param('viewingUser', 'kevin').fields(['pcode','name']).all %}
params(...)
Add any own multiple parameters to the query.
Example
{# Add a parameter "viewingUser" = "kevin" to actual dataset-query. #} {% set myData = hublify.dataset('product')
.params(
{
"myParam1": 123,
"anotherParam": "aloha!"
})
.fields(['pcode','name'])
.all %}
one(...)
EXECUTEs the data-query and returns only the first object.
(Like a: limit 1).
Put this always to the end of your twig-expression!
all(...)
EXECUTEs the data-query and returns an array of records.
Filters and sorting and limits are regarded.
Put this always to the end of your twig-expression!