|
|
@ -98,7 +98,9 @@ function addFilters( |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
function addRelationships( |
|
|
function addRelationships( |
|
|
|
|
|
knex: Knex, |
|
|
query: KnexQuery, |
|
|
query: KnexQuery, |
|
|
|
|
|
fields: string | string[], |
|
|
fromTable: string, |
|
|
fromTable: string, |
|
|
relationships: RelationshipsJson[] | undefined |
|
|
relationships: RelationshipsJson[] | undefined |
|
|
): KnexQuery { |
|
|
): KnexQuery { |
|
|
@ -114,7 +116,7 @@ function addRelationships( |
|
|
query = query.leftJoin( |
|
|
query = query.leftJoin( |
|
|
toTable, |
|
|
toTable, |
|
|
`${fromTable}.${from}`, |
|
|
`${fromTable}.${from}`, |
|
|
`${relationship.tableName}.${to}` |
|
|
`${toTable}.${to}` |
|
|
) |
|
|
) |
|
|
} else { |
|
|
} else { |
|
|
const throughTable = relationship.through |
|
|
const throughTable = relationship.through |
|
|
@ -130,7 +132,7 @@ function addRelationships( |
|
|
.leftJoin(toTable, `${toTable}.${toPrimary}`, `${throughTable}.${to}`) |
|
|
.leftJoin(toTable, `${toTable}.${toPrimary}`, `${throughTable}.${to}`) |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
return query |
|
|
return query.limit(BASE_LIMIT) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
function buildCreate( |
|
|
function buildCreate( |
|
|
@ -199,7 +201,7 @@ function buildRead(knex: Knex, json: QueryJson, limit: number): KnexQuery { |
|
|
[tableName]: query, |
|
|
[tableName]: query, |
|
|
}).select(selectStatement) |
|
|
}).select(selectStatement) |
|
|
// handle joins
|
|
|
// handle joins
|
|
|
return addRelationships(preQuery, tableName, relationships) |
|
|
return addRelationships(knex, preQuery, selectStatement, tableName, relationships) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
function buildUpdate( |
|
|
function buildUpdate( |
|
|
|