This repository has been archived by the owner on Feb 26, 2022. It is now read-only.
-
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
Showing
3 changed files
with
60 additions
and
0 deletions.
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,35 @@ | ||
import * as Faker from 'faker'; | ||
import { PrismaClient, Animal } from '@prisma/client'; | ||
import { random } from 'faker'; | ||
|
||
const prisma = new PrismaClient(); | ||
|
||
export const seedAnimals = async (): Promise<void> => { | ||
const breeds = await prisma.breed.findMany(); | ||
const users = await prisma.user.findMany(); | ||
const promises: Promise<Animal>[] = []; | ||
|
||
for (let index = 0; index < 10; index++) { | ||
const user = random.arrayElement(users); | ||
|
||
const items = { | ||
name: Faker.name.findName(), | ||
height: 100, | ||
weight: 100, | ||
description: Faker.lorem.lines(2), | ||
castrated: false, | ||
birthYear: Faker.date.between('2000-01-01', new Date()).getFullYear(), | ||
breeds: { | ||
connect: random.arrayElement(breeds.map((m) => ({ id: m.id }))), | ||
}, | ||
user: { | ||
connect: { | ||
id: user.id, | ||
}, | ||
}, | ||
sex: 1, | ||
}; | ||
promises.push(prisma.animal.create({ data: items })); | ||
} | ||
await Promise.all(promises); | ||
}; |
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,16 @@ | ||
import * as Faker from 'faker'; | ||
import { PrismaClient, Breed } from '@prisma/client'; | ||
|
||
const prisma = new PrismaClient(); | ||
|
||
export const seedBreeds = async (): Promise<void> => { | ||
const promises: Promise<Breed>[] = []; | ||
|
||
for (let index = 0; index < 10; index++) { | ||
const items = { | ||
name: Faker.animal.dog(), | ||
}; | ||
promises.push(prisma.breed.create({ data: items })); | ||
} | ||
await Promise.all(promises); | ||
}; |
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