mirror of https://github.com/nocodb/nocodb
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
494 lines
11 KiB
494 lines
11 KiB
3 years ago
|
const formulaTypes = {
|
||
3 years ago
|
NUMERIC: "numeric",
|
||
3 years ago
|
STRING: "string",
|
||
|
DATE: "date",
|
||
|
LOGICAL: "logical",
|
||
|
COND_EXP: "conditional_expression"
|
||
|
}
|
||
|
|
||
3 years ago
|
const formulas = {
|
||
3 years ago
|
AVG: {
|
||
3 years ago
|
type: formulaTypes.NUMERIC,
|
||
3 years ago
|
validation: {
|
||
3 years ago
|
args: {
|
||
|
min: 1
|
||
|
}
|
||
|
},
|
||
|
description: 'Average of input parameters',
|
||
|
syntax: 'AVG(value1, [value2, ...])',
|
||
|
examples: [
|
||
|
'AVG(10, 5) => 7.5',
|
||
|
'AVG({column1}, {column2})',
|
||
|
'AVG({column1}, {column2}, {column3})'
|
||
|
]
|
||
3 years ago
|
},
|
||
|
ADD: {
|
||
3 years ago
|
type: formulaTypes.NUMERIC,
|
||
3 years ago
|
validation: {
|
||
3 years ago
|
args: {
|
||
|
min: 1
|
||
|
}
|
||
|
},
|
||
|
description: 'Sum of input parameters',
|
||
|
syntax: 'ADD(value1, [value2, ...])',
|
||
|
examples: [
|
||
|
'ADD(5, 5) => 10',
|
||
|
'ADD({column1}, {column2})',
|
||
|
'ADD({column1}, {column2}, {column3})'
|
||
|
]
|
||
|
},
|
||
|
DATEADD: {
|
||
3 years ago
|
type: formulaTypes.DATE,
|
||
3 years ago
|
validation: {
|
||
|
args: {
|
||
|
rqd: 3
|
||
|
}
|
||
|
},
|
||
|
description: 'Adds a "count" units to Datetime.',
|
||
|
syntax: 'DATEADD(date | datetime, value, ["day" | "week" | "month" | "year"])',
|
||
|
examples: [
|
||
|
'DATEADD({column1}, 2, "day")',
|
||
|
'DATEADD({column1}, -2, "day")',
|
||
|
'DATEADD({column1}, 2, "week")',
|
||
|
'DATEADD({column1}, -2, "week")',
|
||
|
'DATEADD({column1}, 2, "month")',
|
||
|
'DATEADD({column1}, -2, "month")',
|
||
|
'DATEADD({column1}, 2, "year")',
|
||
|
'DATEADD({column1}, -2, "year")'
|
||
|
]
|
||
3 years ago
|
},
|
||
3 years ago
|
AND: {
|
||
3 years ago
|
type: formulaTypes.COND_EXP,
|
||
3 years ago
|
validation: {
|
||
3 years ago
|
args: {
|
||
|
min: 1
|
||
|
}
|
||
|
},
|
||
|
description: 'TRUE if all expr evaluate to TRUE',
|
||
|
syntax: 'AND(expr1, [expr2, ...])',
|
||
|
examples: [
|
||
|
'AND(5 > 2, 5 < 10) => 1',
|
||
|
'AND({column1} > 2, {column2} < 10)'
|
||
|
]
|
||
3 years ago
|
},
|
||
|
OR: {
|
||
3 years ago
|
type: formulaTypes.COND_EXP,
|
||
3 years ago
|
validation: {
|
||
3 years ago
|
args: {
|
||
|
min: 1
|
||
|
}
|
||
|
},
|
||
|
description: 'TRUE if at least one expr evaluates to TRUE',
|
||
|
syntax: 'OR(expr1, [expr2, ...])',
|
||
|
examples: [
|
||
|
'OR(5 > 2, 5 < 10) => 1',
|
||
|
'OR({column1} > 2, {column2} < 10)'
|
||
|
]
|
||
3 years ago
|
},
|
||
3 years ago
|
CONCAT: {
|
||
3 years ago
|
type: formulaTypes.STRING,
|
||
3 years ago
|
validation: {
|
||
|
args: {
|
||
|
min: 1
|
||
|
}
|
||
|
},
|
||
|
description: 'Concatenated string of input parameters',
|
||
|
syntax: 'CONCAT(str1, [str2, ...])',
|
||
|
examples: [
|
||
|
'CONCAT("AA", "BB", "CC") => "AABBCC"',
|
||
|
'CONCAT({column1}, {column2}, {column3})'
|
||
|
]
|
||
3 years ago
|
},
|
||
|
TRIM: {
|
||
3 years ago
|
type: formulaTypes.STRING,
|
||
3 years ago
|
validation: {
|
||
|
args: {
|
||
|
rqd: 1
|
||
|
}
|
||
|
},
|
||
|
description: 'Remove trailing and leading whitespaces from input parameter',
|
||
|
syntax: 'TRIM(str)',
|
||
|
examples: [
|
||
|
'TRIM(" HELLO WORLD ") => "HELLO WORLD"',
|
||
|
'TRIM({column1})'
|
||
|
]
|
||
3 years ago
|
},
|
||
|
UPPER: {
|
||
3 years ago
|
type: formulaTypes.STRING,
|
||
3 years ago
|
validation: {
|
||
|
args: {
|
||
|
rqd: 1
|
||
|
}
|
||
|
},
|
||
|
description: 'Upper case converted string of input parameter',
|
||
|
syntax: 'UPPER(str)',
|
||
|
examples: [
|
||
|
'UPPER("nocodb") => "NOCODB"',
|
||
|
'UPPER({column1})'
|
||
|
]
|
||
|
},
|
||
|
LOWER: {
|
||
3 years ago
|
type: formulaTypes.STRING,
|
||
3 years ago
|
validation: {
|
||
|
args: {
|
||
|
rqd: 1
|
||
|
}
|
||
|
},
|
||
|
description: 'Lower case converted string of input parameter',
|
||
|
syntax: 'LOWER(str)',
|
||
|
examples: [
|
||
|
'LOWER("NOCODB") => "nocodb"',
|
||
|
'LOWER({column1})'
|
||
|
]
|
||
|
},
|
||
|
LEN: {
|
||
3 years ago
|
type: formulaTypes.STRING,
|
||
3 years ago
|
validation: {
|
||
|
args: {
|
||
|
rqd: 1
|
||
|
}
|
||
|
},
|
||
|
description: 'Input parameter character length',
|
||
|
syntax: 'LEN(value)',
|
||
|
examples: [
|
||
|
'LEN("NocoDB") => 6',
|
||
|
'LEN({column1})'
|
||
|
]
|
||
|
},
|
||
|
MIN: {
|
||
3 years ago
|
type: formulaTypes.NUMERIC,
|
||
3 years ago
|
validation: {
|
||
|
args: {
|
||
|
min: 1
|
||
|
}
|
||
|
},
|
||
|
description: 'Minimum value amongst input parameters',
|
||
|
syntax: 'MIN(value1, [value2, ...])',
|
||
|
examples: [
|
||
|
'MIN(1000, 2000) => 1000',
|
||
|
'MIN({column1}, {column2})'
|
||
|
]
|
||
|
},
|
||
|
MAX: {
|
||
3 years ago
|
type: formulaTypes.NUMERIC,
|
||
3 years ago
|
validation: {
|
||
|
args: {
|
||
|
min: 1
|
||
|
}
|
||
|
},
|
||
|
description: 'Maximum value amongst input parameters',
|
||
|
syntax: 'MAX(value1, [value2, ...])',
|
||
|
examples: [
|
||
|
'MAX(1000, 2000) => 2000',
|
||
|
'MAX({column1}, {column2})'
|
||
|
]
|
||
|
},
|
||
|
CEILING: {
|
||
3 years ago
|
type: formulaTypes.NUMERIC,
|
||
3 years ago
|
validation: {
|
||
|
args: {
|
||
|
rqd: 1
|
||
|
}
|
||
|
},
|
||
|
description: 'Rounded next largest integer value of input parameter',
|
||
|
syntax: 'CEILING(value)',
|
||
|
examples: [
|
||
|
'CEILING(1.01) => 2',
|
||
|
'CEILING({column1})'
|
||
|
]
|
||
|
},
|
||
|
FLOOR: {
|
||
3 years ago
|
type: formulaTypes.NUMERIC,
|
||
3 years ago
|
validation: {
|
||
|
args: {
|
||
|
rqd: 1
|
||
|
}
|
||
|
},
|
||
|
description: 'Rounded largest integer less than or equal to input parameter',
|
||
|
syntax: 'FLOOR(value)',
|
||
|
examples: [
|
||
|
'FLOOR(3.1415) => 3',
|
||
|
'FLOOR({column1})'
|
||
|
]
|
||
|
},
|
||
|
ROUND: {
|
||
3 years ago
|
type: formulaTypes.NUMERIC,
|
||
3 years ago
|
validation: {
|
||
|
args: {
|
||
|
rqd: 1
|
||
|
}
|
||
|
},
|
||
|
description: 'Nearest integer to the input parameter',
|
||
|
syntax: 'ROUND(value)',
|
||
|
examples: [
|
||
|
'ROUND(3.1415) => 3',
|
||
|
'ROUND({column1})'
|
||
|
]
|
||
|
},
|
||
|
MOD: {
|
||
3 years ago
|
type: formulaTypes.NUMERIC,
|
||
3 years ago
|
validation: {
|
||
|
args: {
|
||
|
rqd: 2
|
||
|
}
|
||
|
},
|
||
|
description: 'Remainder after integer division of input parameters',
|
||
|
syntax: 'MOD(value1, value2)',
|
||
|
examples: [
|
||
|
'MOD(1024, 1000) => 24',
|
||
|
'MOD({column}, 2)'
|
||
|
]
|
||
|
},
|
||
|
REPEAT: {
|
||
3 years ago
|
type: formulaTypes.STRING,
|
||
3 years ago
|
validation: {
|
||
|
args: {
|
||
|
rqd: 2
|
||
|
}
|
||
|
},
|
||
|
description: 'Specified copies of the input parameter string concatenated together',
|
||
|
syntax: 'REPEAT(str, count)',
|
||
|
examples: [
|
||
|
'REPEAT("A", 5) => "AAAAA"',
|
||
|
'REPEAT({column}, 5)'
|
||
|
]
|
||
|
},
|
||
|
LOG: {
|
||
3 years ago
|
type: formulaTypes.NUMERIC,
|
||
3 years ago
|
validation: {},
|
||
|
description: 'Logarithm of input parameter to the base (default = e) specified',
|
||
|
syntax: 'LOG([base], value)',
|
||
|
examples: [
|
||
|
'LOG(2, 1024) => 10',
|
||
|
'LOG(2, {column1})'
|
||
|
]
|
||
|
},
|
||
|
EXP: {
|
||
3 years ago
|
type: formulaTypes.NUMERIC,
|
||
3 years ago
|
validation: {},
|
||
|
description: 'Exponential value of input parameter (e ^ power)',
|
||
|
syntax: 'EXP(power)',
|
||
|
examples: [
|
||
|
'EXP(1) => 2.718281828459045',
|
||
|
'EXP({column1})'
|
||
|
]
|
||
|
},
|
||
|
POWER: {
|
||
3 years ago
|
type: formulaTypes.NUMERIC,
|
||
3 years ago
|
validation: {
|
||
|
args: {
|
||
|
rqd: 2
|
||
|
}
|
||
|
},
|
||
|
description: 'base to the exponent power, as in base ^ exponent',
|
||
|
syntax: 'POWER(base, exponent)',
|
||
|
examples: [
|
||
|
'POWER(2, 10) => 1024',
|
||
|
'POWER({column1}, 10)'
|
||
|
]
|
||
|
},
|
||
|
SQRT: {
|
||
3 years ago
|
type: formulaTypes.NUMERIC,
|
||
3 years ago
|
validation: {
|
||
|
args: {
|
||
|
rqd: 1
|
||
|
}
|
||
|
},
|
||
|
description: 'Square root of the input parameter',
|
||
|
syntax: 'SQRT(value)',
|
||
|
examples: [
|
||
|
'SQRT(100) => 10',
|
||
|
'SQRT({column1})'
|
||
|
]
|
||
|
},
|
||
|
ABS: {
|
||
3 years ago
|
type: formulaTypes.NUMERIC,
|
||
3 years ago
|
validation: {
|
||
|
args: {
|
||
|
rqd: 1
|
||
|
}
|
||
|
},
|
||
|
description: 'Absolute value of the input parameter',
|
||
|
syntax: 'ABS(value)',
|
||
|
examples: [
|
||
|
'ABS({column1})'
|
||
|
]
|
||
|
},
|
||
|
NOW: {
|
||
3 years ago
|
type: formulaTypes.DATE,
|
||
3 years ago
|
validation: {
|
||
|
args: {
|
||
|
rqd: 0
|
||
|
}
|
||
|
},
|
||
|
description: 'Returns the current time and day',
|
||
|
syntax: 'NOW()',
|
||
|
examples: [
|
||
|
'NOW() => 2022-05-19 17:20:43'
|
||
|
]
|
||
|
},
|
||
|
REPLACE: {
|
||
3 years ago
|
type: formulaTypes.STRING,
|
||
3 years ago
|
validation: {
|
||
|
args: {
|
||
|
rqd: 3
|
||
|
}
|
||
|
},
|
||
|
description: 'String, after replacing all occurrences of srchStr with rplcStr',
|
||
|
syntax: 'REPLACE(str, srchStr, rplcStr)',
|
||
|
examples: [
|
||
|
'REPLACE("AABBCC", "AA", "BB") => "BBBBCC"',
|
||
|
'REPLACE({column1}, {column2}, {column3})'
|
||
|
]
|
||
|
},
|
||
|
SEARCH: {
|
||
3 years ago
|
type: formulaTypes.STRING,
|
||
3 years ago
|
validation: {
|
||
|
args: {
|
||
|
rqd: 2
|
||
|
}
|
||
|
},
|
||
|
description: 'Index of srchStr specified if found, 0 otherwise',
|
||
|
syntax: 'SEARCH(str, srchStr)',
|
||
|
examples: [
|
||
|
'SEARCH("HELLO WORLD", "WORLD") => 7',
|
||
|
'SEARCH({column1}, "abc")'
|
||
|
]
|
||
|
},
|
||
|
INT: {
|
||
3 years ago
|
type: formulaTypes.NUMERIC,
|
||
3 years ago
|
validation: {
|
||
|
args: {
|
||
|
rqd: 1
|
||
|
}
|
||
|
},
|
||
|
description: 'Integer value of input parameter',
|
||
|
syntax: 'INT(value)',
|
||
|
examples: [
|
||
|
'INT(3.1415) => 3',
|
||
|
'INT({column1})'
|
||
|
]
|
||
|
},
|
||
|
RIGHT: {
|
||
3 years ago
|
type: formulaTypes.STRING,
|
||
3 years ago
|
validation: {
|
||
|
args: {
|
||
|
rqd: 2
|
||
|
}
|
||
|
},
|
||
|
description: 'n characters from the end of input parameter',
|
||
|
syntax: 'RIGHT(str, n)',
|
||
|
examples: [
|
||
|
'RIGHT("HELLO WORLD", 5) => WORLD',
|
||
|
'RIGHT({column1}, 3)'
|
||
|
]
|
||
|
},
|
||
3 years ago
|
LEFT: {
|
||
3 years ago
|
type: formulaTypes.STRING,
|
||
3 years ago
|
validation: {
|
||
|
args: {
|
||
|
rqd: 2
|
||
|
}
|
||
|
},
|
||
|
description: 'n characters from the beginning of input parameter',
|
||
|
syntax: 'LEFT(str, n)',
|
||
|
examples: [
|
||
|
'LEFT({column1}, 2)',
|
||
|
'LEFT("ABCD", 2) => "AB"'
|
||
|
]
|
||
3 years ago
|
},
|
||
3 years ago
|
SUBSTR: {
|
||
3 years ago
|
type: formulaTypes.STRING,
|
||
3 years ago
|
validation: {
|
||
|
args: {
|
||
|
min: 2,
|
||
|
max: 3
|
||
|
}
|
||
|
},
|
||
|
description: 'Substring of length n of input string from the postition specified',
|
||
|
syntax: ' SUBTR(str, position, [n])',
|
||
|
examples: [
|
||
|
'SUBSTR("HELLO WORLD", 7) => WORLD',
|
||
|
'SUBSTR("HELLO WORLD", 7, 3) => WOR',
|
||
|
'SUBSTR({column1}, 7, 5)'
|
||
|
]
|
||
|
},
|
||
|
MID: {
|
||
3 years ago
|
type: formulaTypes.STRING,
|
||
3 years ago
|
validation: {
|
||
|
args: {
|
||
|
rqd: 3
|
||
|
}
|
||
|
},
|
||
|
description: 'Alias for SUBSTR',
|
||
|
syntax: 'MID(str, position, [count])',
|
||
|
examples: [
|
||
|
'MID("NocoDB", 3, 2) => "co"',
|
||
|
'MID({column1}, 3, 2)'
|
||
|
]
|
||
|
},
|
||
|
IF: {
|
||
3 years ago
|
type: formulaTypes.COND_EXP,
|
||
3 years ago
|
validation: {
|
||
|
args: {
|
||
|
min: 2,
|
||
|
max: 3
|
||
|
}
|
||
|
},
|
||
|
description: 'SuccessCase if expr evaluates to TRUE, elseCase otherwise',
|
||
|
syntax: 'IF(expr, successCase, elseCase)',
|
||
|
examples: [
|
||
|
'IF(5 > 1, "YES", "NO") => "YES"',
|
||
|
'IF({column} > 1, "YES", "NO")'
|
||
|
]
|
||
|
},
|
||
|
SWITCH: {
|
||
3 years ago
|
type: formulaTypes.COND_EXP,
|
||
3 years ago
|
validation: {
|
||
|
args: {
|
||
|
min: 3
|
||
|
}
|
||
|
},
|
||
|
description: 'Switch case value based on expr output',
|
||
|
syntax: 'SWITCH(expr, [pattern, value, ..., default])',
|
||
|
examples: [
|
||
|
'SWITCH(1, 1, "One", 2, "Two", "N/A") => "One""',
|
||
|
'SWITCH(2, 1, "One", 2, "Two", "N/A") => "Two"',
|
||
|
'SWITCH(3, 1, "One", 2, "Two", "N/A") => "N/A"',
|
||
|
'SWITCH({column1}, 1, "One", 2, "Two", "N/A")'
|
||
|
]
|
||
|
},
|
||
|
URL: {
|
||
3 years ago
|
type: formulaTypes.STRING,
|
||
3 years ago
|
validation: {
|
||
|
args: {
|
||
|
rqd: 1
|
||
|
}
|
||
|
},
|
||
|
description: 'Convert to a hyperlink if it is a valid URL',
|
||
|
syntax: 'URL(str)',
|
||
|
examples: [
|
||
|
'URL("https://github.com/nocodb/nocodb")',
|
||
|
'URL({column1})'
|
||
|
]
|
||
3 years ago
|
},
|
||
|
WEEKDAY: {
|
||
|
type: formulaTypes.NUMERIC,
|
||
|
validation: {
|
||
|
args: {
|
||
|
min: 1,
|
||
|
max: 2,
|
||
|
}
|
||
|
},
|
||
2 years ago
|
description: 'Returns the day of the week as an integer between 0 and 6 inclusive starting from Monday by default',
|
||
3 years ago
|
syntax: 'WEEKDAY(date, [startDayOfWeek])',
|
||
|
examples: [
|
||
|
'WEEKDAY("2021-06-09")',
|
||
2 years ago
|
'WEEKDAY(NOW(), "sunday")'
|
||
3 years ago
|
]
|
||
3 years ago
|
}
|
||
3 years ago
|
}
|
||
3 years ago
|
|
||
3 years ago
|
export default Object.keys(formulas)
|
||
3 years ago
|
export { formulas, formulaTypes }
|