Skip to content

Commit

Permalink
support data downloads
Browse files Browse the repository at this point in the history
  • Loading branch information
KeithKelleher committed Mar 10, 2021
1 parent c2028cc commit 158a0d4
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 8 deletions.
5 changes: 5 additions & 0 deletions src/models/DataModelList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,11 @@ export abstract class DataModelList {
if (additionalWhereClause) {
query.andWhere(this.database.raw(additionalWhereClause));
}
innerJoins[i].columns.forEach(col => {
if(col.where_clause){
query.andWhere(that.database.raw(col.where_clause));
}
});
}
}
this.addModelSpecificFiltering(query, true);
Expand Down
2 changes: 1 addition & 1 deletion src/models/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ export class QueryDefinition {
}

const newTable = new SqlTable(reqData.table, {}, links, reqData.subQuery);
newTable.columns.push(new SqlColumns(reqData.data, reqData.alias, reqData.group_method));
newTable.columns.push(new SqlColumns(reqData.data, reqData.alias, reqData.group_method, reqData.where_clause));
this.tables.push(newTable);
}

Expand Down
9 changes: 6 additions & 3 deletions src/models/databaseTable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export class DatabaseTable {
/**
* tables which should always be left joined to because they might not have a mapping
*/
static sparseTables: string[] = ["tinx_novelty", "xref"];
static sparseTables: string[] = ["tinx_novelty"];

/**
* tables which have a data type column which describes the data the caller wants
Expand Down Expand Up @@ -117,14 +117,17 @@ export class DatabaseTable {

static requiredLinks: Map<string, string[]> = new Map(
[
["protein-target", ["t2tc"]],
["protein-viral_protein", ["viral_ppi", "virus"]],
["protein-virus", ["viral_ppi", "viral_protein"]],
["protein-dto", ["p2dto"]],
["protein-panther_class", ["p2pc"]],
["protein-virus", ["viral_protein", "viral_ppi"]],
["protein-viral_protein", ["virus", "viral_ppi"]],
["protein-ncats_ligands", ["ncats_ligand_activity", "target", "t2tc"]]

// checked
["protein-target", ["t2tc"]],
["protein-ncats_ligands", ["t2tc", "target", "ncats_ligand_activity"]],
["protein-ncats_ligand_activity", ["t2tc", "target"]]
]);

static getRequiredLinks(table1: string, table2: string): string[] | undefined {
Expand Down
17 changes: 13 additions & 4 deletions src/resolvers.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,21 @@ const resolvers = {

Query: {
download: async function (_, args, {dataSources}){
const listObj = DataModelListFactory.getListObject(args.model, dataSources.tcrd, args);
let listQuery;
try {
const listObj = DataModelListFactory.getListObject(args.model, dataSources.tcrd, args);
listQuery = listObj.getListQuery();
}
catch(e){
return {
result: false,
errorDetails: e.message
}
}
return {
result: true,
data: args.sqlOnly ? null : listObj.getListQuery(),
sql: listObj.getListQuery().toString(),
errorDetails: dataSources.tcrd.tableInfo.facetMap
data: args.sqlOnly ? null : listQuery,
sql: listQuery.toString()
};
},

Expand Down

0 comments on commit 158a0d4

Please sign in to comment.