Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nc fix: add missing formula docs and link #7987

Merged
merged 7 commits into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ onMounted(() => {
</div>
</div>
<div class="flex flex-row mt-1 mb-3 justify-end pr-3">
<a target="_blank" rel="noopener noreferrer" :href="suggestionPreviewed.docsUrl">
<a v-if="suggestionPreviewed.docsUrl" target="_blank" rel="noopener noreferrer" :href="suggestionPreviewed.docsUrl">
<NcButton type="text" class="!text-gray-400 !hover:text-gray-800 !text-xs"
>View in Docs
<GeneralIcon icon="openInNew" class="ml-1" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ DATETIME_DIFF("2022/10/14", "2022/10/15", "seconds") => -86400
```

#### Remark
This function compares two dates and returns the difference in the specified unit. Positive integers indicate that second date is in the past compared to first, and vice versa for negative values.
This function compares two dates and returns the difference in the specified unit. Positive integers indicate that the second date is in the past compared to the first, and vice versa for negative values.

---

Expand Down Expand Up @@ -94,6 +94,80 @@ Returns the day of the week as an integer between 0 and 6 (inclusive), with Mond

---

## DATESTR
The DATESTR function converts a date or datetime field into a string in "YYYY-MM-DD" format.

#### Syntax
```plaintext
DATESTR(date | datetime)
```

#### Sample
```plaintext
DATESTR('2022-03-14') => 2022-03-14
DATESTR('2022-03-14 12:00:00') => 2022-03-14
```

#### Remark
This function converts a date or datetime field into a string in "YYYY-MM-DD" format, ignoring the time part.

---

## DAY
The DAY function returns the day of the month as an integer.

#### Syntax
```plaintext
DAY(date | datetime)
```

#### Sample
```plaintext
DAY('2022-03-14') => 14
DAY('2022-03-14 12:00:00') => 14
```

#### Remark
This function returns the day of the month as an integer between 1 and 31 (inclusive).

---

## MONTH
The MONTH function returns the month of the year as an integer.

#### Syntax
```plaintext
MONTH(date | datetime)
```

#### Sample
```plaintext
MONTH('2022-03-14') => 3
MONTH('2022-03-14 12:00:00') => 3
```

#### Remark
This function returns the month of the year as an integer between 1 and 12 (inclusive).

---

## HOUR
The HOUR function returns the hour of the day as an integer.

#### Syntax
```plaintext
HOUR(datetime)
```

#### Sample
```plaintext
HOUR('2022-03-14 12:00:00') => 12
```

#### Remark
This function returns the hour of the day as an integer between 0 and 23 (inclusive).

---

## Related Articles
- [Numeric and Logical Operators](015.operators.md)
rameshmane7218 marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
title: 'Generic Functions'
description: 'This article explains system functions & miscellaneous functions that can be used in formula fields.'
tags: ['Fields', 'Field types', 'Formula']
keywords: ['Fields', 'Field types', 'Formula', 'Create formula field', 'System functions', 'Miscellaneous functions']
---

# System Functions

## RECORD_ID

The `RECORD_ID` function returns the unique identifier of the record.

#### Syntax
```plaintext
RECORD_ID()
```

#### Sample
```plaintext
RECORD_ID() => 1
```

---
18 changes: 14 additions & 4 deletions packages/nocodb-sdk/src/lib/formulaHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,8 @@ interface FormulaMeta {

export const formulas: Record<string, FormulaMeta> = {
AVG: {
docsUrl:
'https://docs.nocodb.com/fields/field-types/formula/numeric-functions#avg',
validation: {
args: {
min: 1,
Expand All @@ -296,10 +298,10 @@ export const formulas: Record<string, FormulaMeta> = {
'AVG({column1}, {column2}, {column3})',
],
returnType: FormulaDataTypes.NUMERIC,
docsUrl:
'https://docs.nocodb.com/fields/field-types/formula/numeric-functions#avg',
},
ADD: {
docsUrl:
'https://docs.nocodb.com/fields/field-types/formula/numeric-functions#add',
validation: {
args: {
min: 1,
Expand All @@ -314,8 +316,6 @@ export const formulas: Record<string, FormulaMeta> = {
'ADD({column1}, {column2}, {column3})',
],
returnType: FormulaDataTypes.NUMERIC,
docsUrl:
'https://docs.nocodb.com/fields/field-types/formula/numeric-functions#add',
},
DATEADD: {
docsUrl:
Expand Down Expand Up @@ -376,6 +376,8 @@ export const formulas: Record<string, FormulaMeta> = {
returnType: FormulaDataTypes.DATE,
},
DATESTR: {
docsUrl:
'https://docs.nocodb.com/fields/field-types/formula/date-functions#datestr',
validation: {
args: {
rqd: 1,
Expand All @@ -387,6 +389,8 @@ export const formulas: Record<string, FormulaMeta> = {
returnType: FormulaDataTypes.STRING,
},
DAY: {
docsUrl:
'https://docs.nocodb.com/fields/field-types/formula/date-functions#day',
validation: {
args: {
rqd: 1,
Expand All @@ -398,6 +402,8 @@ export const formulas: Record<string, FormulaMeta> = {
returnType: FormulaDataTypes.STRING,
},
MONTH: {
docsUrl:
'https://docs.nocodb.com/fields/field-types/formula/date-functions#month',
validation: {
args: {
rqd: 1,
Expand All @@ -409,6 +415,8 @@ export const formulas: Record<string, FormulaMeta> = {
returnType: FormulaDataTypes.STRING,
},
HOUR: {
docsUrl:
'https://docs.nocodb.com/fields/field-types/formula/date-functions#hour',
validation: {
args: {
rqd: 1,
Expand Down Expand Up @@ -1171,6 +1179,8 @@ export const formulas: Record<string, FormulaMeta> = {
syntax: 'REGEX_MATCH(string, regex)',
examples: ['REGEX_MATCH({title}, "abc.*")'],
returnType: FormulaDataTypes.NUMERIC,
docsUrl:
'https://docs.nocodb.com/fields/field-types/formula/string-functions#regex_match',
},

REGEX_EXTRACT: {
Expand Down