# Database

**Shipped** comes with a database ORM that makes it extremely easy to configure a database and interact with it (query, insert, update, delete) — [Prisma](https://www.prisma.io/).

Prisma supports multiple databases, PostgreSQL, MySQL, MariaDB, MongoDB, and others ([full list here](https://www.prisma.io/docs/reference/database-reference/supported-databases)).

I always go with Postgres, because it's one of the best SQL databases in the market, open source, very popular, and very stable.

You can create a Postgres database for free using [Supabase](https://supabase.com/).

But these are other popular services to create a SQL database (Postgres or MySQL):

* [Digital Ocean](https://www.digitalocean.com/)
* [PlanetScale](https://planetscale.com/)
* [Railway](https://railway.app/)
* [AWS RDS](https://aws.amazon.com/rds/)

I usually go with DigitalOcean, because of its ease of use.

If you prefer a NoSQL database instead, go with MongoDB.\
You can create a managed MongoDB instance in the cloud using [MongoDB Atlas](https://www.mongodb.com/atlas/database).

## :gear: Setup

Create the database using your favorite service, and get the connection string.

For Postgres, it is a string with this format

```properties
postgresql://johndoe:randompassword@host:5432/mydb?schema=public
```

{% hint style="info" %}
If you use the Supabase Postgres, take the database connection string string way.

* Go to Supabase and select your project.
* Go to Home.
* Click on the button "Connect".
* Click on the tab "ORMs"
* Paste DATABASE\_URL and DIRECT\_URL to your `.env`
* Paste the `schema.prisma` values into your local file

{% endhint %}

### 1. Set the connection string

Paste it into the `.env` file as the value for the variable `DATABASE_URL`

The database schema (tables and columns) is defined in the file `prisma/schema.prisma` and Shipped already provides the base tables to handle authentication there.

### 2. Set the provider&#x20;

Open `prisma/schema.prisma` and set `provider = "postgresql"` .&#x20;

Here's the list of provider values:

| Database             | Provider value |
| -------------------- | -------------- |
| PostgreSQL           | postgresql     |
| MySQL                | mysql          |
| MariaDB              | mysql          |
| SQLite               | sqlite         |
| Microsoft SQL Server | sqlserver      |
| MongoDB              | mongodb        |
| CockroachDB          | cockroachdb    |

### 3. Initiate the database

To initiate your database, open a terminal, go to the Shipped folder,  and run

{% code title="terminal" %}

```bash
npm i # install all dependencies
npx prisma generate # initiate prisma
npx prisma db push # push the schema to the database
```

{% endcode %}

Now the database is ready to be used.

If you see this message, you are ready!<br>

<figure><img src="/files/PfaMQSNMTYz79SuKb0YC" alt=""><figcaption></figcaption></figure>

## Database operations

To execute query, insert, update, delete on the database, follow this pattern.

{% code title="example.ts" %}

```typescript
import { prismaClient } from "@/prisma/db";

const user = await prismaClient.user.findUnique({
  where: {
    email: "john@doe.com",
  },
});

```

{% endcode %}


---

# 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.shipped.club/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.
