🎁

12 Days of Baddass Courses sale! Get instant access to the entire egghead library of courses and lessons for 58% off.

Runs out in:
15 : 05 : 53 : 24
1×
Become a member
to unlock all features
Autoplay

    Selecting multiple fields in an FQL query

    Chris BiscardiChris Biscardi
    faunadbFaunaDB

    You can use array and object literals to compose multiple selections into a single query, such as within a lambda.

    Map(
      Paginate(Match(Index("all_customers"))),
      Lambda(
        "X",
        Select(["data", "firstName"], Get(Var("X")))
      )
    )

    with arrays

    Map(
      Paginate(Match(Index("all_customers"))),
      Lambda(
        "X",
        [
          Select(["data", "firstName"], Get(Var("X"))),
          Select(["data", "lastName"], Get(Var("X")))
        ]
      )
    )

    with objects

    Map(
      Paginate(Match(Index("all_customers"))),
      Lambda(
        "X",
        [
          Select(["data", "firstName"], Get(Var("X"))),
          Select(["data", "lastName"], Get(Var("X")))
        ]
      )
    )

    Map( Paginate(Match(Index("all_customers"))), Lambda( "X", { firstName: Select("data", "firstName", Get(Var("X"))), lastName: Select("data", "lastName", Get(Var("X"))) } ) )

    Code

    Code

    Become a Member to view code

    You must be a Member to view code

    Access all courses and lessons, track your progress, gain confidence and expertise.

    Become a Member
    and unlock code for this lesson
    Discuss

    Discuss

    Transcript

    Transcript

    Instructor: 0:00 Here, we have an FQL query. We match on the index all customers and paginate the results. We map over those paginated results, using a Lambda, and select the first name out. Lambda defines a variable x. We select the first name out of the resulting object.

    0:19 If we run this query, we can see that we do get all of the first names from all of the customers. What if we want their last name, too? First, we'll use an array. We can take our select statement and duplicate it, then replace the field that we want.

    0:44 If we run this query, we can see that we get the first name and last name in an array, which results in a multidimensional array. Typically, we'll probably want to use an object instead.

    1:01 If we use an object when we run our query, we can see that the two select statements have composed to create an object. This pattern of composition is how we'll include multiple expressions to select multiple fields.