This example shows how to implement a simple web app using React Router 7 and Prisma ORM. This example was bootstrapped using the React Router CLI tool create-react-router.
Download this example:
npx try-prisma@latest --template orm/react-router-7
Then navigate to the project directory
cd react-router-7
Alternative: Clone the entire repo
Clone this repository:
git clone git@github.com:prisma/prisma-examples.git --depth=1
Install npm dependencies:
cd prisma-examples/orm/nextjs
npm install
This example uses a Prisma Postgres database by default. To get started with the project, you will need to setup a Prisma Postgres connection string:
-
Set up a new Prisma Postgres instance in the Prisma Data Platform Console and copy the database connection URL.
-
Add your database url to the
.env
That's it, your project is now configured to use Prisma Postgres!
Run the following command to generate the Prisma Client. This is what you will be using to interact with your database.
npx prisma generate
npm run dev
The server is now running at http://localhost:5173. You can now view your todo list!
If you want to try this example with another database than Prisma Postgres, you can adjust the the database connection in prisma/schema.prisma by reconfiguring the datasource block.
Learn more about the different connection configurations in the docs.
Expand for an overview of example configurations with different databases
For PostgreSQL, the connection URL has the following structure:
datasource db {
provider = "postgresql"
url = "postgresql://USER:PASSWORD@HOST:PORT/DATABASE?schema=SCHEMA"
}Here is an example connection string with a local PostgreSQL database:
datasource db {
provider = "postgresql"
url = "postgresql://janedoe:mypassword@localhost:5432/notesapi?schema=public"
}For MySQL, the connection URL has the following structure:
datasource db {
provider = "mysql"
url = "mysql://USER:PASSWORD@HOST:PORT/DATABASE"
}Here is an example connection string with a local MySQL database:
datasource db {
provider = "mysql"
url = "mysql://janedoe:mypassword@localhost:3306/notesapi"
}Here is an example connection string with a local Microsoft SQL Server database:
datasource db {
provider = "sqlserver"
url = "sqlserver://localhost:1433;initial catalog=sample;user=sa;password=mypassword;"
}Here is an example connection string with a local MongoDB database:
datasource db {
provider = "mongodb"
url = "mongodb://USERNAME:PASSWORD@HOST/DATABASE?authSource=admin&retryWrites=true&w=majority"
}- Check out the Prisma docs
- Share your feedback on the Prisma Discord
- Create issues and ask questions on GitHub