Skip to content

Latest commit

 

History

History

starter

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 

Prisma Accelerate Example: TypeScript Starter

This repository has been created to help you get started with Prisma Accelerate. This project comes with a basic schema.prisma configured with PostgreSQL and an example operation found in the index.ts file.

Prerequisites

To successfully run the project, you will need the following:

  • An Accelerate connection string. If you don't have one yet, you can get one in 2 minutes by signing up on console.prisma.io or following our Getting Started guide.

Getting started

1. Download example and install dependencies

Download this example:

npx try-prisma@latest --template typescript/starter

Install npm dependencies:

cd starter
npm install
Alternative: Clone the entire repo

Clone this repository:

git clone [email protected]:prisma/prisma-examples.git --depth=1

Install npm dependencies:

cd prisma-examples/typescript/starter
npm install

2. Configure environment variables

Create a .env in the root of the project directory:

touch .env

Now, open the .env file and update the DATABASE_URL environment variables with the values of your connection string:

# .env
DATABASE_URL="__ACCELERATE_CONNECTION_STRING_PLACEHOLDER__"
DIRECT_URL="__DIRECT_DATABASE_CONNECTION_STRING_PLACEHOLDER__"

Note that you need to replace the placeholder values with the actual values.

3. Run a database migration to create the User table

The Prisma schema file contains a single User model. You can map this model to the database and create the corresponding User table using the following command:

npx prisma migrate dev --name init

You now have an empty User table in your database.

4. Run a Prisma operation

Run the main script

npm run start

This will add a new user to the User table, and then run a simple query to fetch all users.

Resources