Include * when having formulas
This commit is contained in:
parent
80dcc51923
commit
f92fcea42a
|
@ -272,12 +272,17 @@ class InternalBuilder {
|
||||||
return parts.join(".")
|
return parts.join(".")
|
||||||
}
|
}
|
||||||
|
|
||||||
private isFullSelectStatementRequired(): boolean {
|
private isFullSelectStatementRequired(includedFields: string[]): boolean {
|
||||||
for (let column of Object.values(this.table.schema)) {
|
for (const column of Object.values(this.table.schema)) {
|
||||||
if (this.SPECIAL_SELECT_CASES.POSTGRES_MONEY(column)) {
|
if (this.SPECIAL_SELECT_CASES.POSTGRES_MONEY(column)) {
|
||||||
return true
|
return true
|
||||||
} else if (this.SPECIAL_SELECT_CASES.MSSQL_DATES(column)) {
|
} else if (this.SPECIAL_SELECT_CASES.MSSQL_DATES(column)) {
|
||||||
return true
|
return true
|
||||||
|
} else if (
|
||||||
|
column.type === FieldType.FORMULA &&
|
||||||
|
includedFields.includes(column.name)
|
||||||
|
) {
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
|
@ -292,11 +297,9 @@ class InternalBuilder {
|
||||||
|
|
||||||
const alias = this.getTableName(table)
|
const alias = this.getTableName(table)
|
||||||
const schema = this.table.schema
|
const schema = this.table.schema
|
||||||
if (this.isFullSelectStatementRequired()) {
|
|
||||||
return [this.knex.raw("??", [`${alias}.*`])]
|
|
||||||
}
|
|
||||||
// get just the fields for this table
|
// get just the fields for this table
|
||||||
return resource.fields
|
const tableFields = resource.fields
|
||||||
.map(field => {
|
.map(field => {
|
||||||
const parts = field.split(/\./g)
|
const parts = field.split(/\./g)
|
||||||
let table: string | undefined = undefined
|
let table: string | undefined = undefined
|
||||||
|
@ -311,34 +314,43 @@ class InternalBuilder {
|
||||||
return { table, column, field }
|
return { table, column, field }
|
||||||
})
|
})
|
||||||
.filter(({ table }) => !table || table === alias)
|
.filter(({ table }) => !table || table === alias)
|
||||||
.map(({ table, column, field }) => {
|
|
||||||
const columnSchema = schema[column]
|
|
||||||
|
|
||||||
if (this.SPECIAL_SELECT_CASES.POSTGRES_MONEY(columnSchema)) {
|
if (
|
||||||
return this.knex.raw(`??::money::numeric as ??`, [
|
this.isFullSelectStatementRequired(
|
||||||
this.rawQuotedIdentifier([table, column].join(".")),
|
tableFields.map(({ column }) => column)
|
||||||
this.knex.raw(this.quote(field)),
|
)
|
||||||
])
|
) {
|
||||||
}
|
return [this.knex.raw("??", [`${alias}.*`])]
|
||||||
|
}
|
||||||
|
|
||||||
if (this.SPECIAL_SELECT_CASES.MSSQL_DATES(columnSchema)) {
|
return tableFields.map(({ table, column, field }) => {
|
||||||
// Time gets returned as timestamp from mssql, not matching the expected
|
const columnSchema = schema[column]
|
||||||
// HH:mm format
|
|
||||||
|
|
||||||
// TODO: figure out how to express this safely without string
|
if (this.SPECIAL_SELECT_CASES.POSTGRES_MONEY(columnSchema)) {
|
||||||
// interpolation.
|
return this.knex.raw(`??::money::numeric as ??`, [
|
||||||
return this.knex.raw(`CONVERT(varchar, ??, 108) as ??`, [
|
this.rawQuotedIdentifier([table, column].join(".")),
|
||||||
this.rawQuotedIdentifier(field),
|
this.knex.raw(this.quote(field)),
|
||||||
this.knex.raw(this.quote(field)),
|
])
|
||||||
])
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (table) {
|
if (this.SPECIAL_SELECT_CASES.MSSQL_DATES(columnSchema)) {
|
||||||
return this.rawQuotedIdentifier(`${table}.${column}`)
|
// Time gets returned as timestamp from mssql, not matching the expected
|
||||||
} else {
|
// HH:mm format
|
||||||
return this.rawQuotedIdentifier(field)
|
|
||||||
}
|
// TODO: figure out how to express this safely without string
|
||||||
})
|
// interpolation.
|
||||||
|
return this.knex.raw(`CONVERT(varchar, ??, 108) as ??`, [
|
||||||
|
this.rawQuotedIdentifier(field),
|
||||||
|
this.knex.raw(this.quote(field)),
|
||||||
|
])
|
||||||
|
}
|
||||||
|
|
||||||
|
if (table) {
|
||||||
|
return this.rawQuotedIdentifier(`${table}.${column}`)
|
||||||
|
} else {
|
||||||
|
return this.rawQuotedIdentifier(field)
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// OracleDB can't use character-large-objects (CLOBs) in WHERE clauses,
|
// OracleDB can't use character-large-objects (CLOBs) in WHERE clauses,
|
||||||
|
|
|
@ -173,7 +173,7 @@ export async function buildSqlFieldList(
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isView) {
|
if (isView) {
|
||||||
Object.entries(source.schema?.[field.name].columns || {})
|
Object.entries(source.schema?.[field.name]?.columns || {})
|
||||||
.filter(([_, column]) => helpers.views.isVisible(column))
|
.filter(([_, column]) => helpers.views.isVisible(column))
|
||||||
.forEach(([field]) => viewFields.add(field))
|
.forEach(([field]) => viewFields.add(field))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue