Skip to contentSkip to navigationSkip to topbar
On 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 page anchor

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.

(warning)

Warning

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.


OperatorDescriptionAlternative formsExample
andLogical AND operation.and, AND, &&a == "b" AND c != "d"
orLogical OR operation.or, OR, ||a == "b" OR c != "d"
inEvaluates whether an attribute's value matches an element (possibly many) from the given array.in, INfield IN ["value1", "value2"]
eqChecks if an attribute has a specified value.eq, EQ, ==field EQ "value"
not_inEvaluates whether an attribute has any values other than those specified in the given array.not_in, NOT_INfield NOT_IN ["value1", "value2"]
not_eqChecks if an attribute has any values other than the given one.not_eq, NOT_EQ, !=field NOT_EQ "value"
containsChecks if an attribute value string contains a substringcontains, CONTAINSfield CONTAINS "value"
()Start and end of evaluation block, determine operator precedence.n/a(field == "value" OR lang IN ["es", "en"]) AND team EQ "engineering"
[]Start and end of array block, enumerate a list of elements.n/a["value1", "value2"]
,Comma is used to separate elements in array.n/an/a
"..."Value of a string type must be double-quoted within the query expression.n/an/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

subscribing-to-live-updates-for-worker-bob page anchor
1
const SyncClient = require('twilio-sync');
2
3
syncClient.liveQuery('tr-worker', 'data.attributes.worker_name == "Bob"')
4
.then(function (args) {
5
console.log('Subscribed to live data updates for worker Bob');
6
let items = args.getItems();
7
Object.entries(items).forEach(([key, value]) => {
8
console.log('Search result item key: ' + key);
9
console.log('Search result item value: ' + value);
10
});
11
})
12
.catch(function (err) {
13
console.log('Error when subscribing to live updates for Bob', err);
14
});
using-empty-string-for-wildcard-search page anchor

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

1
const SyncClient = require('twilio-sync');
2
3
syncClient.liveQuery('tr-worker', '')
4
.then(function (args) {
5
console.log('Subscribed to live data updates for workers');
6
let items = args.getItems();
7
Object.entries(items).forEach(([key, value]) => {
8
console.log('Search result item key: ' + key);
9
console.log('Search result item value: ' + value);
10
});
11
})
12
.catch(function (err) {
13
console.log('Error when subscribing to live updates', err);
14
});;

Need some help?

Terms of service

Copyright © 2024 Twilio Inc.