-
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.
chore(): add more models and descriptions in readme
- Loading branch information
Showing
8 changed files
with
92 additions
and
32 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
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
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,14 @@ | ||
import { faker } from '@faker-js/faker'; | ||
import { primaryKey } from '@mswjs/data'; | ||
|
||
faker.seed(); | ||
|
||
export const cat = { | ||
cat: { | ||
// ...with these properties and value getters. | ||
id: primaryKey(Number), | ||
type: () => faker.animal.cat(), | ||
description: () => faker.lorem.lines(5), | ||
price: () => faker.commerce.price({ min: 50, max: 400 }), | ||
}, | ||
}; |
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,6 +1,7 @@ | ||
import { factory } from '@mswjs/data'; | ||
import { cat } from './cat.js'; | ||
import { user } from './user.js'; | ||
import { post } from './post.js'; | ||
|
||
// Create database model | ||
export const db = factory({ ...user, ...post }); | ||
export const db = factory({ ...cat, ...user, ...post }); |
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,20 @@ | ||
/* eslint-disable import/order */ | ||
/* eslint-disable @typescript-eslint/no-unsafe-assignment */ | ||
|
||
import { createRequire } from 'node:module'; | ||
import { db } from '../models/db.js'; | ||
import { type Cat } from '../types.js'; | ||
|
||
const require = createRequire(import.meta.url); | ||
const catData: Cat[] = require('../data/data.json'); | ||
|
||
export const catSeeder = () => { | ||
for (const cat of catData) { | ||
db.cat.create({ | ||
id: cat.id, | ||
type: cat.type, | ||
description: cat.description, | ||
price: cat.price, | ||
}); | ||
} | ||
}; |
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,2 +1,3 @@ | ||
export * from './post-seeder.js'; | ||
export * from './user-seeder.js'; | ||
export * from './cat-seeder.js'; |
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
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