Skip to content

Commit

Permalink
Merge pull request #97 from JarvusInnovations/develop
Browse files Browse the repository at this point in the history
Release: v0.21.6
  • Loading branch information
themightychris authored Jul 7, 2022
2 parents 482c949 + 5670962 commit 624f456
Show file tree
Hide file tree
Showing 4 changed files with 396 additions and 708 deletions.
30 changes: 26 additions & 4 deletions backend/commands/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,23 @@ exports.builder = {
describe: 'Truncate results to given count',
type: 'number'
},
'filter.<field>': {
'filter': {
group: 'Filtering',
describe: 'Filter results by one or more field values',
type: 'array'
},
'filter.<field>[=<value>]': {
group: 'Filtering',
describe: 'Field to filter by'
},
fields: {
group: 'Field selection',
describe: 'List of fields to order/limit output columns with',
type: 'array'
},
'fields.<from>': {
describe: 'Fields to remap',
'fields.<from>=<to>': {
group: 'Field selection',
describe: 'Field to remap',
type: 'array'
}
};
Expand Down Expand Up @@ -125,11 +133,25 @@ async function* limitResult(result, limit) {
}

async function* mapResult(result, fields) {
if (!Array.isArray(fields)) {
const fieldsObject = fields;
fields = [];
for (const fromKey in fieldsObject) {
const fieldMap = {};
fieldMap[fromKey] = fieldsObject[fromKey];
fields.push(fieldMap);
}
}

for await (const record of result) {
const output = {};

for (const field of fields) {
if (typeof field == 'object') {
if (Array.isArray(field)) {
for (const fieldValue of field) {
output[fieldValue] = record[fieldValue];
}
} else if (typeof field == 'object') {
for (const from in field) {
output[field[from]] = record[from];
}
Expand Down
Loading

0 comments on commit 624f456

Please sign in to comment.