-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
eff3f0b
commit da01254
Showing
2 changed files
with
57 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# express + nodejs | ||
|
||
## integrate with prisma + postgresql | ||
|
||
### 0. Install Postgresql With Docker | ||
|
||
```sh | ||
docker run --name postgres -e POSTGRES_USER=postgres -e POSTGRES_PASSWORD=postgres -p 5432:5432 -d postgres | ||
``` | ||
|
||
### 1. Install Prisma CLI | ||
|
||
```sh | ||
pnpm install @prisma/client | ||
``` | ||
### 2. Init a Prisma Schema | ||
|
||
```sh | ||
npx prisma init | ||
``` | ||
|
||
### 3. Migrate the database | ||
|
||
```sh | ||
npx prisma migrate dev --name initname | ||
``` | ||
|
||
### 4. Generate the prisma client | ||
|
||
```sh | ||
npx prisma generate | ||
``` | ||
|
||
```js | ||
import {PrismaClient} from '@prisma/client' | ||
|
||
const prisma = new PrismaClient({ | ||
log: ["error", "info", "warn", "query"] | ||
}) | ||
|
||
export default prisma | ||
``` | ||
|
||
### 6. Open the Prisma Studio | ||
|
||
```sh | ||
npx prisma studio | ||
``` | ||
|
||
### 7. Using Prisma in Express | ||
|
||
```sh | ||
(async () => { | ||
return await prisma.tableName.findMany() | ||
})() | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
import {PrismaClient} from '@prisma/client' | ||
|
||
const prisma = new PrismaClient({ | ||
log: ["error", "info", "warn"] | ||
log: ["error", "info", "warn", "query"] | ||
}) | ||
|
||
export default prisma |