Menu

Expand
Rate this page:

Live Query Language

The Live Query Language allows Flex customers to get basic information about their Flex instance from Sync. Queries are written in infix notation in the form 'field [operator] "value"'. Only string types are supported for values.

The examples on this page use the Sync SDK.

Index name:

Index name is a data class for which Live Queries are available. Currently supported index names for Flex are: tr-task, tr-worker, tr-reservation, tr-queue.

The TaskQueue list may not include all TaskQueues if the TaskQueue has not been used for 30 days or more. Reset the expiration on your TaskQueue by routing an inbound task to the Queue. Each additional task and any transfers will reset the expiration time to 30 days.

Query operators:

Operator Description Alternative forms Example
and Logical AND operation. and, AND, && a == "b" AND c != "d"
or Logical OR operation. or, OR, || a == "b" OR c != "d"
in Evaluates whether an attribute's value matches an element (possibly many) from the given array. in, IN field IN ["value1", "value2"]
eq Checks if an attribute has a specified value. eq, EQ, == field EQ "value"
not_in Evaluates whether an attribute has any values other than those specified in the given array. not_in, NOT_IN field NOT_IN ["value1", "value2"]
not_eq Checks if an attribute has any values other than the given one. not_eq, NOT_EQ, != field NOT_EQ "value"
contains Checks if an attribute value string contains a substring contains, CONTAINS field CONTAINS "value"
() Start and end of evaluation block, determines operator precedence. n/a (field == "value" OR lang IN ["es", "en"]) AND team EQ "engineering"
[] Start and end of array block, enumerates a list of elements. n/a ["value1", "value2"]
, Comma is used to separate elements in array. n/a n/a
"..." Value of a string type must be double-quoted within the query expression. n/a n/a

* Sync Client has a number of limits in place which will constrain certain query expressions. Please check Sync Client Limits page for more information.

Subscribing to live updates for worker Bob:

const SyncClient = require('twilio-sync');

syncClient.liveQuery('tr-worker', 'data.attributes.worker_name == "Bob"')
    .then(function (args) {
        console.log('Subscribed to live data updates for worker Bob');
        let items = args.getItems();
        Object.entries(items).forEach(([key, value]) => {
            console.log('Search result item key: ' + key);
            console.log('Search result item value: ' + value);
        });
    })
    .catch(function (err) {
        console.log('Error when subscribing to live updates for Bob', err);
    });

Using empty string for wildcard search.

As currently max response size is 200 records, code example below will subscribe us to up to 200 workers.

const SyncClient = require('twilio-sync');

syncClient.liveQuery('tr-worker', '')
    .then(function (args) {
        console.log('Subscribed to live data updates for workers');
        let items = args.getItems();
        Object.entries(items).forEach(([key, value]) => {
            console.log('Search result item key: ' + key);
            console.log('Search result item value: ' + value);
        });
    })
    .catch(function (err) {
        console.log('Error when subscribing to live updates', err);
    });;
Rate this page:

Need some help?

We all do sometimes; code is hard. Get help now from our support team, or lean on the wisdom of the crowd by visiting Twilio's Stack Overflow Collective or browsing the Twilio tag on Stack Overflow.

Loading Code Sample...
        
        
        

        Thank you for your feedback!

        Please select the reason(s) for your feedback. The additional information you provide helps us improve our documentation:

        Sending your feedback...
        🎉 Thank you for your feedback!
        Something went wrong. Please try again.

        Thanks for your feedback!

        thanks-feedback-gif