Browse Source

refactor(nocodb): move the logic to switch

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

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

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

Loading…
Cancel
Save