title: AlaSQL.js WHERE Clause on a Feld that is an Array of Objects
body: <p>What I'm trying to do is <code>SELECT metadata-&gt;name, metadata-&gt;namespace</code> but only if the <code>spec.volumes</code> contains an object with <code>secretName = 'test-secret'</code> from a list of objects that look like this:</p>
  
  <pre><code>{
    "kind": "PodList",
    "apiVersion": "v1",
    "metadata": {
      "selfLink": "/api/v1/pods",
    },
    "items": [
      {
        "metadata": {
          "name": "pod1",
          "namespace": "namespace1"
        },
        "spec": {
          "volumes": [
            {
              "name": "default-token",
              "secret": {
                "secretName": "default-token"
              }
            }
          ],
          "nodeName": "node-1"
        }
      }
      {
        "metadata": {
          "name": "pod2",
          "namespace": "namespace2"        
        },
        "spec": {
          "volumes": [
            {
              "name": "default-token",
              "secret": {
                "secretName": "default-token"
              }
            }
          ],
          "nodeName": "node-2"
        }
      },
      {
        "metadata": {
          "name": "chosen-pod",
          "namespace": "namespace3",
        },
        "spec": {
          "volumes": [
            {
              "name": "pod-storage",
            },
            {
              "name": "test-data",
              "secret": {
                "secretName": "test-secret"
              }
            }
          ],
          "nodeName": "node-2",
        }
      }
    ]
  }
  </code></pre>
  
  <p>This list is inserted into a table;</p>
  
  <pre><code>CREATE TABLE pods (node TEXT, metadata Object, spec Object)
  </code></pre>
  
  <p>I think this is the closest I've come;</p>
  
  <pre><code>SELECT metadata-&gt;name, metadata-&gt;namespace, spec-&gt;volumes AS volumes FROM pods WHERE (SELECT COUNT(*) FROM ? WHERE secret-&gt;secretName = 'test-data') &gt; 0
  </code></pre>
  
  <p>But this throws an error:</p>
  
  <pre><code>TypeError: Cannot read property '0' of undefined
      at Object.eval [as datafn] (eval at &lt;anonymous&gt; (~/Documents/myproject/node_modules/alasql/dist/alasql.fs.js:7487:20), &lt;anonymous&gt;:3:40)
      at ~/Documents/myproject/node_modules/alasql/dist/alasql.fs.js:6100:19
      at Array.forEach (native)
      at queryfn (~/Documents/myproject/node_modules/alasql/dist/alasql.fs.js:6097:16)
      at Array.statement (~/Documents/myproject/node_modules/alasql/dist/alasql.fs.js:7121:14)
      at eval [as wherefn] (eval at &lt;anonymous&gt; (~/Documents/myproject/node_modules/alasql/dist/alasql.fs.js:7899:11), &lt;anonymous&gt;:3:56)
      at doJoin (~/Documents/myproject/node_modules/alasql/dist/alasql.fs.js:6615:12)
      at doJoin (~/Documents/myproject/node_modules/alasql/dist/alasql.fs.js:6687:8)
      at queryfn3 (~/Documents/myproject/node_modules/alasql/dist/alasql.fs.js:6174:2)
      at queryfn2 (~/Documents/myproject/node_modules/alasql/dist/alasql.fs.js:6149:9)
  </code></pre>
  
  <p>Hmm, is there an error in my <code>WHERE</code> clause? No, removing <code>&gt; 0</code> from the end and it throws the same exception.</p>
  
  <p>Working backwards from <a href="https://stackoverflow.com/questions/34527959/parse-a-jsonwith-array-and-objects-and-export-the-data-into-excel-file-in-node/34771859#34771859">this question/ answer</a> I also tried;</p>
  
  <pre><code>SEARCH / AS @a
    UNION ALL(
      spec-&gt;volumes AS @v
      RETURN(@a-&gt;metadata-&gt;name AS name, 
        @a-&gt;metadata-&gt;namespace AS namespace, 
        @v-&gt;secret-&gt;secretName AS [secretNames]
      )
    ) 
  FROM pods
  </code></pre>
  
  <p>But the <code>@v-&gt;secret-&gt;secretName AS [secretNames]</code> just yields <code>undefined</code>;</p>
  
  <pre><code>[ 'pod1', 'namespace1', undefined ]
  [ 'pod2', 'namespace2', undefined ]
  [ 'chosen-pod', 'namespace3', undefined ]
  </code></pre>
  
  <p>Returning the naked <code>@v</code> array puts me right back where I was before--a row with an array that I can't seem to filter against.</p>