Overview of the FaunaDB Query Language (FQL)

Chris Biscardi
InstructorChris Biscardi

Share this video with your friends

Send Tweet
Published 3 years ago
Updated a year ago

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:


Instructor: [00:00] 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.

[00:13] 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.

[00:26] 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.

[00:45] 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.

[01:02] 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.

[01:15] 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.

[01:37] 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.

[02:01] 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.