FQL basics cookbook
This Fauna documentation cookbook explores the key areas of knowledge needed to become a proficient Fauna developer.
Cookbook topics
- Fauna at-a-glance
-
This section gives you a broad overview of Fauna and the Fauna Query Language to provide context for the topics that follow without going too deep.
This section also sets up a small database as a reference for the exercises in the sections that follow.
- Iterate on sets
-
This section covers basic CRUD operations and the concepts of documents and sets.
- Define relationships
-
This section covers how to establish one-to-one, one-to-many, and many-to-many relationships between documents across collections.
- Improve performance with indexes
-
Learn the fundamentals of indexing to improve performance and reduce costs.
- Get query results one page at a time
-
Learn how to get your data in manageable chunks.
- Catch errors at compile time
-
Learn how to leverage static typing to catch errors at compile time.
- Write custom logic with user-defined functions
-
This section covers user-defined functions (UDFs), which let you write and store custom logic.
How to use the cookbook
This cookbook provides a hands-on learning experience to facilitate learning about Fauna and FQL. Each tutorial is a progression in a graduated learning experience where later tutorials build on what you learned in earlier tutorials. The cookbook terminology defines each top-level section ss a tutorial, and tutorials include exercises that cover a Fauna feature.
After you have set up your environment and verified that you can run queries, work on the tutorials sequentially or start with the topic that matches your immediate interest and experience level.
The examples assume a given database setup so fields with dynamically
set values, such as You’re also encouraged to experiment with variations on these examples as a way to gain an even deeper insight into Fauna capabilities. |
Some tutorial steps might include variations on the basic operations for added insight and direct you to the documentation, where you can find more detailed information.
Environment setup for running the examples
The easiest way to try the examples as you follow the tutorials is to use the Dashboard. If you’ve already tried the Dashboard quick start, you’re already set up to run the examples. Because the FQL syntax is the same in all contexts, you can also run the same examples programmatically using one of the Supported drivers for your language of choice.
Error detection and reporting
A word should be said about error detection and reporting. FQL validates queries and performs runtime checks, returning informative error messages that aid debugging when an error occurs.
For example, when type checking is enabled an error is raised by the following example because the non-null assertion postfix operator is omitted:
QueryCheckError
error: Type `CoffeeBean | NullCoffeeBean` isn't a subtype of `{ update: { Owner: "Healthy Grounds" } => Any, ... }`
at *query*:1:39
|
1 | CoffeeBean.byId("366190711733747780").update(
| ^^^^^^
|
cause: Type `Null` does not have field `update`: use the ! operator to remove the null case
|
1 | CoffeeBean.byId("366190711733747780").update(
| ^^^^^^^^^^^^^^^
|
Notice that the error message indicates the location of the error.
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!