Browse Source

refacotr(nocodb): move the logic out as convertDateFormatByType

pull/5498/head
Wing-Kam Wong 2 years ago
parent
commit
087a37bbbc
  1. 41
      packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/helpers/formulaFnHelper.ts

41
packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/helpers/formulaFnHelper.ts

@ -54,6 +54,25 @@ export function validateDateWithUnknownFormat(v: string) {
return false; return false;
} }
export function convertDateFormatByType(query, clientType, dateFormat) {
if (clientType === 'mysql2') {
query = `DATE_FORMAT(${query}, '${convertDateFormat(
dateFormat,
clientType
)}')`;
} else if (clientType === 'pg') {
query = `TO_CHAR(${query}, '${convertDateFormat(dateFormat, clientType)}')`;
} else if (clientType === 'sqlite3') {
query = `strftime('${convertDateFormat(
dateFormat,
clientType
)}', ${query})`;
} else if (clientType === 'mssql') {
query = `FORMAT(${query}, '${convertDateFormat(dateFormat, clientType)}')`;
}
return query;
}
export async function convertDateFormatForConcat( export async function convertDateFormatForConcat(
o, o,
columnIdToUidt, columnIdToUidt,
@ -71,27 +90,7 @@ export async function convertDateFormatForConcat(
}) })
).meta; ).meta;
if (clientType === 'mysql2') { return convertDateFormatByType(query, clientType, meta.date_format);
query = `DATE_FORMAT(${query}, '${convertDateFormat(
meta.date_format,
clientType
)}')`;
} else if (clientType === 'pg') {
query = `TO_CHAR(${query}, '${convertDateFormat(
meta.date_format,
clientType
)}')`;
} else if (clientType === 'sqlite3') {
query = `strftime('${convertDateFormat(
meta.date_format,
clientType
)}', ${query})`;
} else if (clientType === 'mssql') {
query = `FORMAT(${query}, '${convertDateFormat(
meta.date_format,
clientType
)}')`;
}
} }
return query; return query;
} }

Loading…
Cancel
Save