Giter Club home page Giter Club logo

node_express_prisma's Introduction

옛날 방식 express 서버 설치.

npm init npm i express npm i -D nodemon

touch index.js

import express from 'express'

const app =express();

//route
app.get("/",(req,res) => {
    return res.send("hello world!!");
})

app.listen (3000, () => {
    console.log("server on 3000");
}) 

“dev”: “nodemon —-watch ./index.js”

npm run dev -> hello world.

npm i prisma npx prisma init

 ✝  prisma/example/node_express_prisma   master±  npx prisma init

✔ Your Prisma schema was created at prisma/schema.prisma
  You can now open it in your favorite editor.

Next steps:
1. 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
2. Set the provider of the datasource block in schema.prisma to match your database: postgresql, mysql, sqlite, sqlserver, mongodb or cockroachdb.
3. Run prisma db pull to turn your database schema into a Prisma schema.
4. Run prisma generate to generate the Prisma Client. You can then start querying your database.

More information in our documentation:
https://pris.ly/d/getting-started

.env file and schema.prisma file are created.

table is called model in prisma.

3 add model & npx prisma format

npx prisma migrate dev

Environment variables loaded from .env
Prisma schema loaded from prisma/schema.prisma
Datasource "db": PostgreSQL database "prisma_test", schema "public" at "localhost:5443"

✔ Enter a name for the new migration: … init
Applying migration `20221102023129_init`

The following migration(s) have been created and applied from new schema changes:

migrations/
  └─ 20221102023129_init/ 
    └─ migration.sql

Your database is now in sync with your schema.

npm i @faker-js/faker

✝  prisma/example/node_express_prisma   master±  node test
Jan Hettinger
silver

jake テストファイル生成 →   DB model 変更

 ✝  prisma/example/node_express_prisma   master±  npx prisma format
Prisma schema loaded from prisma/schema.prisma
Formatted /Users/sjkim030303/opt/dev_2022/nestjs/prisma/example/node_express_prisma/prisma/schema.prisma in 21ms 🚀

npx prisma migrate dev
......

 ✝  prisma/example/node_express_prisma   master±  npx prisma db push
Environment variables loaded from .env
Prisma schema loaded from prisma/schema.prisma
Datasource "db": PostgreSQL database "prisma_test", schema "public" at "localhost:5443"

⚠️ We found changes that cannot be executed:
  • Added the required column `name` to the `User` table without a default value. There are 3 rows in this table, it is not possible to execute this step.
✔ To apply this change we need to reset the database, do you want to continue? All data will be lost. … yes
The PostgreSQL database "prisma_test" from "localhost:5443" was successfully reset.
🚀  Your database is now in sync with your Prisma schema. Done in 35.60s
✔ Generated Prisma Client (4.5.0 | library) to ./node_modules/@prisma/client in 44ms


 ✝  prisma/example/node_express_prisma   master±  npx prisma generate   
Environment variables loaded from .env
Prisma schema loaded from prisma/schema.prisma

✔ Generated Prisma Client (4.5.0 | library) to ./node_modules/@prisma/client in 43ms
You can now start using Prisma Client in your code. Reference: https://pris.ly/d/client
--
import { PrismaClient } from '@prisma/client'
const prisma = new PrismaClient()
--

... add git history...

add table like. npx prisma format npx prisma migrate dev

중간에 컬럼 변경이 있을 경우 데이터가 다 날아가므로 주의할것.


model tags

✝  prisma/example/node_express_prisma   master±  npx prisma db push
Environment variables loaded from .env
Prisma schema loaded from prisma/schema.prisma
Datasource "db": PostgreSQL database "prisma_test", schema "public" at "localhost:5443"

🚀  Your database is now in sync with your Prisma schema. Done in 287ms

✔ Generated Prisma Client (4.5.0 | library) to ./node_modules/@prisma/client in 48ms

✝  prisma/example/node_express_prisma   master±  npx prisma generate
Environment variables loaded from .env
Prisma schema loaded from prisma/schema.prisma

✔ Generated Prisma Client (4.5.0 | library) to ./node_modules/@prisma/client in 49ms
You can now start using Prisma Client in your code. Reference: https://pris.ly/d/client

import { PrismaClient } from '@prisma/client'
const prisma = new PrismaClient()

npx prisma migrate dev 이걸 했더니 디비가 몽창 다시 지워졌다.. -_-...

node_express_prisma's People

Contributors

sungjun030303 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.