Export & Cache
Once a query has run, the result set is more than something to look at — you can take the data with you and reuse it programmatically.
Getting the data out
There are two complementary ways to get a result set out of Kvery:
- From the result view — download the rows as a file with the CSV or Excel button above the table, for quick, one-off needs. The buttons are on the query's run page, its shared page and dashboard tiles; the result beside the editor and the Kvery mobile app have none.
- As an API response — publish the query and call its endpoint to receive the same rows as JSON. This is the right approach for anything repeatable: spreadsheets, scripts, or another service.
An export from the result view contains every row that matches the table's search
(on all pages), in the table's current order, and every column of the result —
also hidden:: columns and columns hidden with Columns. Long values are
exported in full. The file is named after the page: the query's description
followed by the Kvery host (<description> - app.kvery.io.csv or .xlsx), with
the characters other than letters, digits, spaces and _ . , - ! ( ) left out. A
CSV file is UTF-8 encoded; an Excel sheet has a filter on its header row.
Column modifiers do not shape the API output: the
JSON contains every column of the result, hidden:: columns too. With the query's
Slug JSON keys (response time may be slower) option, which is on for new
queries, the keys are slugs of the column names without the modifier prefixes, and
JSON text values are returned as nested JSON; with it off, each key keeps its
prefix (for example hidden::password_hash). In the result view, hidden:: only
hides a column when the table opens. Leave columns that must not leave the
database out of the SELECT.
In a CSV file exported from the result view, a text value that a spreadsheet
would run as a formula — one starting with =, +, -, @, a tab or a carriage
return — gets a leading apostrophe ('), so it stays plain text. A value starting
with + or - is kept as it is when it contains nothing but digits, spaces (also
no-break spaces), an exponent (such as 1.5e-7) and the characters
+ - . , % : / ( ): numbers such as -5, +3.2 or -1,5, phone numbers such as
+36 30 123 4567 and times such as -01:30:00. The header row, which holds the
column names, gets the same protection as the cells. An Excel export keeps
every value as data and contains no formulas.
Result caching
The result cache is opt-in per query: set Cache expiration in seconds in the
query's settings (0 = disabled). It works only for GET requests. While a cached
result has not expired, a run with the same request values gets it without
querying the database — re-running the query returns the cached result too, because
an entry is not replaced before it expires. Add ?cache=0 to the URL to bypass the
cache (runs in the editor always do), or remove the stored results with the query's
Clear cache button. Dashboard tiles are served from
the cache as well.
When a result comes from the cache, the query's run page shows (cached) next to its description. Queries with a cache time have a Cached icon in the Queries list. Clear cache is offered to the editors of the query; it asks "Are you sure you want to clear the cache?" and answers "Cache was cleared!".
Cached results of runs by a signed-in user are kept per user, and runs of the
published version are cached separately from runs of a
draft. A query that uses the
:log variable is not
cached, because its result depends on the caller.
Large result sets
The result view is paginated (25 rows per page by default) so the UI stays fast
no matter how many rows match. If you need every row in another system, call
the public API: it returns the whole result in one
response and has no paging of its own (?ri= only selects a single row by its
index). To fetch the rows in pages, add your own LIMIT / OFFSET parameters to
the query, or narrow it with WHERE / LIMIT so you only pull what you need.
Aggregate and filter in SQL before exporting. Pulling a pre-summarised result is far faster and cheaper than exporting raw rows and crunching them elsewhere.