Browse Source

feat: add MONTH?HOUR function support(PG) - WIP

pull/7268/head
Pranav C 11 months ago
parent
commit
688024077e
  1. 22
      packages/nocodb-sdk/src/lib/formulaHelpers.ts
  2. 18
      packages/nocodb/src/db/functionMappings/pg.ts

22
packages/nocodb-sdk/src/lib/formulaHelpers.ts

@ -402,10 +402,30 @@ const formulas: Record<string, FormulaMeta> = {
rqd: 1,
},
},
description: 'Formats a datetime into a string (YYYY-MM-DD)',
description: 'Extract day from a date(1-31)',
examples: ['DATESTR({column1})'],
returnType: FormulaDataTypes.STRING,
},
MONTH: {
validation: {
args: {
rqd: 1,
},
},
description: 'Extract month from a date(1-12)',
examples: ['MONTH({column1})'],
returnType: FormulaDataTypes.STRING,
},
HOUR: {
validation: {
args: {
rqd: 1,
},
},
description: 'Extract hour from a datetime(0-23)',
examples: ['HOUR({column1})'],
returnType: FormulaDataTypes.STRING,
},
DATETIME_DIFF: {
validation: {
args: {

18
packages/nocodb/src/db/functionMappings/pg.ts

@ -152,6 +152,24 @@ const pg = {
),
};
},
MONTH: async ({ fn, knex, pt, colAlias }: MapFnArgs) => {
return {
builder: knex.raw(
`EXTRACT('Month' FROM DATE ${
(await fn(pt?.arguments[0])).builder
}) ${colAlias}`,
),
};
},
HOUR: async ({ fn, knex, pt, colAlias }: MapFnArgs) => {
return {
builder: knex.raw(
`EXTRACT('Hour' FROM (${
(await fn(pt?.arguments[0])).builder
})::TIMESTAMP) ${colAlias}`,
),
};
},
AND: async (args: MapFnArgs) => {
return {
builder: args.knex.raw(

Loading…
Cancel
Save