Merge pull request #6402 from Budibase/bug/sev2/sql-server-int-filter-range-validation
External data source plus - Integer filter range validation
This commit is contained in:
commit
cb4fa33d73
|
@ -54,8 +54,9 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
const onFieldChange = (expression, field) => {
|
const onFieldChange = (expression, field) => {
|
||||||
// Update the field type
|
// Update the field types
|
||||||
expression.type = enrichedSchemaFields.find(x => x.name === field)?.type
|
expression.type = enrichedSchemaFields.find(x => x.name === field)?.type
|
||||||
|
expression.externalType = getSchema(expression)?.externalType
|
||||||
|
|
||||||
// Ensure a valid operator is set
|
// Ensure a valid operator is set
|
||||||
const validOperators = LuceneUtils.getValidOperatorsForType(
|
const validOperators = LuceneUtils.getValidOperatorsForType(
|
||||||
|
|
|
@ -63,3 +63,25 @@ export const TableNames = {
|
||||||
* - Coerce types for search endpoint
|
* - Coerce types for search endpoint
|
||||||
*/
|
*/
|
||||||
export const ApiVersion = "1"
|
export const ApiVersion = "1"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Maximum minimum range for SQL number values
|
||||||
|
*/
|
||||||
|
export const SqlNumberTypeRangeMap = {
|
||||||
|
integer: {
|
||||||
|
max: 2147483647,
|
||||||
|
min: -2147483648,
|
||||||
|
},
|
||||||
|
int: {
|
||||||
|
max: 2147483647,
|
||||||
|
min: -2147483648,
|
||||||
|
},
|
||||||
|
smallint: {
|
||||||
|
max: 32767,
|
||||||
|
min: -32768,
|
||||||
|
},
|
||||||
|
mediumint: {
|
||||||
|
max: 8388607,
|
||||||
|
min: -8388608,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { Helpers } from "@budibase/bbui"
|
import { Helpers } from "@budibase/bbui"
|
||||||
import { OperatorOptions } from "../constants"
|
import { OperatorOptions, SqlNumberTypeRangeMap } from "../constants"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the valid operator options for a certain data type
|
* Returns the valid operator options for a certain data type
|
||||||
|
@ -94,7 +94,7 @@ export const buildLuceneQuery = filter => {
|
||||||
}
|
}
|
||||||
if (Array.isArray(filter)) {
|
if (Array.isArray(filter)) {
|
||||||
filter.forEach(expression => {
|
filter.forEach(expression => {
|
||||||
let { operator, field, type, value } = expression
|
let { operator, field, type, value, externalType } = expression
|
||||||
// Parse all values into correct types
|
// Parse all values into correct types
|
||||||
if (type === "datetime" && value) {
|
if (type === "datetime" && value) {
|
||||||
value = new Date(value).toISOString()
|
value = new Date(value).toISOString()
|
||||||
|
@ -106,16 +106,14 @@ export const buildLuceneQuery = filter => {
|
||||||
value = `${value}`?.toLowerCase() === "true"
|
value = `${value}`?.toLowerCase() === "true"
|
||||||
}
|
}
|
||||||
if (operator.startsWith("range")) {
|
if (operator.startsWith("range")) {
|
||||||
|
const minint =
|
||||||
|
SqlNumberTypeRangeMap[externalType]?.min || Number.MIN_SAFE_INTEGER
|
||||||
|
const maxint =
|
||||||
|
SqlNumberTypeRangeMap[externalType]?.max || Number.MAX_SAFE_INTEGER
|
||||||
if (!query.range[field]) {
|
if (!query.range[field]) {
|
||||||
query.range[field] = {
|
query.range[field] = {
|
||||||
low:
|
low: type === "number" ? minint : "0000-00-00T00:00:00.000Z",
|
||||||
type === "number"
|
high: type === "number" ? maxint : "9999-00-00T00:00:00.000Z",
|
||||||
? Number.MIN_SAFE_INTEGER
|
|
||||||
: "0000-00-00T00:00:00.000Z",
|
|
||||||
high:
|
|
||||||
type === "number"
|
|
||||||
? Number.MAX_SAFE_INTEGER
|
|
||||||
: "9999-00-00T00:00:00.000Z",
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (operator === "rangeLow" && value != null && value !== "") {
|
if (operator === "rangeLow" && value != null && value !== "") {
|
||||||
|
|
|
@ -246,6 +246,7 @@ module MSSQLModule {
|
||||||
autocolumn: !!autoColumns.find((col: string) => col === name),
|
autocolumn: !!autoColumns.find((col: string) => col === name),
|
||||||
name: name,
|
name: name,
|
||||||
...convertSqlType(def.DATA_TYPE),
|
...convertSqlType(def.DATA_TYPE),
|
||||||
|
externalType: def.DATA_TYPE,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
tables[tableName] = {
|
tables[tableName] = {
|
||||||
|
|
|
@ -232,6 +232,7 @@ module MySQLModule {
|
||||||
autocolumn: isAuto,
|
autocolumn: isAuto,
|
||||||
constraints,
|
constraints,
|
||||||
...convertSqlType(column.Type),
|
...convertSqlType(column.Type),
|
||||||
|
externalType: column.Type,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!tables[tableName]) {
|
if (!tables[tableName]) {
|
||||||
|
|
|
@ -271,6 +271,7 @@ module PostgresModule {
|
||||||
autocolumn: isAuto,
|
autocolumn: isAuto,
|
||||||
name: columnName,
|
name: columnName,
|
||||||
...convertSqlType(column.data_type),
|
...convertSqlType(column.data_type),
|
||||||
|
externalType: column.data_type,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue