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) {
case 'milliseconds':
case 'ms': {
if (type === 'mssql') {
return 'millisecond';
switch (type) {
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 's': {
if (type === 'mssql' || type === 'pg') {
return 'second';
}
if (type === 'mysql') {
return 'SECOND';
switch (type) {
case 'mssql':
case 'pg':
return 'second';
case 'mysql':
return 'SECOND';
case 'sqlite':
return 'seconds';
default:
return unit;
}
if (type === 'sqlite') {
return 'seconds';
}
return unit;
}
case 'minutes':
case 'm': {
if (type === 'mssql' || type === 'pg') {
return 'minute';
}
if (type === 'mysql') {
return 'MINUTE';
switch (type) {
case 'mssql':
case 'pg':
return 'minute';
case 'mysql':
return 'MINUTE';
case 'sqlite':
return 'minutes';
default:
return unit;
}
if (type === 'sqlite') {
return 'minutes';
}
return unit;
}
case 'hours':
case 'h': {
if (type === 'mssql' || type === 'pg') {
return 'hour';
}
if (type === 'mysql') {
return 'HOUR';
}
if (type === 'sqlite') {
return 'hours';
switch (type) {
case 'mssql':
case 'pg':
return 'hour';
case 'mysql':
return 'HOUR';
case 'sqlite':
return 'hours';
default:
return unit;
}
return unit;
}
case 'days':
case 'd': {
if (type === 'mssql' || type === 'pg') {
return 'day';
}
if (type === 'mysql') {
return 'DAY';
}
if (type === 'sqlite') {
return 'days';
switch (type) {
case 'mssql':
case 'pg':
return 'day';
case 'mysql':
return 'DAY';
case 'sqlite':
return 'days';
default:
return unit;
}
return unit;
}
case 'weeks':
case 'w': {
if (type === 'mssql' || type === 'pg') {
return 'week';
}
if (type === 'mysql') {
return 'WEEK';
switch (type) {
case 'mssql':
case 'pg':
return 'week';
case 'mysql':
return 'WEEK';
case 'sqlite':
return 'weeks';
default:
return unit;
}
if (type === 'sqlite') {
return 'weeks';
}
return unit;
}
case 'months':
case 'M': {
if (type === 'mssql' || type === 'pg') {
return 'month';
switch (type) {
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 'Q': {
if (type === 'mssql' || type === 'pg') {
return 'quarter';
switch (type) {
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 'y': {
if (type === 'mssql' || type === 'pg') {
return 'year';
switch (type) {
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:
return unit;

Loading…
Cancel
Save