Database

    We are using mongodb with Prisma ORM to make database operations if you are not familiar with Prisma it has a very easy learning curve, follow the guide below.

    We are planning to support postgresql in the future.

    Setup

    1. Create an account on atlas
    2. Create a database guide here
      • Select Atlas UI tab
    3. Copy your database URL to .env at the root of the project folder, URL looks similar to the URL below.
      • Make sure to add username, password and rename your database by replacing project_name in the URL below

    .env

    DATABASE_URL=mongodb+srv://username:password@cluster0.q8e4oaz.mongodb.net/project_name?retryWrites=true&w=majority&appName=Cluster0
    

    Using Prisma

    1. Import db from lib/db to interact with the database on the server

    /src/app/(site)/example_page/page.tsx

    import { db } from "lib/db";
    
    1. Let's fetch all active products from the database

    /src/app/(site)/example_page/page.tsx

    const ExamplePage = async () => {
      const products = await db.findMany({
        where: { active: true },
      });
    
      return (
        <div>
          {products.map((product) => (
            <p key={product.id}>{product.title}</p>
          ))}
        </div>
      );
    };
    
    export default ExamplePage;
    

    That's it!

    Learn Prisma

    Follow the guide here