-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemp_file.txt
73 lines (58 loc) · 1.5 KB
/
temp_file.txt
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
Inspiration:
School management : https://github.com/safak/full-stack-school/blob/main/prisma/schema.prisma
// schema.prisma
model User {
id Int @id @default(autoincrement())
name String
email String @unique
posts Post[]
}
model Post {
id Int @id @default(autoincrement())
title String
content String?
published Boolean @default(false)
author User @relation(fields: [authorId], references: [id])
authorId Int
}
model Comment {
id Int @id @default(autoincrement())
content String
post Post @relation(fields: [postId], references: [id])
postId Int
}
> prisma generate
// generate-types.ts
import fs from 'fs';
import path from 'path';
import { User, Post, Comment } from '@prisma/client';
// Define the types you want to export
const types = `
export type User = ${JSON.stringify(User, null, 2)};
export type Post = ${JSON.stringify(Post, null, 2)};
export type Comment = ${JSON.stringify(Comment, null, 2)};
`;
// Write to a file
const outputPath = path.join(__dirname, 'shared-entities.ts');
fs.writeFileSync(outputPath, types);
console.log(`Entity types exported to ${outputPath}`);
> ts-execute generate-types.ts
will gives:
// shared-entities.ts
export type User = {
id: number;
name: string;
email: string;
};
export type Post = {
id: number;
title: string;
content: string | null;
published: boolean;
authorId: number;
};
export type Comment = {
id: number;
content: string;
postId: number;
};