Browse Source

fix: using functions for DATEADD interval

Signed-off-by: mertmit <mertmit99@gmail.com>
pull/1877/head
mertmit 2 years ago
parent
commit
9dfa2845bb
  1. 13
      packages/nocodb/src/lib/dataMapper/lib/sql/functionMappings/pg.ts
  2. 4
      packages/nocodb/src/lib/dataMapper/lib/sql/functionMappings/sqlite.ts

13
packages/nocodb/src/lib/dataMapper/lib/sql/functionMappings/pg.ts

@ -35,17 +35,8 @@ const pg = {
},
DATEADD: ({ fn, knex, pt, colAlias }: MapFnArgs) => {
return knex.raw(
`CASE
WHEN CAST(${fn(pt.arguments[0])} AS text) LIKE '%:%' THEN
${fn(pt.arguments[0])} + INTERVAL '${fn(pt.arguments[1])}
${String(fn(pt.arguments[2])).replace(
/["']/g,
''
)}'
ELSE
${fn(pt.arguments[0])} + INTERVAL '${fn(pt.arguments[1])}
${String(fn(pt.arguments[2])).replace(/["']/g, '')}'
END${colAlias}`
`${fn(pt.arguments[0])} + (${fn(pt.arguments[1])} ||
'${String(fn(pt.arguments[2])).replace(/["']/g, '')}')::interval${colAlias}`
);
}
};

4
packages/nocodb/src/lib/dataMapper/lib/sql/functionMappings/sqlite.ts

@ -64,13 +64,13 @@ const sqlite3 = {
STRFTIME('%Y-%m-%d %H:%M', DATETIME(DATETIME(${fn(
pt.arguments[0]
)}, 'localtime'),
'${dateIN > 0 ? '+' : ''}${fn(pt.arguments[1])} ${String(fn(pt.arguments[2])).replace(
${dateIN > 0 ? '+' : ''}${fn(pt.arguments[1])} || ' ${String(fn(pt.arguments[2])).replace(
/["']/g,
''
)}'))
ELSE
DATE(DATETIME(${fn(pt.arguments[0])}, 'localtime'),
'${dateIN > 0 ? '+' : ''}${fn(pt.arguments[1])} ${String(fn(pt.arguments[2])).replace(
${dateIN > 0 ? '+' : ''}${fn(pt.arguments[1])} || ' ${String(fn(pt.arguments[2])).replace(
/["']/g,
''
)}')

Loading…
Cancel
Save