Refactor - simplify regex and use enum
This commit is contained in:
parent
9603a92c2c
commit
ece1e7533d
|
@ -93,13 +93,14 @@ function generateSelectStatement(json: QueryJson, knex: Knex): any[] {
|
||||||
const { resource, meta } = json
|
const { resource, meta } = json
|
||||||
const schema = meta?.table?.schema
|
const schema = meta?.table?.schema
|
||||||
return resource.fields.map(field => {
|
return resource.fields.map(field => {
|
||||||
const shortFieldName = field.match(/(?<=\.).*$/g)?.[0]
|
const fieldNames = field.split(/\./g)
|
||||||
if (shortFieldName && knex.client.config.client === "pg") {
|
const tableName = fieldNames[0]
|
||||||
const externalType = schema?.[shortFieldName].externalType
|
const columnName = fieldNames[1]
|
||||||
|
if (columnName && knex.client.config.client === SqlClients.POSTGRES) {
|
||||||
|
const externalType = schema?.[columnName].externalType
|
||||||
if (externalType?.includes("money")) {
|
if (externalType?.includes("money")) {
|
||||||
const fieldName = field.split(/\./g)
|
|
||||||
return knex.raw(
|
return knex.raw(
|
||||||
`"${fieldName?.[0]}"."${fieldName?.[1]}"::money::numeric as "${field}"`
|
`"${tableName}"."${columnName}"::money::numeric as "${field}"`
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue