Skip to content

Commit

Permalink
Update sql request body sent to flatmap server.
Browse files Browse the repository at this point in the history
  • Loading branch information
alan-wu committed Nov 25, 2024
1 parent e7c4d69 commit ee4e17c
Showing 1 changed file with 6 additions and 18 deletions.
24 changes: 6 additions & 18 deletions services/flatmaps.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,40 +6,28 @@ const speciesMap = {
'NCBITaxon:9685': 'cat'
}

const buildConnectivitySqlStatement = function (keastIds) {
let sql = 'select knowledge from knowledge where entity in ('
if (keastIds.length === 1) {
sql += `'${keastIds[0]}')`
} else if (keastIds.length > 1) {
for (let i in keastIds) {
sql += `'${keastIds[i]}'${i >= keastIds.length - 1 ? ')' : ','} `
}
}
return sql
}

const buildAnatomySqlStatement = function(taxo, anatomy) {
const buildAnatomySqlStatement = function(anatomy) {
let anatomyString = ''
if (anatomy.length === 1) {
anatomyString = `('${anatomy[0]}')`
anatomyString = '(?)'
} else if (anatomy.length > 1) {
anatomyString = '('
for (let i in anatomy) {
anatomyString += `'${anatomy[i]}'${i >= anatomy.length - 1 ? ')' : ','} `
anatomyString += `?${i >= anatomy.length - 1 ? ')' : ','} `
}
}
let sql = `select id, entity from (select id, models from flatmaps group by models having max(created)) left join flatmap_entities on id = flatmap where models = '${taxo}' and entity in ${anatomyString}`
let sql = `select id, entity from (select id, models from flatmaps group by models having max(created)) left join flatmap_entities on id = flatmap where models = ? and entity in ${anatomyString}`
return sql
}

const anatomyQuery = async (taxo, anatomy) => {
const { $flatmapApiClient } = useNuxtApp()
const sqlData = { sql: buildAnatomySqlStatement(taxo, anatomy) }
const params = [taxo, ...anatomy]
const sqlData = { sql: buildAnatomySqlStatement(anatomy), params }
return $flatmapApiClient.post('knowledge/query/', sqlData)
}

export default {
anatomyQuery,
buildConnectivitySqlStatement,
speciesMap
}

0 comments on commit ee4e17c

Please sign in to comment.