@nestledjs/api 1.0.1 → 1.0.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/package.json
CHANGED
|
@@ -4,14 +4,18 @@ import { CorePagingInput } from './dto/core-paging.input'
|
|
|
4
4
|
import { withOptimize } from '@prisma/extension-optimize'
|
|
5
5
|
|
|
6
6
|
@Injectable()
|
|
7
|
-
export class ApiCoreDataAccessService
|
|
7
|
+
export class ApiCoreDataAccessService
|
|
8
|
+
extends PrismaClient
|
|
9
|
+
implements OnModuleInit, OnModuleDestroy
|
|
10
|
+
{
|
|
8
11
|
constructor() {
|
|
9
12
|
const config: Prisma.PrismaClientOptions = {
|
|
10
13
|
datasources: {
|
|
11
14
|
db: { url: `${process.env['DATABASE_URL']}?connection_limit=30` },
|
|
12
15
|
},
|
|
13
16
|
log:
|
|
14
|
-
process.env['LOG_PRISMA_QUERIES'] === 'true' ||
|
|
17
|
+
process.env['LOG_PRISMA_QUERIES'] === 'true' ||
|
|
18
|
+
process.env['COUNT_PRISMA_QUERIES'] === 'true'
|
|
15
19
|
? [{ emit: 'event', level: 'query' }]
|
|
16
20
|
: [{ emit: 'event', level: 'warn' }],
|
|
17
21
|
}
|
|
@@ -40,19 +44,21 @@ export class ApiCoreDataAccessService extends PrismaClient implements OnModuleIn
|
|
|
40
44
|
await this.$connect()
|
|
41
45
|
|
|
42
46
|
if (process.env['LOG_PRISMA_QUERIES'] == 'true') {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
47
|
+
this.$on('query' as never, async (e: Prisma.QueryEvent) => {
|
|
48
|
+
console.log(`QUERY: ${e.query} \n\nPARAMS: ${e.params}\n\n\n`)
|
|
49
|
+
})
|
|
46
50
|
}
|
|
47
51
|
|
|
48
52
|
if (process.env['COUNT_PRISMA_QUERIES'] == 'true') {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
53
|
+
this.$on('query' as never, async () => {
|
|
54
|
+
this.queryCount++
|
|
55
|
+
})
|
|
52
56
|
}
|
|
53
57
|
}
|
|
54
58
|
|
|
55
|
-
filter<T extends Record<string, unknown>>(
|
|
59
|
+
filter<T extends Record<string, unknown>>(
|
|
60
|
+
input: CorePagingInput = {},
|
|
61
|
+
): {
|
|
56
62
|
skip: number
|
|
57
63
|
take: number
|
|
58
64
|
where?: T
|
|
@@ -76,7 +82,9 @@ export class ApiCoreDataAccessService extends PrismaClient implements OnModuleIn
|
|
|
76
82
|
}
|
|
77
83
|
|
|
78
84
|
if (trimmedSearch && searchFields.length > 0) {
|
|
79
|
-
const terms = trimmedSearch.includes(' ')
|
|
85
|
+
const terms = trimmedSearch.includes(' ')
|
|
86
|
+
? trimmedSearch.split(' ')
|
|
87
|
+
: [trimmedSearch].filter(Boolean)
|
|
80
88
|
const searchFilters = terms.map((term) => ({
|
|
81
89
|
OR: searchFields.map((field) => ({
|
|
82
90
|
[field]: { contains: term, mode: Prisma.QueryMode.insensitive },
|