SelectAll

SelectAll( path, from )
SelectAll( path, from )
SelectAll( path, from )
SelectAll( path, from )
select_all( path, from )
SelectAll( path, from )

Description

The SelectAll function extracts one or more values from a document. It is very useful when extracting multiple values in an array. It extracts all of the values specified by the path parameter out of the from parameter and returns the values as an Array. If the path does not exist an empty array is returned.

This function is not comparable to SQL’s SELECT command. If you are looking to fetch documents from a collection, see Paginate.

Parameter

Argument Type Definition and Requirements

path

The path to the field in the document to extract

from

The object or array containing the data to be extracted.

Returns

The value(s) specified by the path.

Examples

The following query extracts all of the name fields from the provided array, by using a string-based path:

Value result = await client.Query(
  SelectAll(
    Arr("people", "name"),
    Obj(
      "people", Arr(
        Obj("name", "Jane"),
        Obj("name", "John"),
        Obj("name", "Thomas")
      )
    )
  )
);
[
  "Jane",
  "John",
  "Thomas"
]
result, err := client.Query(
  f.SelectAll(
    f.Arr{"people", "name"},
    f.Obj{
      "people": f.Arr{
        f.Obj{ "name": "Jane" },
        f.Obj{ "name": "John" },
        f.Obj{ "name": "Thomas" }}}))
[Jane John Thomas]
System.out.println(
    client.query(
        SelectAll(
            Arr(Value("people"), Value("name")),
            Obj(
                "people",
                Arr(
                    Obj("name", Value("Jane")),
                    Obj("name", Value("John")),
                    Obj("name", Value("Thomas"))
                )
            )
        )
    ).get());
["Jane", "John", "Thomas"]
client.query(
  q.SelectAll(
    ['people', 'name'],
    {
      'people': [
        { 'name': 'Jane' },
        { 'name': 'John' },
        { 'name': 'Thomas' },
      ],
    },
  )
)
.then((ret) => console.log(ret))
[ 'Jane', 'John', 'Thomas' ]
print(client.query(
  q.select_all(
    ["people", "name"],
    {
      "people": [
        { "name": "Jane" },
        { "name": "John" },
        { "name": "Thomas" },
      ],
    },
  )
))
['Jane', 'John', 'Thomas']
println(Await.result(
  client.query(
    SelectAll(
      Arr("people", "name"),
      Obj(
        "people" -> Arr(
          Obj("name" -> "Jane"),
          Obj("name" -> "John"),
          Obj("name" -> "Thomas")
        )
      )
    )
  ),
  5.seconds
))
["Jane", "John", "Thomas"]

The following query extracts all of the first names from the name fields, by using a path that includes a numeric index:

Value result = await client.Query(
  SelectAll(
    Arr("name", 0),
    Arr(
      Obj("name", Arr("Jane", "Eyre")),
      Obj("name", Arr("John", "Connor")),
      Obj("name", Arr("Thomas", "Magnum"))
    )
  )
);
[
  "Jane",
  "John",
  "Thomas"
]
result, err := client.Query(
  f.SelectAll(
    f.Arr{"name", 0},
    f.Arr{
      f.Obj{"name": f.Arr{"Jane", "Eyre"}},
      f.Obj{"name": f.Arr{"John", "Connor"}},
      f.Obj{"name": f.Arr{"Thomas", "Magnum"}}}))
[Jane John Thomas]
System.out.println(
    client.query(
        SelectAll(
            Arr(Value("name"), Value(0)),
            Arr(
                Obj("name", Arr(Value("Jane"), Value("Eyre"))),
                Obj("name", Arr(Value("John"), Value("Connor"))),
                Obj("name", Arr(Value("Thomas"), Value("Magnum")))
            )
        )
    ).get());
["Jane", "John", "Thomas"]
client.query(
  q.SelectAll(
    ['name', 0],
    [
      { 'name': [ 'Jane', 'Eyre' ] },
      { 'name': [ 'John', 'Connor' ] },
      { 'name': [ 'Thomas', 'Magnum' ] },
    ],
  )
)
.then((ret) => console.log(ret))
[ 'Jane', 'John', 'Thomas' ]
print(client.query(
  q.select_all(
    ["name", 0],
    [
      {"name": ["Jane", "Eyre"]},
      {"name": ["John", "Connor"]},
      {"name": ["Thomas", "Magnum"]}
    ]
  )
))
['Jane', 'John', 'Thomas']
println(Await.result(
  client.query(
    SelectAll(
      Arr("name", 0),
      Arr(
        Obj("name" -> Arr("Jane", "Eyre")),
        Obj("name" -> Arr("John", "Connor")),
        Obj("name" -> Arr("Thomas", "Magnum"))
      )
    )
  ),
  5.seconds
))
["Jane", "John", "Thomas"]

Is this article helpful? 

Tell Fauna how the article can be improved:
Visit Fauna's forums or email docs@fauna.com

Thank you for your feedback!