fervor [>]CODING & CURIOSITY
FERVOR LEARNING SYSTEMTUTORIALS
← Back end

Back end / 5 MIN READ

Setting up Supabase

Adapt to change

From the original Fervor library. Examples may use older package versions.

Setting up a database in Supabase is like playing with building blocks—super fun and easier than you might think! Here’s a step-by-step guide to get you started with your very own Supabase database:

Step 1: Sign Up or Log In

First, you’ll need an account. Head over to Supabase and sign up if you’re new, or log in if you already have an account.

Step 2: Create a New Project

  1. Dashboard Navigation: Once logged in, you’ll find yourself on the dashboard. Click on the New Project button.

  2. Project Details: You’ll need to enter some details here:

    • Name your project: Something catchy or descriptive.
    • Database Password: This is crucial. Choose a strong password as this is the key to your database castle.
    • Region: Select the region closest to you or your users for the best performance.
  3. Create the Project: After filling out the details, hit the Create new project button and wait for a few minutes. Supabase will set up everything for you.

Step 3: Set Up Your Database

Once your project is ready, it’s time to shape your database.

  1. Access the SQL Editor: In your project’s dashboard, navigate to the SQL section on the left sidebar.

  2. Create Tables: You can create tables either by using the Table Editor or SQL scripts. Here’s a simple SQL command to create a table:

    CREATE TABLE example (
      id SERIAL PRIMARY KEY,
      name TEXT NOT NULL,
      created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP
    );
    

    Copy and paste this into the SQL editor and run it to create your example table.

  3. Insert Data: Let’s add some data to your table. In the SQL editor, you can run:

    INSERT INTO example (name) VALUES ('First Entry'), ('Second Entry');
    

Step 4: Explore and Expand

Now that you have a basic setup:

  • Explore the UI: Supabase provides a friendly user interface. Explore the Table Editor, Authentication, API, and other features.
  • Add More Tables: Build out your database schema as needed for your project.
  • Set Up APIs: Supabase automatically generates APIs for your tables. Check out the API documentation in the API section to connect your application.

Step 5: Connect Your App

  • API Keys: Retrieve your API keys from the Settings -> API section.
  • Client Setup: Use the following sample code to initialize Supabase in your app (example in JavaScript):
    import { createClient } from '@supabase/supabase-js'
    
    const supabase = createClient('your-project-url', 'your-anon-key')
    

Step 6: Go Live!

Test your setup, make sure all parts of your application are communicating well with the database, and then go live with confidence!

And just like that, you’ve laid the foundations of your Supabase project. Dive deeper into their docs to see what else you can build—Supabase is like a toy box for developers, after all. Enjoy creating!

Bonus Cool things to do with SupaBase

Supabase is a powerful platform that packs a lot of cool features, making it a great tool for building dynamic apps quickly. Here are some awesome things you can do with Supabase:

  1. Real-time Data Updates One of the coolest features of Supabase is its ability to handle real-time data updates. Imagine creating a live chat app or a real-time dashboard where data updates instantly across all clients as soon as it changes in the database. Here’s how you can set up a real-time listener in JavaScript:

javascript Copy code const mySubscription = supabase .from(‘messages’) .on(‘*’, payload => { console.log(‘Change received!’, payload) }) .subscribe() 2. Authentication Made Easy Supabase provides built-in authentication support that’s easy to implement, which includes everything from email and password login to OAuth logins with Google, GitHub, etc. This means you can set up a secure user authentication system without a lot of boilerplate code:

javascript Copy code await supabase.auth.signIn({ email: 'user@example.com’, password: ‘your-strong-password’ }) 3. Row Level Security This is a super secure feature that allows you to control which rows different users can access or modify in your database. It’s perfect for apps where user data privacy is critical. You can define policies directly in your dashboard to manage access based on user roles or other criteria.

  1. Serverless Functions Supabase allows you to run serverless functions (similar to AWS Lambda) which can react to database events, handle complex authentication workflows, or any server-side logic you need. This could be anything from processing images to handling heavy computations.

  2. Storage for Files With Supabase, you can store and serve files and media without needing a separate service. It’s great for apps requiring user file uploads, like documents in a collaboration tool or photos in a social media app. The storage API is simple to use and integrates directly with your database.

  3. Scheduled Tasks You can automate tasks using Supabase’s scheduled tasks feature. This is perfect for routine jobs like sending out weekly newsletters, updating records periodically, or cleaning up old data from your database.

  4. Generate APIs Instantly As soon as you create a table in Supabase, it automatically provides a ready-to-use RESTful API to access your data. This means you can start fetching and manipulating your data from your app right away without setting up additional backend code.

  5. Analytics and Logs Supabase provides detailed analytics and logs about your project’s usage, which can help you understand how your app is performing and troubleshoot any issues that arise.

  6. PostgreSQL Under the Hood Because Supabase uses PostgreSQL, you can take advantage of all PostgreSQL features, such as complex queries, joins, and transaction support, which are typically only available in traditional relational databases.

  7. Third-Party Integrations You can extend your Supabase project with integrations like Stripe for payments or send emails using SendGrid directly from your database using triggers and functions.

Each of these features opens up a myriad of possibilities for app development, making Supabase a versatile backend solution for modern web and mobile applications. Dive in and start building; you’ll find plenty to explore and innovate with Supabase!

Keep your curiosity going.Explore more Back end →
287 TUTORIALS · 22 TOPICSREADY