The Query object
Query object properties and JavaScript API methods.
Each Query object represents a query within an app, such as an SQL query or transformer. Each instance has a unique name with which to reference (e.g., getUsers.trigger()
).
Properties
dataany
The query results.
errorstring
The error message if the query was unsuccessful.
cacheKeyTtlnumber
The duration, in seconds, to cache query results.
confirmationMessagestring
The message to display in the confirmation modal before running the query, if query.requireConfirmation
is true
.
enableTransformerboolean
Whether a transformer is enabled.
eventsobject
Event handlers to trigger in response to query success or failure.
finishednumber
The UNIX timestamp specifying when the query finished executing.
idstring
The query name.
enableCachingboolean
Whether to cache query results.
isFetchingboolean
Whether the query is in the process of retrieving results.
isImportedboolean
Whether the query was imported from the Query Library.
lastReceivedFromResourceAtnumber
The UNIX timestamp the query was last received from the resource. If the query is cached, this is used with cacheKeyTtl
to determine whether to return results from the cache the next time the query runs.
notificationDurationnumber
The duration, in seconds, to display notifications on query success or failure.
pluginTypestring
The query type.
privateParamsobject
A list of parameters to exclude from audit logs.
querystring
The raw query string. For JavaScript and database queries, this is the entire query body. For REST API queries, this is the endpoint string.
queryDisabledboolean
Whether the query is disabled.
queryDisabledMessagestring
The message to display when a disabled query is triggered.
queryFailureConditionsobject[]
A list of conditions that determine if the query has failed.
conditionstring
The condition that determines if the query has failed.
messagestring
The notification message to display if the query fails based on this condition.
queryRefreshTimenumber
The frequency, in milliseconds, to run the query if it is set to run periodically.
queryRunTimenumber
The duration, in milliseconds, of the most recent query run.
queryTimeoutnumber
The duration, in milliseconds, to wait before the query times out. After 120 seconds (120000 ms), all queries time out, even if queryTimeout
is higher.
queryTriggerDelaynumber
The duration, in milliseconds, to delay before running event handlers on query success or failure.
rawDataany
The data returned from the query before any transformers are applied.
requestSentTimestampnumber
The Unix timestamp the query request was sent.
runWhenModelUpdatesboolean
Whether to automatically run the query when its parameters change.
runWhenPageLoadsboolean
Whether to automatically run the query when the app loads.
runWhenPageLoadsDelaynumber
The amount of time, in milliseconds, to delay running the query on page load.
servedFromCacheboolean
Whether the most recent query results were returned from the cache.
showFailureToasterboolean
Whether to show a notification on query failure.
showSuccessToasterboolean
Whether to show a notification on query success.
successMessagestring
The notification message to display on query success.
timestampnumber
The Unix timestamp the query began to run.
transformerstring
The contents of the query's transformer code.
updateSetValueDynamicallyboolean
Whether to sync component references from the query with the rest of the app.
Methods
Methods for interacting with queries. You can write JavaScript almost anywhere in Retool and use methods to manipulate data or components.
invalidateCache()
Declares the cached results of the query invalid. The next time the query is triggered, it will return fresh results.
Example
Invalidate the cache for the getUsers
query.
getUsers.invalidateCache();
reset()
Clear the data
and error
properties of the query.
Example
Clear the data
and error
properties of the getUsers
query. Returns a Promise
that resolves to the query's data
property.
getUsers.reset();
trigger()
Run the query.
options
object
Optional settings to use when triggering a query.
additionalScope
object
Additional context to pass to query.
onSuccess
function
Function to call after the query successfully returns.
onFailure
function
Function to call after the query unsuccessfully returns.
Example
Trigger getUserById
with additional scope, and call different functions if the query succeeds or fails.
const user = { id: 1, name: "test" };
await getUserById.trigger({
additionalScope: { userId: user.id },
onSuccess: function (data) {
console.log(data);
},
onFailure: function (error) {
console.log("Error");
},
});