Learn the basics of FaunaDB by modeling a social graph in this beginner-friendly database tutorial.

Fauna https://fauna.com

Source Code https://github.com/fireship-io/faunadb-basics

FaunaDB is a next-generation cloud database that combines the simplicity of NoSQL, without sacrificing the ability to model complex relationships. It’s completely serverless, fast, ACID-compliant, and has a generous free tier for small apps - basically everything you could possibly want in a fully-managed database.

The following lesson demonstrates how to model a basic twitter-inspired social graph with FaunaDB and access it on the web with Node.js. It will introduce you to Fauna Query Language (FQL) and common patterns for reading and writing to the database.

Initial Setup

Start by creating a node project, then install the FaunaDB JS package and Express.

npm init -y

npm install faunadb express

Initialize FaunaDB

Create a server key from the Fauna security tabCreate a server key from the Fauna security tab

Initialize the client with your server key, then import the FQL functions required for this demo.

const faunadb = require('faunadb');
const client = new faunadb.Client({ secret: 'YOUR-KEY' })

// FQL functions
const {
    Function: Fn,
} = faunadb.query;

Initialize Express

We’ll use Express to serve the API.

const app = require('express')();

app.listen(5000, () => console.log('API on http://localhost:5000'))

At this point, I would recommend using an API client like Insomnia to make requests to your API on http://localhost:5000.

Database Structure

The database contains three collections - users, tweets, and relationships. Create these collections from the Fauna dashboard.

Read more: https://fireship.io/lessons/fauna-db-quickstart/

#faunadb #programming #developer

FaunaDB Basics - The Database of your Dreams
10.90 GEEK