Query preview sort by number for number types

This commit is contained in:
Mel O'Hagan 2022-05-03 15:52:03 +01:00
parent f72fe95fc8
commit 41b72027c4
1 changed files with 15 additions and 0 deletions

View File

@ -44,6 +44,21 @@
$: readQuery = query.queryVerb === "read" || query.readable $: readQuery = query.queryVerb === "read" || query.readable
$: queryInvalid = !query.name || (readQuery && data.length === 0) $: queryInvalid = !query.name || (readQuery && data.length === 0)
//Cast field in query preview response to number if specified by schema
$: {
for (let i = 0; i < data.length; i++) {
let row = data[i]
for (let fieldNameIndex in Object.keys(fields)) {
let fieldName = Object.keys(fields)[fieldNameIndex]
if (fields[fieldName] === "number" && !isNaN(Number(row[fieldName]))) {
row[fieldName] = Number(row[fieldName])
} else {
row[fieldName] = row[fieldName]?.toString()
}
}
}
}
// seed the transformer // seed the transformer
if (query && !query.transformer) { if (query && !query.transformer) {
query.transformer = "return data" query.transformer = "return data"