Browse Source

refactor(nocodb): move the logic to switch

pull/4629/head
Wing-Kam Wong 2 years ago
parent
commit
9105cd8cd9
  1. 144
      packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/helpers/convertUnits.ts

144
packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/helpers/convertUnits.ts

@ -5,150 +5,132 @@ export function convertUnits(
switch (unit) { switch (unit) {
case 'milliseconds': case 'milliseconds':
case 'ms': { case 'ms': {
if (type === 'mssql') { switch (type) {
case 'mssql':
return 'millisecond'; return 'millisecond';
} case 'mysql':
if (type === 'mysql') {
// MySQL doesn't support millisecond // MySQL doesn't support millisecond
// hence change from MICROSECOND to millisecond manually // hence change from MICROSECOND to millisecond manually
return 'MICROSECOND'; return 'MICROSECOND';
} case 'pg':
case 'sqlite':
if (type === 'pg' || type === 'sqlite') {
return 'milliseconds'; return 'milliseconds';
} default:
return unit; return unit;
} }
}
case 'seconds': case 'seconds':
case 's': { case 's': {
if (type === 'mssql' || type === 'pg') { switch (type) {
case 'mssql':
case 'pg':
return 'second'; return 'second';
} case 'mysql':
if (type === 'mysql') {
return 'SECOND'; return 'SECOND';
} case 'sqlite':
if (type === 'sqlite') {
return 'seconds'; return 'seconds';
} default:
return unit; return unit;
} }
}
case 'minutes': case 'minutes':
case 'm': { case 'm': {
if (type === 'mssql' || type === 'pg') { switch (type) {
case 'mssql':
case 'pg':
return 'minute'; return 'minute';
} case 'mysql':
if (type === 'mysql') {
return 'MINUTE'; return 'MINUTE';
} case 'sqlite':
if (type === 'sqlite') {
return 'minutes'; return 'minutes';
} default:
return unit; return unit;
} }
}
case 'hours': case 'hours':
case 'h': { case 'h': {
if (type === 'mssql' || type === 'pg') { switch (type) {
case 'mssql':
case 'pg':
return 'hour'; return 'hour';
} case 'mysql':
if (type === 'mysql') {
return 'HOUR'; return 'HOUR';
} case 'sqlite':
if (type === 'sqlite') {
return 'hours'; return 'hours';
} default:
return unit; return unit;
} }
}
case 'days': case 'days':
case 'd': { case 'd': {
if (type === 'mssql' || type === 'pg') { switch (type) {
case 'mssql':
case 'pg':
return 'day'; return 'day';
} case 'mysql':
if (type === 'mysql') {
return 'DAY'; return 'DAY';
} case 'sqlite':
if (type === 'sqlite') {
return 'days'; return 'days';
} default:
return unit; return unit;
} }
}
case 'weeks': case 'weeks':
case 'w': { case 'w': {
if (type === 'mssql' || type === 'pg') { switch (type) {
case 'mssql':
case 'pg':
return 'week'; return 'week';
} case 'mysql':
if (type === 'mysql') {
return 'WEEK'; return 'WEEK';
} case 'sqlite':
if (type === 'sqlite') {
return 'weeks'; return 'weeks';
} default:
return unit; return unit;
} }
}
case 'months': case 'months':
case 'M': { case 'M': {
if (type === 'mssql' || type === 'pg') { switch (type) {
case 'mssql':
case 'pg':
return 'month'; return 'month';
} case 'mysql':
if (type === 'mysql') {
return 'MONTH'; return 'MONTH';
} case 'sqlite':
if (type === 'sqlite') {
return 'months'; return 'months';
} default:
return unit; return unit;
} }
}
case 'quarters': case 'quarters':
case 'Q': { case 'Q': {
if (type === 'mssql' || type === 'pg') { switch (type) {
case 'mssql':
case 'pg':
return 'quarter'; return 'quarter';
} case 'mysql':
if (type === 'mysql') {
return 'QUARTER'; return 'QUARTER';
} case 'sqlite':
if (type === 'sqlite') {
return 'quarters'; return 'quarters';
} default:
return unit; return unit;
} }
}
case 'years': case 'years':
case 'y': { case 'y': {
if (type === 'mssql' || type === 'pg') { switch (type) {
case 'mssql':
case 'pg':
return 'year'; return 'year';
} case 'mysql':
if (type === 'mysql') {
return 'YEAR'; return 'YEAR';
} case 'sqlite':
if (type === 'sqlite') {
return 'years'; return 'years';
} default:
return unit; return unit;
} }
}
default: default:
return unit; return unit;
} }

Loading…
Cancel
Save