-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathseed.ts
75 lines (68 loc) · 1.89 KB
/
seed.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import { Photon } from '@generated/photon'
const photon = new Photon()
// A `main` function so that we can use async/await
async function main() {
// const users = await photon.users
// .findOne({
// where: {
// name: 'heyMP'
// }
// })
// console.log(users)
// Seed the database with users and posts
const user1 = await photon.users.create({
data: {
name: 'heyMP',
}
})
const user2 = await photon.users.create({
data: {
name: 'btopro',
}
})
}
// console.log(`Created users: ${user1.name} (${user1.posts.length} post) and (${user2.posts.length} posts) `)
// // Retrieve all published posts
// const allPosts = await photon.posts.findMany({
// where: { published: true },
// })
// console.log(`Retrieved all published posts: `, allPosts)
// // Create a new post (written by an already existing user with email [email protected])
// const newPost = await photon.posts.create({
// data: {
// title: 'Join the Prisma Slack community',
// content: 'http://slack.prisma.io',
// published: false,
// author: {
// connect: {
// email: '[email protected]',
// },
// },
// },
// })
// console.log(`Created a new post: `, newPost)
// // Publish the new post
// const updatedPost = await photon.posts.update({
// where: {
// id: newPost.id,
// },
// data: {
// published: true,
// },
// })
// console.log(`Published the newly created post: `, updatedPost)
// // Retrieve all posts by user with email [email protected]
// const postsByUser = await photon.users
// .findOne({
// where: {
// email: '[email protected]',
// },
// })
// .posts()
// console.log(`Retrieved all posts from a specific user: `, postsByUser)
// }
main()
.catch(e => console.error(e))
.finally(async () => {
await photon.disconnect()
})