Skip to content
Branch: master
Find file History
Type Name Latest commit message Commit time
Failed to load latest commit information.
prisma adjust datamodel to v1.1 Apr 15, 2019
src prettier Feb 5, 2019 update to v1.34 May 28, 2019
package.json Update dependency @types/graphql to v14.2.1 Jun 16, 2019
tsconfig.json adjust tsconfigs Nov 29, 2018

Simple TypeScript Script Example

This example shows how to use the Prisma client in a simple TypeScript script to read and write data in a database.

How to use

1. Download example & install dependencies

Clone the repository:

git clone

Install Node dependencies:

cd prisma-examples/typescript/script
npm install

2. Install the Prisma CLI

To run the example, you need the Prisma CLI. Please install it via NPM or using another method:

npm install -g prisma

3. Set up database & deploy Prisma datamodel

For this example, you'll use a free demo database (AWS Aurora) hosted in Prisma Cloud. To set up your database, run:

prisma deploy

Then, follow these steps in the interactive CLI wizard:

  1. Select Demo server
  2. Authenticate with Prisma Cloud in your browser (if necessary)
  3. Back in your terminal, confirm all suggested values
Alternative: Run Prisma locally via Docker
  1. Ensure you have Docker installed on your machine. If not, you can get it from here.
  2. Create docker-compose.yml for MySQL (see here for Postgres):
    version: '3'
        image: prismagraphql/prisma:1.34
        restart: always
        - "4466:4466"
          PRISMA_CONFIG: |
            port: 4466
                connector: mysql
                host: mysql
                port: 3306
                user: root
                password: prisma
                migrations: true
        image: mysql:5.7
        restart: always
          MYSQL_ROOT_PASSWORD: prisma
          - mysql:/var/lib/mysql
  3. Run docker-compose up -d
  4. Set the endpoint in prisma.yml to http://localhost:4466
  5. Run prisma deploy

You can now use Prisma Admin to view and edit your data by appending /_admin to your Prisma endpoint.

4. Run the script

Execute the script with this command:

npm run start

Next steps

You can’t perform that action at this time.