Skip to content

Latest commit

 

History

History
86 lines (54 loc) · 2.74 KB

File metadata and controls

86 lines (54 loc) · 2.74 KB

PRISMA

DESCRIPTION

EXAMPLES OF NODE.JS USING:

  • PRISMA: AN OBJECT RELATIONAL MAPPING (ORM).

PREREQUISITES

  • NODEMON: FOLLOW THE INSTRUCTIONS HERE.
  • EXPRESS.JS: FOLLOW THE INSTRUCTIONS HERE.
  • TYPESCRIPT: FOLLOW THE INSTRUCTIONS HERE.

RECOMMENDED VSCODE EXTENSIONS

INSTALL PRISMA VSCODE EXTENSION.

REQUIRED PACKAGES

npm install -D prisma
npm install @prisma/client

INITIALIZATION

THE FOLLOWING COMMAND WILL INITIALIZE PRISMA. IT WILL CREATE THE FILE schema.prisma IN prisma FOLDER AND MODIFY THE .env FILE.

# IF YOU ARE USING MYSQL PROVIDER AND YOUR MYSQL PASSWORD IS EMPTY:
npx prisma init --url mysql://root:@localhost:3306/databaseProject

# IF YOU ARE USING MYSQL PROVIDER AND YOUR MYSQL PASSWORD IS "password":
#npx prisma init --url mysql://root:password@localhost:3306/databaseProject

PRISMA DATA SOURCE

YOU CAN ALSO MODIFY YOUR SETTINGS AFTER INITIALIZATION. FOR THIS, JUST MODIFY THE PROVIDER IN prisma/schema.prisma (IN datasource db ENTRY) AND THE DATABASE_URL VARIABLE IN .env FILE.

CONFIGURATIONS

  • FILL THE DATABASE SCHEMA FILE schema.prisma IN prisma FOLDER. YOU CAN DO IT MANUALLY OR IMPORT THE DATABASE STRUCTURE WITH THE COMMAND:

    npx prisma db pull --schema=./prisma/schema.prisma
  • WINDOWS BUG FIX: IF WORKING WITH WINDOWS, OPEN THE MYSQL FILE my.ini AND ADD lower_case_table_names=2 RIGHT AFTER THE LINE [mysqld]. RESTART THE MYSQL SERVER. THIS IS GOING TO ENABLE UPPERCASE IN MYSQL TABLE NAMES.

  • CREATE THE COMMAND npm run database BY ADDING THE FOLLOWING LINES TO THE script ENTRY IN package.json:

    "database": "prisma db push --schema=./prisma/schema.prisma && prisma generate --schema=./prisma/schema.prisma",
  • CREATE COMMAND npm run studio BY ADDING THE FOLLOWING LINES TO THE script ENTRY IN package.json:

    "studio": "prisma studio --schema=./prisma/schema.prisma",

USING PRISMA

  • CREATE THE DATABASE AND PREPARE PRISMA:
npm run database
  • RUN PRISMA STUDIO:

    npm run studio

EXAMPLE

  • INSTALL THE REST Client VSCODE EXTENSION TO SIMULATE POST, PUT AND DELETE REQUESTS.

  • RUN THE EXAMPLE:

    npm run tsc-nodemon --jsfile=./folderDist/folderTopics/folderPrisma/examplePrisma.js