-
Notifications
You must be signed in to change notification settings - Fork 0
/
backend-repositories-new.code-snippets
92 lines (90 loc) · 5.43 KB
/
backend-repositories-new.code-snippets
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
{
"New Repository Class Template": {
"scope": "typescript",
"prefix": "repository",
"body": [
"import { Prisma, ${TM_FILENAME/(.*).repository.ts/${1:/pascalcase}/g} } from '@prisma/client';",
"import { DefaultArgs } from '@prisma/client/runtime/library';",
"import { database } from '@/providers/database.provider.js';",
"import { Injectable } from '@decorators/di';",
"",
"type SelectDefaultArgs = Prisma.${TM_FILENAME/(.*).repository.ts/${1:/pascalcase}/g}Select<DefaultArgs>;",
"type CustomReturnType<T> = Prisma.${TM_FILENAME/(.*).repository.ts/${1:/pascalcase}/g}GetPayload<{ select: T }>;",
"const fields = {",
" ID: true,",
"} satisfies Prisma.${TM_FILENAME/(.*).repository.ts/${1:/pascalcase}/g}Select;",
"export type ${TM_FILENAME/(.*).repository.ts/${1:/pascalcase}/g}WithPublicFields = Prisma.${TM_FILENAME/(.*).repository.ts/${1:/pascalcase}/g}GetPayload<{",
" select: ${TM_FILENAME/(.*).repository.ts/${1:/pascalcase}/g}PublicSelect;",
"}>;",
"",
"@Injectable()",
"export class ${TM_FILENAME/(.*).repository.ts/${1:/pascalcase}/g}Repository {",
" aggregate(",
" params: Prisma.${TM_FILENAME/(.*).repository.ts/${1:/pascalcase}/g}AggregateArgs,",
" connection: Prisma.TransactionClient = database.read",
" ) {",
" return connection.${TM_FILENAME/(.*).repository.ts/${1:/camelcase}/g}.aggregate(params);",
" }",
"",
" upsert<T>(",
" params: Prisma.${TM_FILENAME/(.*).repository.ts/${1:/pascalcase}/g}UpsertArgs,",
" connection: Prisma.TransactionClient = database.write,",
" ): Promise<CustomReturnType<T>> {",
" return connection.${TM_FILENAME/(.*).repository.ts/${1:/camelcase}/g}.upsert(params) as unknown as Promise<CustomReturnType<T>>;",
" }",
"",
" create<T>(",
" params: Omit<Prisma.${TM_FILENAME/(.*).repository.ts/${1:/pascalcase}/g}CreateArgs, 'data'> & {",
" data?: Omit<Prisma.${TM_FILENAME/(.*).repository.ts/${1:/pascalcase}/g}CreateInput, 'ID'> & { ID?: string };",
" },",
" connection: Prisma.TransactionClient = database.write",
" ): Promise<CustomReturnType<T>> {",
" return connection.${TM_FILENAME/(.*).repository.ts/${1:/camelcase}/g}.create(params as Prisma.${TM_FILENAME/(.*).repository.ts/${1:/pascalcase}/g}CreateArgs) as unknown as Promise<CustomReturnType<T>>;",
" }",
"",
" createMany<T>(",
" params: Omit<Prisma.${TM_FILENAME/(.*).repository.ts/${1:/pascalcase}/g}CreateManyArgs, 'data'> & {",
" data?: Array<Omit<Prisma.${TM_FILENAME/(.*).repository.ts/${1:/pascalcase}/g}CreateManyInput, 'ID'> & { ID?: string }>;",
" },",
" connection: Prisma.TransactionClient = database.write",
" ): Promise<Array<CustomReturnType<T>>> {",
" return connection.${TM_FILENAME/(.*).repository.ts/${1:/camelcase}/g}.createMany(params as Prisma.${TM_FILENAME/(.*).repository.ts/${1:/pascalcase}/g}CreateManyArgs) as unknown as Promise<Array<CustomReturnType<T>>>;",
" }",
"",
" findFirst<T>(params: Prisma.${TM_FILENAME/(.*).repository.ts/${1:/pascalcase}/g}FindFirstArgs, connection: Prisma.TransactionClient = database.read): Promise<CustomReturnType<T>> {",
" return connection.${TM_FILENAME/(.*).repository.ts/${1:/camelcase}/g}.findFirst(params) as unknown as Promise<CustomReturnType<T>>;",
" }",
"",
" findMany<T>(",
" params: Prisma.${TM_FILENAME/(.*).repository.ts/${1:/pascalcase}/g}FindManyArgs,",
" connection: Prisma.TransactionClient = database.read",
" ): Promise<Array<CustomReturnType<T>>> {",
" return connection.${TM_FILENAME/(.*).repository.ts/${1:/camelcase}/g}.findMany(params) as unknown as Promise<Array<CustomReturnType<T>>>;",
" }",
"",
" count(params: Prisma.${TM_FILENAME/(.*).repository.ts/${1:/pascalcase}/g}CountArgs, connection: Prisma.TransactionClient = database.read) {",
" return connection.${TM_FILENAME/(.*).repository.ts/${1:/camelcase}/g}.count(params);",
" }",
"",
" update<T>(params: Prisma.${TM_FILENAME/(.*).repository.ts/${1:/pascalcase}/g}UpdateArgs, connection: Prisma.TransactionClient = database.write): Promise<CustomReturnType<T>> {",
" return connection.${TM_FILENAME/(.*).repository.ts/${1:/camelcase}/g}.update(params) as unknown as Promise<CustomReturnType<T>>;",
" }",
"",
" updateMany<T>(",
" params: Prisma.${TM_FILENAME/(.*).repository.ts/${1:/pascalcase}/g}UpdateManyArgs,",
" connection: Prisma.TransactionClient = database.write",
" ): Promise<Array<CustomReturnType<T>>> {",
" return connection.${TM_FILENAME/(.*).repository.ts/${1:/camelcase}/g}.updateMany(params) as unknown as Promise<Array<CustomReturnType<T>>>",
" }",
"",
" delete(params: Prisma.${TM_FILENAME/(.*).repository.ts/${1:/pascalcase}/g}DeleteArgs, connection: Prisma.TransactionClient = database.write) {",
" return connection.${TM_FILENAME/(.*).repository.ts/${1:/camelcase}/g}.delete(params);",
" }",
"",
" deleteMany(params: Prisma.${TM_FILENAME/(.*).repository.ts/${1:/pascalcase}/g}DeleteManyArgs, connection: Prisma.TransactionClient = database.write) {",
" return connection.${TM_FILENAME/(.*).repository.ts/${1:/camelcase}/g}.deleteMany(params);",
" }",
"}"
]
}
}