1

I have a Javascript object being passed into AlaSQL like:

const details = {
  "returnCode": 0,
  "someProperty": {
    "results": [
      {
        "resultId": 1234,
        "resultProperty1": "asdf",
        "notWantedProperty": "notThis",
        "anotherNotWantedProperty": "orAnyOther"
      },
      {
        "resultId": 5678,
        "resultProperty1": "qwert",
        "notWantedProperty": "notThisEither"
      }
    ]
  }
}
results = alasql(query, [details]);

I'm trying to use alasql to filter out like any of these with a WHERE query "resultProperty1 == "asdf" and get a result like:

{
  "returnCode": 0,
  "results": [
    {
      "resultId": 1234,
      "resultProperty1": "asdf"
    },
  ]
}
-- or --
{
  "returnCode": 0,
  "results": {
    "resultId": 1234,
    "resultProperty1": "asdf"
  }
}
-- or --
{
  "returnCode": 0,
  "someProperty": {
    "results": {
      "resultId": 1234,
      "resultProperty1": "asdf"
    }
  }
}
-- or --
{
  "returnCode": 0,
  "someProperty": {
    "results": [
      {
        "resultId": 1234,
        "resultProperty1": "asdf"
      }
    ]
  }
}

I'm having issues referencing the inner array. I have tried queries like:

SEARCH / AS @RES results / WHERE([0]='someProperty'] @RES FROM ?
SELECT * FROM (SELECT [1]->results AS results FROM ? WHERE [0] = 'someProperty')

But it's either pulling all of the inner array results, or none of them. Selecting and organising the object's fields into the results is also proving difficult.

So far my closest attempt is:

SEARCH / AS @RES results / WHERE(resultId=1234) RETURN (resultId AS `results->resultId`, resultProperty1 AS `results->resultId`) FROM ?

Which is returning

[
  {
    "results": {
      "resultId": 1234,
      "resultProperty1": "asdf"
  }
]
Slyke
  • 124
  • 1
  • 12

0 Answers0