An open API service indexing awesome lists of open source software.

https://github.com/tidbcloud/nextjs-prisma-example

Fullstack Example with Next.js and Prisma.
https://github.com/tidbcloud/nextjs-prisma-example

Last synced: 4 months ago
JSON representation

Fullstack Example with Next.js and Prisma.

Awesome Lists containing this project

README

          

# Fullstack Example with Next.js and Prisma

> Modified form [Prisma Examples](https://github.com/prisma/prisma-examples/tree/latest/typescript/rest-nextjs-api-routes)

This example shows how to implement a **fullstack app in TypeScript with [Next.js](https://nextjs.org/)** using [React](https://reactjs.org/) and [Prisma Client](https://www.prisma.io/docs/reference/tools-and-interfaces/prisma-client).

Deploy on Local

### 🧑‍🍳 Before We Start

1. Create a [TiDB Cloud](https://tidbcloud.com/) account and get your free trial cluster.

### 1. Get connection details

1. Navigate to your TiDB Cloud Serverless cluster's dashboard.
2. Get **Endpoint**, **Port** and **User** field from the Connection tab.
3. Build your DATABASE_URL string: `mysql://:@:/rest_nextjs?sslaccept=strict`

![image](https://user-images.githubusercontent.com/35677990/202609001-ecf07f3d-a7a3-4376-9b7d-54f4096aaec6.jpg)

You will use this DATABASE_URL string to connect to TiDB Cloud Serverless cluster later.

### 2. Deploy on your workspace

1. Clone the code.
```shell
git clone https://github.com/tidbcloud/nextjs-prisma-example.git
cd nextjs-prisma-example
```
2. Set DATABASE_URL environment variables.
```shell
export DATABASE_URL=${your_DATABASE_URL_string}
```
3. Install dependence.
```shell
npm install .
```
4. Migrate your database.
````shell
npx prisma migrate dev
````
5. Start the app.
```shell
npm run dev
```

🎉 Mission Completes.

The app is now running, navigate to http://localhost:3000/ in your browser to explore its UI.

Deploy on Netlify

### 🧑‍🍳 Before We Start

1. Create a [TiDB Cloud](https://tidbcloud.com/) account and get your free trial cluster.
2. Create a [Netlify](https://app.netlify.com/signup) account.

### 1. Get connection details

1. Navigate to your TiDB Serverless cluster's dashboard.
2. Get **Endpoint**, **Port** and **User** field from the Connection tab.
3. Build your DATABASE_URL string: `mysql://:@:/rest_nextjs?sslaccept=strict`

![image](https://user-images.githubusercontent.com/35677990/202609001-ecf07f3d-a7a3-4376-9b7d-54f4096aaec6.jpg)

You will use this DATABASE_URL string to connect to TiDB Cloud Serverless cluster later.

### 2. Deploy on Netlify

The **Deploy to Netlify** button will take you to Netlify's deployment page. Then Netlify will help to clone this job to your own GitHub repository and automatically deploy it.

[![Deploy to Netlify button](https://www.netlify.com/img/deploy/button.svg)](https://app.netlify.com/start/deploy?repository=https://github.com/tidbcloud/nextjs-prisma-example)

1. Click the **Deploy to Netlify** button.
2. Click **Connect to GitHub** and authenticate GitHub account.
3. Fill in **Repository name** for your own GitHub repository.
4. Enter the DATABASE_URL string, get in the previous step, in the **Set database URL** field.
5. Click **Save & Deploy**.

![img](https://user-images.githubusercontent.com/35677990/208869376-c642e816-cb74-4012-9070-9a2cc301b72e.jpg)

🎉 Mission Completes.

Now wait for the deployment to complete, then you can view your site on the default domain generated by Netlify.

Deploy on Vercel

### 🧑‍🍳 Before We Start

1. Create a [TiDB Cloud](https://tidbcloud.com/) account and get your free trial cluster.
2. Create a [Vercel](https://vercel.com/signup) account.

### 1. Get connection details

1. Navigate to your TiDB Serverless cluster's dashboard.
2. Get **Endpoint**, **Port** and **User** field from the Connection tab.
3. Build your DATABASE_URL string: `mysql://:@:/rest_nextjs?sslaccept=strict`

![image](https://user-images.githubusercontent.com/35677990/202609001-ecf07f3d-a7a3-4376-9b7d-54f4096aaec6.jpg)

You will use this DATABASE_URL string to connect to TiDB Cloud Serverless cluster later.

### 2. Deploy on Vercel

The **Deploy** button will take you through Vercel's project creation flow. Vercel will help to clone this job to your own GitHub repository and automatically deploy it.

[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/clone?repository-name=nextjs-prisma-example&repository-url=https%3A%2F%2Fgithub.com%2Ftidbcloud%2Fnextjs-prisma-example&env=DATABASE_URL&envDescription=TiDB%20Cloud%20connection%20string)

1. Click the **Deploy** button.
2. Click **GitHub** button and authenticate GitHub account.
3. Select your **Git Scope** and fill in **Repository Name** for your own GitHub repository.
4. Click **Create** to create the git repository.
5. Enter the DATABASE_URL string, get in the previous step, in the **Value** field.
6. Click **Deploy**.

🎉 Mission Completes.

Now wait for the deployment to complete, then you can view your site on the default domain generated by Vercel.