Added Knex.Raw to return type

This commit is contained in:
Mel O'Hagan 2022-06-23 13:09:22 +01:00
parent 1d6f780c72
commit 688a46f75e
1 changed files with 6 additions and 11 deletions

View File

@ -89,7 +89,10 @@ function parseFilters(filters: SearchFilters | undefined): SearchFilters {
return filters return filters
} }
function generateSelectStatement(json: QueryJson, knex: Knex): any[] { function generateSelectStatement(
json: QueryJson,
knex: Knex
): (string | Knex.Raw)[] {
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 => {
@ -235,9 +238,7 @@ class InternalBuilder {
} }
addRelationships( addRelationships(
knex: Knex,
query: KnexQuery, query: KnexQuery,
fields: string | string[],
fromTable: string, fromTable: string,
relationships: RelationshipsJson[] | undefined relationships: RelationshipsJson[] | undefined
): KnexQuery { ): KnexQuery {
@ -342,7 +343,7 @@ class InternalBuilder {
if (!resource) { if (!resource) {
resource = { fields: [] } resource = { fields: [] }
} }
let selectStatement: string | any[] = "*" let selectStatement: string | (string | Knex.Raw)[] = "*"
// handle select // handle select
if (resource.fields && resource.fields.length > 0) { if (resource.fields && resource.fields.length > 0) {
// select the resources as the format "table.columnName" - this is what is provided // select the resources as the format "table.columnName" - this is what is provided
@ -382,13 +383,7 @@ class InternalBuilder {
preQuery = this.addSorting(preQuery, json) preQuery = this.addSorting(preQuery, json)
} }
// handle joins // handle joins
query = this.addRelationships( query = this.addRelationships(preQuery, tableName, relationships)
knex,
preQuery,
selectStatement,
tableName,
relationships
)
return this.addFilters(query, filters, { relationship: true }) return this.addFilters(query, filters, { relationship: true })
} }