🎁

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 : 06 : 05 : 12
1×
Become a member
to unlock all features
Autoplay

    Overview of the FaunaDB Query Language (FQL)

    Chris BiscardiChris Biscardi
    faunadbFaunaDB

    FQL is the main query language for interacting with FaunaDB. It supports all JSON types, plus some additional types like Ref, Date, and Set. FQL is based in expressions and as such everything returns a value. This makes it easy to compose logic into larger queries.

    Code shown in the shell:

    Match(Index("all_customers"))
    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: Fauna's native API for querying is called the Fauna Query Language, or FQL. While FQL can't be used for general purpose programming, it is based on a Lambda calculus and is expression-oriented. That means everything returns a value.

    Notably, pre-execution for FQL is transactional. No changes are committed if something goes wrong. If a query fails, all you get is an error response. This is part of FaunaDB's consistency model.

    FQL can be used in the shell or through a number of client drivers. Each of the drivers will implement FQL slightly differently, so be sure to check the documentation for your language of choice. The data types in FQL extend the JSON data format. All of JSON's data types are supported, including NULL.

    In addition to the JSON types that you're probably used to, there are a number of special types that FQLX adds. These include byte, date, ref, set, and timestamp. We'll be dealing with refs quite often. This is how we access documents or sets of documents.

    One more data type that is less a data type and more an object is an event. An event is a specially structured object that is used to represent all of the events that have happened to a particular document, such as create, update, and delete.

    Since everything in FQL returns a value, functions are very important. Here, we can see an overview of various data types and use cases and the functions in those collections. This includes functions you may be used to, like Map, as well as functions you may be less used to, like At, which retrieves a document at or before a particular point in time.

    This is related to the temporal querying aspect on a DB. Here, we are at the FaunaDB shell, where we'll use FQL to make our first query. Note that when we match on the index all customers, we get a setback. Note, also, that because index returns the value, we can pass that value to match. This is how we'll compose all of our expressions.

    If we look at the return value for index, we can see that it returns a ref. If we look at match, we can see that it takes an index ref and a set of search terms. We happened to not use the search terms this time, so we'll return all of the documents in the index as a set ref.