Skip to content

Commit

Permalink
update prisma schema
Browse files Browse the repository at this point in the history
  • Loading branch information
tun2010 committed Dec 13, 2023
1 parent 370c897 commit b38af2b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# next.js
/.next/
/out/
/public/uploads/*
# /public/uploads/*

# production
/build
Expand Down
36 changes: 18 additions & 18 deletions app/api/prisma/user/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,29 @@ export async function GET(request: NextRequest) {
try {
const prisma = new PrismaClient()

// const tResult = await prisma.$transaction(async (prisma) => {
// const hashedUsers = []
// for await (const user of users) {
// const hashedPassword = await bcrypt.hash(user.password, 10)
// hashedUsers.push({
// ...user,
// password: hashedPassword
// })
// }
// const userResult = await prisma.user.createMany({
// data: hashedUsers
// })

// return {
// userResult,
// }
// })
const tResult = await prisma.$transaction(async (prisma) => {
const hashedUsers = []
for await (const user of users) {
const hashedPassword = await bcrypt.hash(user.password, 10)
hashedUsers.push({
...user,
password: hashedPassword
})
}
const userResult = await prisma.user.createMany({
data: hashedUsers
})

return {
userResult,
}
})



await prisma.$disconnect()

return NextResponse.json({ success: true, data: 'tResult' })
return NextResponse.json({ success: true, data: tResult })
} catch(error: any) {
return NextResponse.json({ success: false, message: error.message }, { status: 500 })
}
Expand Down
2 changes: 1 addition & 1 deletion prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ generator client {

datasource db {
provider = "postgresql"
url = env("POSTGRES_LOCAL_URL") // uses connection pooling
url = env("POSTGRES_AIVEN_URL") // uses connection pooling
// directUrl = env("POSTGRES_URL_NON_POOLING") // uses a direct connection
}

Expand Down

0 comments on commit b38af2b

Please sign in to comment.