Browse Source

Merge pull request #1877 from mertmit/fix-date-args

fix: using functions for DATEADD interval
pull/1881/head
աɨռɢӄաօռɢ 3 years ago committed by GitHub
parent
commit
28d5a8b04e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  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) => { DATEADD: ({ fn, knex, pt, colAlias }: MapFnArgs) => {
return knex.raw( return knex.raw(
`CASE `${fn(pt.arguments[0])} + (${fn(pt.arguments[1])} ||
WHEN CAST(${fn(pt.arguments[0])} AS text) LIKE '%:%' THEN '${String(fn(pt.arguments[2])).replace(/["']/g, '')}')::interval${colAlias}`
${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}`
); );
} }
}; };

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( STRFTIME('%Y-%m-%d %H:%M', DATETIME(DATETIME(${fn(
pt.arguments[0] pt.arguments[0]
)}, 'localtime'), )}, '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, /["']/g,
'' ''
)}')) )}'))
ELSE ELSE
DATE(DATETIME(${fn(pt.arguments[0])}, 'localtime'), 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, /["']/g,
'' ''
)}') )}')

Loading…
Cancel
Save