It's a simple example which presents my attempt to work with prisma.
- npm install
- npm start - starts the server on http://localhost:4000
- Set the DATABASE_URL in the .env file to point to your existing database. If your database has no tables yet, read https://pris.ly/d/getting-started.
- Set the provider of the datasource block in schema.prisma to match your database: postgresql, mysql or sqlite.
- Run
prisma introspect
to turn your database schema into a Prisma data model. - Run
prisma generate
to install Prisma Client. You can then start querying your database.
Create necessary tables
Books
CREATE TABLE books (
id SERIAL PRIMARY KEY NOT NULL,
title TEXT NOT NULL,
isbn varchar(13) NOT NULL,
"availableAmount" INT NOT NULL,
"authorId" INT NOT NULL,
CONSTRAINT author FOREIGN KEY ("authorId") REFERENCES "public"."authors" (id)
);
Authors
CREATE TABLE authors (
id SERIAL PRIMARY KEY NOT NULL,
name varchar(40) NOT NULL,
surname varchar(40) NOT NULL
);