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

Loading…
Cancel
Save