EXAMPLES OF NODE.JS USING:
- PRISMA: AN OBJECT RELATIONAL MAPPING (ORM).
- NODEMON: FOLLOW THE INSTRUCTIONS HERE.
- EXPRESS.JS: FOLLOW THE INSTRUCTIONS HERE.
- TYPESCRIPT: FOLLOW THE INSTRUCTIONS HERE.
INSTALL PRISMA VSCODE EXTENSION.
npm install -D prisma
npm install @prisma/client
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
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.
-
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",
- CREATE THE DATABASE AND PREPARE PRISMA:
npm run database
-
RUN PRISMA STUDIO:
npm run studio
-
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