# Database

You can use any SQL database but I recommend Postgres.

Fell free to use any provider you like:

* [Supabase](https://supabase.com/)
* [NeonDB](https://neon.tech/)
* Your own server!

### Setup

1. Get your URI (a string starting with *"postgres:"*)

```sql
postgres://user:password@postgres:5432/dbname
```

2. Paste it to your .env:

{% code title=".env" %}

```
# Database URL
POSTGRES_URL="postgres://user:password@postgres:6543/dbname?pgbouncer=true&connection_limit=1"
POSTGRES_URL_NON_POOLING=""postgres://user:password@postgres:5432/dbname"
```

{% endcode %}

{% hint style="info" %}
Prefer a Pooling URL (PORT 6543) for Serverless environnements.

If you don't have a pooling URL, fill the 2 lines with your standard URI (PORT 5432)
{% endhint %}

### Database Init

Simply run these commands:

{% code title="Terminal" lineNumbers="true" %}

```bash
npx prisma generate
npx prisma migrate dev --skip-seed # push the schema to the database without seeds
```

{% endcode %}

### Database Queries

Prisma greatly simplify the database queries, here's an example:

{% code lineNumbers="true" %}

```typescript
const product = await prisma.product.findUnique({
    where: {
      slug: params.slug,
    },
    include: {
      ratings: true,
      category: true,
      collections: {
        include: {
          user: true,
          products: true,
        },
      },
    },
  });
```

{% endcode %}

Learn more by checking the [official Prisma documentation](https://www.prisma.io/docs). 📖


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.directoryfa.st/features/database.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
