@tsed/prisma 7.35.1 → 7.36.0-rc.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/tsconfig.esm.tsbuildinfo +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +15 -12
- package/readme.md +1 -266
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsed/prisma",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.36.0-rc.2",
|
|
4
4
|
"description": "Generate Ts.ED JsonSchema based on Prisma models",
|
|
5
5
|
"source": "./src/index.ts",
|
|
6
6
|
"main": "./lib/cjs/index.js",
|
|
@@ -36,12 +36,12 @@
|
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"@prisma/client": "^4.0.0",
|
|
39
|
-
"@tsed/core": "7.
|
|
40
|
-
"@tsed/di": "7.
|
|
41
|
-
"@tsed/eslint": "7.
|
|
42
|
-
"@tsed/json-mapper": "7.
|
|
43
|
-
"@tsed/schema": "7.
|
|
44
|
-
"@tsed/typescript": "7.
|
|
39
|
+
"@tsed/core": "7.36.0-rc.2",
|
|
40
|
+
"@tsed/di": "7.36.0-rc.2",
|
|
41
|
+
"@tsed/eslint": "7.36.0-rc.2",
|
|
42
|
+
"@tsed/json-mapper": "7.36.0-rc.2",
|
|
43
|
+
"@tsed/schema": "7.36.0-rc.2",
|
|
44
|
+
"@tsed/typescript": "7.36.0-rc.2",
|
|
45
45
|
"@types/change-case": "^2.3.1",
|
|
46
46
|
"@types/pluralize": "0.0.29",
|
|
47
47
|
"eslint": "^8.12.0",
|
|
@@ -49,10 +49,10 @@
|
|
|
49
49
|
},
|
|
50
50
|
"peerDependencies": {
|
|
51
51
|
"@prisma/client": ">=4.0.0",
|
|
52
|
-
"@tsed/core": "^7.
|
|
53
|
-
"@tsed/di": "^7.
|
|
54
|
-
"@tsed/json-mapper": "^7.
|
|
55
|
-
"@tsed/schema": "^7.
|
|
52
|
+
"@tsed/core": "^7.36.0-rc.2",
|
|
53
|
+
"@tsed/di": "^7.36.0-rc.2",
|
|
54
|
+
"@tsed/json-mapper": "^7.36.0-rc.2",
|
|
55
|
+
"@tsed/schema": "^7.36.0-rc.2"
|
|
56
56
|
},
|
|
57
57
|
"keywords": [
|
|
58
58
|
"TypeScript",
|
|
@@ -71,5 +71,8 @@
|
|
|
71
71
|
},
|
|
72
72
|
"homepage": "https://github.com/tsedio/tsed/tree/production/packages/orm/prisma",
|
|
73
73
|
"author": "Romain Lenzotti",
|
|
74
|
-
"license": "MIT"
|
|
74
|
+
"license": "MIT",
|
|
75
|
+
"publishConfig": {
|
|
76
|
+
"tag": "rc"
|
|
77
|
+
}
|
|
75
78
|
}
|
package/readme.md
CHANGED
|
@@ -28,272 +28,7 @@
|
|
|
28
28
|
|
|
29
29
|
## Installation
|
|
30
30
|
|
|
31
|
-
|
|
32
|
-
npm i -D prisma
|
|
33
|
-
npm i @tsed/prisma @prisma/client
|
|
34
|
-
```
|
|
35
|
-
|
|
36
|
-
## Configuration
|
|
37
|
-
|
|
38
|
-
After installation, you need to update your `schema.prisma` file and then add a new generator section below the `client` one:
|
|
39
|
-
|
|
40
|
-
```prisma
|
|
41
|
-
generator client {
|
|
42
|
-
// ...
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
generator tsed {
|
|
46
|
-
provider = "@tsed/prisma"
|
|
47
|
-
}
|
|
48
|
-
```
|
|
49
|
-
|
|
50
|
-
Then after running `npx prisma generate`, this will emit the generated Ts.ED classes and Enums to `@tsed/prisma/.schema` in `node_modules` folder.
|
|
51
|
-
|
|
52
|
-
You can also configure the default output folder, e.g.:
|
|
53
|
-
|
|
54
|
-
```prisma
|
|
55
|
-
generator tsed {
|
|
56
|
-
provider = "@tsed/prisma"
|
|
57
|
-
output = "../prisma/generated/tsed"
|
|
58
|
-
}
|
|
59
|
-
```
|
|
60
|
-
|
|
61
|
-
By default, when the output path contains `node_modules`, the generated code is transpiled - containing `*.js` and `*.d.ts` files that are ready to use (import) in your code.
|
|
62
|
-
However, if you explicitly choose an other folder in `output` config, the generated code will be emitted as raw TS files which you can use and import as your other source code files.
|
|
63
|
-
|
|
64
|
-
You can overwrite that by explicitly setting `emitTranspiledCode` config option:
|
|
65
|
-
|
|
66
|
-
```prisma
|
|
67
|
-
generator tsed {
|
|
68
|
-
provider = "@tsed/prisma"
|
|
69
|
-
output = "../prisma/generated/tsed"
|
|
70
|
-
emitTranspiledCode = true
|
|
71
|
-
}
|
|
72
|
-
```
|
|
73
|
-
|
|
74
|
-
## Usage
|
|
75
|
-
|
|
76
|
-
Given that you have this part of datamodel definitions:
|
|
77
|
-
|
|
78
|
-
```groovy
|
|
79
|
-
model User {
|
|
80
|
-
/// @TsED.Groups("!creation")
|
|
81
|
-
/// Comment
|
|
82
|
-
id Int @id @default(autoincrement())
|
|
83
|
-
createdAt DateTime @default(now())
|
|
84
|
-
/// @TsED.Email()
|
|
85
|
-
/// @TsED.Description("User email. This email must be unique!")
|
|
86
|
-
email String @unique
|
|
87
|
-
weight Float?
|
|
88
|
-
is18 Boolean?
|
|
89
|
-
name String?
|
|
90
|
-
successorId Int?
|
|
91
|
-
successor User? @relation("BlogOwnerHistory", fields: [successorId], references: [id])
|
|
92
|
-
predecessor User? @relation("BlogOwnerHistory")
|
|
93
|
-
role Role @default(USER)
|
|
94
|
-
posts Post[]
|
|
95
|
-
keywords String[]
|
|
96
|
-
biography Json
|
|
97
|
-
|
|
98
|
-
/// @TsED.Ignore(ctx.endpoint === true)
|
|
99
|
-
ignored String
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
model Post {
|
|
103
|
-
id Int @id @default(autoincrement())
|
|
104
|
-
user User? @relation(fields: [userId], references: [id])
|
|
105
|
-
userId Int?
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
enum Role {
|
|
109
|
-
USER
|
|
110
|
-
ADMIN
|
|
111
|
-
}
|
|
112
|
-
```
|
|
113
|
-
|
|
114
|
-
it will generate the following UserModel:
|
|
115
|
-
|
|
116
|
-
```typescript
|
|
117
|
-
import {Integer, Required, Property, Groups, Format, Email, Description, Allow, Enum, CollectionOf} from "@tsed/schema";
|
|
118
|
-
import {User} from "../client";
|
|
119
|
-
import {Role} from "../enums";
|
|
120
|
-
import {PostModel} from "./PostModel";
|
|
121
|
-
|
|
122
|
-
export class UserModel implements User {
|
|
123
|
-
@Property(Number)
|
|
124
|
-
@Integer()
|
|
125
|
-
@Required()
|
|
126
|
-
@Groups("!creation")
|
|
127
|
-
id: number;
|
|
128
|
-
|
|
129
|
-
@Property(Date)
|
|
130
|
-
@Format("date-time")
|
|
131
|
-
@Required()
|
|
132
|
-
createdAt: Date;
|
|
133
|
-
|
|
134
|
-
@Property(String)
|
|
135
|
-
@Required()
|
|
136
|
-
@Email()
|
|
137
|
-
@Description("User email. This email must be unique!")
|
|
138
|
-
email: string;
|
|
139
|
-
|
|
140
|
-
@Property(Number)
|
|
141
|
-
@Allow(null)
|
|
142
|
-
weight: number | null;
|
|
143
|
-
|
|
144
|
-
@Property(Boolean)
|
|
145
|
-
@Allow(null)
|
|
146
|
-
is18: boolean | null;
|
|
147
|
-
|
|
148
|
-
@Property(String)
|
|
149
|
-
@Allow(null)
|
|
150
|
-
name: string | null;
|
|
151
|
-
|
|
152
|
-
@Property(Number)
|
|
153
|
-
@Integer()
|
|
154
|
-
@Allow(null)
|
|
155
|
-
successorId: number | null;
|
|
156
|
-
|
|
157
|
-
@Property(() => UserModel)
|
|
158
|
-
@Allow(null)
|
|
159
|
-
predecessor: UserModel | null;
|
|
160
|
-
|
|
161
|
-
@Required()
|
|
162
|
-
@Enum(Role)
|
|
163
|
-
role: Role;
|
|
164
|
-
|
|
165
|
-
@CollectionOf(() => PostModel)
|
|
166
|
-
@Required()
|
|
167
|
-
posts: PostModel[];
|
|
168
|
-
|
|
169
|
-
@CollectionOf(String)
|
|
170
|
-
@Required()
|
|
171
|
-
keywords: string[];
|
|
172
|
-
|
|
173
|
-
@Property(Object)
|
|
174
|
-
@Required()
|
|
175
|
-
biography: any;
|
|
176
|
-
|
|
177
|
-
@Ignore((value: any, ctx: any) => ctx.endpoint === true)
|
|
178
|
-
ignored: string;
|
|
179
|
-
}
|
|
180
|
-
```
|
|
181
|
-
|
|
182
|
-
And, the following repository:
|
|
183
|
-
|
|
184
|
-
```typescript
|
|
185
|
-
import {isArray} from "@tsed/core";
|
|
186
|
-
import {deserialize} from "@tsed/json-mapper";
|
|
187
|
-
import {Injectable, Inject} from "@tsed/di";
|
|
188
|
-
import {PrismaService} from "../services/PrismaService";
|
|
189
|
-
import {Prisma, User} from "../client";
|
|
190
|
-
import {UserModel} from "../models";
|
|
191
|
-
|
|
192
|
-
@Injectable()
|
|
193
|
-
export class UsersRepository {
|
|
194
|
-
@Inject()
|
|
195
|
-
protected prisma: PrismaService;
|
|
196
|
-
|
|
197
|
-
get collection() {
|
|
198
|
-
return this.prisma.user;
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
get groupBy() {
|
|
202
|
-
return this.collection.groupBy.bind(this.collection);
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
protected deserialize<T>(obj: null | User | User[]): T {
|
|
206
|
-
return deserialize<T>(obj, {type: UserModel, collectionType: isArray(obj) ? Array : undefined});
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
async findUnique(args: Prisma.UserFindUniqueArgs): Promise<UserModel | null> {
|
|
210
|
-
const obj = await this.collection.findUnique(args);
|
|
211
|
-
return this.deserialize<UserModel | null>(obj);
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
async findFirst(args: Prisma.UserFindFirstArgs): Promise<UserModel | null> {
|
|
215
|
-
const obj = await this.collection.findFirst(args);
|
|
216
|
-
return this.deserialize<UserModel | null>(obj);
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
async findMany(args?: Prisma.UserFindManyArgs): Promise<UserModel[]> {
|
|
220
|
-
const obj = await this.collection.findMany(args);
|
|
221
|
-
return this.deserialize<UserModel[]>(obj);
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
async create(args: Prisma.UserCreateArgs): Promise<UserModel> {
|
|
225
|
-
const obj = await this.collection.create(args);
|
|
226
|
-
return this.deserialize<UserModel>(obj);
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
async update(args: Prisma.UserUpdateArgs): Promise<UserModel> {
|
|
230
|
-
const obj = await this.collection.update(args);
|
|
231
|
-
return this.deserialize<UserModel>(obj);
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
async upsert(args: Prisma.UserUpsertArgs): Promise<UserModel> {
|
|
235
|
-
const obj = await this.collection.upsert(args);
|
|
236
|
-
return this.deserialize<UserModel>(obj);
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
async delete(args: Prisma.UserDeleteArgs): Promise<UserModel> {
|
|
240
|
-
const obj = await this.collection.delete(args);
|
|
241
|
-
return this.deserialize<UserModel>(obj);
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
async deleteMany(args: Prisma.UserDeleteManyArgs) {
|
|
245
|
-
return this.collection.deleteMany(args);
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
async updateMany(args: Prisma.UserUpdateManyArgs) {
|
|
249
|
-
return this.collection.updateMany(args);
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
async aggregate(args: Prisma.UserAggregateArgs) {
|
|
253
|
-
return this.collection.aggregate(args);
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
```
|
|
257
|
-
|
|
258
|
-
## Add Ts.ED decorator
|
|
259
|
-
|
|
260
|
-
The generator parse prisma command to find extra Ts.ED decorators. You can use any `@tsed/schema` decorators from Ts.ED by
|
|
261
|
-
adding a comment with the following format `/// @TsED.Decorator`. See example above:
|
|
262
|
-
|
|
263
|
-
```prisma
|
|
264
|
-
model User {
|
|
265
|
-
/// @TsED.Groups("!creation")
|
|
266
|
-
/// Comment
|
|
267
|
-
id Int @id @default(autoincrement())
|
|
268
|
-
createdAt DateTime @default(now())
|
|
269
|
-
/// @TsED.Email()
|
|
270
|
-
/// @TsED.Description("User email. This email must be unique!")
|
|
271
|
-
email String @unique
|
|
272
|
-
/// @TsED.Ignore(ctx.endpoint === true)
|
|
273
|
-
ignored String
|
|
274
|
-
}
|
|
275
|
-
```
|
|
276
|
-
|
|
277
|
-
Output:
|
|
278
|
-
|
|
279
|
-
```typescript
|
|
280
|
-
export class UserModel implements User {
|
|
281
|
-
@Property(Number)
|
|
282
|
-
@Integer()
|
|
283
|
-
@Required()
|
|
284
|
-
@Groups("!creation")
|
|
285
|
-
id: number;
|
|
286
|
-
|
|
287
|
-
@Property(String)
|
|
288
|
-
@Required()
|
|
289
|
-
@Email()
|
|
290
|
-
@Description("User email. This email must be unique!")
|
|
291
|
-
email: string;
|
|
292
|
-
|
|
293
|
-
@TsED.Ignore((value: any, ctx: any) => ctx.endpoint === true)
|
|
294
|
-
ignored: string;
|
|
295
|
-
}
|
|
296
|
-
```
|
|
31
|
+
See our [documentation](https://tsed.io/tutorials/prisma.html) for more information.
|
|
297
32
|
|
|
298
33
|
## Contributors
|
|
299
34
|
|