|
|
@ -20,6 +20,7 @@ import { CacheGetType, CacheScope } from '~/utils/globals'; |
|
|
|
import { convertDateFormatForConcat } from '~/helpers/formulaFnHelper'; |
|
|
|
import { convertDateFormatForConcat } from '~/helpers/formulaFnHelper'; |
|
|
|
import FormulaColumn from '~/models/FormulaColumn'; |
|
|
|
import FormulaColumn from '~/models/FormulaColumn'; |
|
|
|
import { Base, BaseUser } from '~/models'; |
|
|
|
import { Base, BaseUser } from '~/models'; |
|
|
|
|
|
|
|
import { getRefColumnIfAlias } from '~/helpers'; |
|
|
|
|
|
|
|
|
|
|
|
const logger = new Logger('FormulaQueryBuilderv2'); |
|
|
|
const logger = new Logger('FormulaQueryBuilderv2'); |
|
|
|
|
|
|
|
|
|
|
@ -637,49 +638,55 @@ async function _formulaQueryBuilder( |
|
|
|
}; |
|
|
|
}; |
|
|
|
}; |
|
|
|
}; |
|
|
|
break; |
|
|
|
break; |
|
|
|
|
|
|
|
case UITypes.CreateTime: |
|
|
|
|
|
|
|
case UITypes.LastModifiedTime: |
|
|
|
case UITypes.DateTime: |
|
|
|
case UITypes.DateTime: |
|
|
|
if (knex.clientType().startsWith('mysql')) { |
|
|
|
{ |
|
|
|
aliasToColumn[col.id] = async (): Promise<any> => { |
|
|
|
const col = await getRefColumnIfAlias(col); |
|
|
|
return { |
|
|
|
|
|
|
|
// convert from DB timezone to UTC
|
|
|
|
if (knex.clientType().startsWith('mysql')) { |
|
|
|
builder: knex.raw( |
|
|
|
aliasToColumn[col.id] = async (): Promise<any> => { |
|
|
|
`CONVERT_TZ(??, @@GLOBAL.time_zone, '+00:00')`, |
|
|
|
return { |
|
|
|
[col.column_name], |
|
|
|
// convert from DB timezone to UTC
|
|
|
|
), |
|
|
|
builder: knex.raw( |
|
|
|
}; |
|
|
|
`CONVERT_TZ(??, @@GLOBAL.time_zone, '+00:00')`, |
|
|
|
}; |
|
|
|
|
|
|
|
} else if ( |
|
|
|
|
|
|
|
knex.clientType() === 'pg' && |
|
|
|
|
|
|
|
col.dt !== 'timestamp with time zone' && |
|
|
|
|
|
|
|
col.dt !== 'timestamptz' |
|
|
|
|
|
|
|
) { |
|
|
|
|
|
|
|
aliasToColumn[col.id] = async (): Promise<any> => { |
|
|
|
|
|
|
|
return { |
|
|
|
|
|
|
|
// convert from DB timezone to UTC
|
|
|
|
|
|
|
|
builder: knex |
|
|
|
|
|
|
|
.raw( |
|
|
|
|
|
|
|
`?? AT TIME ZONE CURRENT_SETTING('timezone') AT TIME ZONE 'UTC'`, |
|
|
|
|
|
|
|
[col.column_name], |
|
|
|
[col.column_name], |
|
|
|
) |
|
|
|
), |
|
|
|
.wrap('(', ')'), |
|
|
|
}; |
|
|
|
}; |
|
|
|
}; |
|
|
|
}; |
|
|
|
} else if ( |
|
|
|
} else if ( |
|
|
|
knex.clientType() === 'pg' && |
|
|
|
knex.clientType() === 'mssql' && |
|
|
|
col.dt !== 'timestamp with time zone' && |
|
|
|
col.dt !== 'datetimeoffset' |
|
|
|
col.dt !== 'timestamptz' |
|
|
|
) { |
|
|
|
) { |
|
|
|
// convert from DB timezone to UTC
|
|
|
|
aliasToColumn[col.id] = async (): Promise<any> => { |
|
|
|
aliasToColumn[col.id] = async (): Promise<any> => { |
|
|
|
return { |
|
|
|
return { |
|
|
|
// convert from DB timezone to UTC
|
|
|
|
builder: knex.raw( |
|
|
|
builder: knex |
|
|
|
`CONVERT(DATETIMEOFFSET, ?? AT TIME ZONE 'UTC')`, |
|
|
|
.raw( |
|
|
|
[col.column_name], |
|
|
|
`?? AT TIME ZONE CURRENT_SETTING('timezone') AT TIME ZONE 'UTC'`, |
|
|
|
), |
|
|
|
[col.column_name], |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
.wrap('(', ')'), |
|
|
|
|
|
|
|
}; |
|
|
|
}; |
|
|
|
}; |
|
|
|
}; |
|
|
|
} else if ( |
|
|
|
} else { |
|
|
|
knex.clientType() === 'mssql' && |
|
|
|
aliasToColumn[col.id] = () => |
|
|
|
col.dt !== 'datetimeoffset' |
|
|
|
Promise.resolve({ builder: col.column_name }); |
|
|
|
) { |
|
|
|
|
|
|
|
// convert from DB timezone to UTC
|
|
|
|
|
|
|
|
aliasToColumn[col.id] = async (): Promise<any> => { |
|
|
|
|
|
|
|
return { |
|
|
|
|
|
|
|
builder: knex.raw( |
|
|
|
|
|
|
|
`CONVERT(DATETIMEOFFSET, ?? AT TIME ZONE 'UTC')`, |
|
|
|
|
|
|
|
[col.column_name], |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
aliasToColumn[col.id] = () => |
|
|
|
|
|
|
|
Promise.resolve({ builder: col.column_name }); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
break; |
|
|
|
break; |
|
|
|
case UITypes.User: |
|
|
|
case UITypes.User: |
|
|
|