-
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.
Initial setup, setup user and post model, upsert user and create posts
- Loading branch information
Benjamin
committed
Apr 30, 2022
1 parent
c69093e
commit aeeb032
Showing
8 changed files
with
509 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,3 @@ | ||
node_modules | ||
# Keep environment variables out of version control | ||
.env |
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,40 @@ | ||
import { PrismaClient } from "@prisma/client"; | ||
|
||
const prisma = new PrismaClient(); | ||
|
||
async function main() { | ||
// ... you will write your Prisma Client queries here | ||
const user = await prisma.user.upsert({ | ||
where: { email: "[email protected]" }, | ||
update: {}, | ||
create: { | ||
name: "Alice", | ||
email: "[email protected]", | ||
}, | ||
}); | ||
|
||
await Promise.all([ | ||
prisma.post.create({ | ||
data: { title: "TestPost1", content: "Some content 1", authorId: 99999 }, | ||
}), | ||
prisma.post.create({ | ||
data: { | ||
title: "TestPost2", | ||
content: "Some content 2", | ||
authorId: user.id, | ||
}, | ||
}), | ||
]); | ||
|
||
const posts = await prisma.post.findMany(); | ||
|
||
console.dir(posts); | ||
} | ||
|
||
main() | ||
.catch((e) => { | ||
throw e; | ||
}) | ||
.finally(async () => { | ||
await prisma.$disconnect(); | ||
}); |
Oops, something went wrong.