@hedhog/prisma 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
package/README.md ADDED
@@ -0,0 +1,53 @@
1
+ # <p align="center">hedhog/prisma</p>
2
+
3
+ <p align="center">
4
+ <img src="https://avatars.githubusercontent.com/u/177489127?s=200&v=4" alt="Hedhog Avatar" />
5
+ </p>
6
+
7
+ **Hedhog Prisma** is a HedHog module that extends [**Prisma**](https://prisma.io/) Client to integrate seamlessly with HedHog projects. It provides an enhanced PrismaClient with additional methods for identifying the database provider and checking the type of database in use.
8
+
9
+ ## Purpose
10
+
11
+ The Hedhog Prisma module is designed to simplify interactions with Prisma by adding convenience methods and ensuring proper database connection management within HedHog projects. It enhances the Prisma Client with functionality specific to HedHog’s requirements, including database provider detection and connection handling.
12
+
13
+ ## Features
14
+
15
+ - **Database Connection Management**: Automatically connects to the database when the module is initialized.
16
+ - **Provider Detection**: Provides methods to detect the type of database provider being used (e.g., [**PostgreSQL**](https://www.postgresql.org/) or [**MySQL**](https://www.mysql.com/)).
17
+
18
+ ## Installation
19
+
20
+ This library is an integral part of the HedHog framework and should be installed as a dependency in your HedHog project. Ensure that the necessary dependencies are configured in your HedHog project.
21
+
22
+ ```bash
23
+ npm i @hedhog/prisma
24
+ ```
25
+
26
+ ## Methods
27
+
28
+ **onModuleInit()**: Automatically connects to the database when the module initializes.
29
+
30
+ **getProvider()**: Returns the active database provider (e.g., 'postgresql', 'mysql').
31
+
32
+ **isPostgres()**: Returns true if the active database provider is PostgreSQL.
33
+
34
+ **isMysql()**: Returns true if the active database provider is MySQL.
35
+
36
+ ## Folder Structure
37
+
38
+ ```plaintext
39
+ prisma/
40
+ ├── dist/ # Compiled JavaScript files from build
41
+ ├── node_modules/ # Discardable folder with all module dependencies
42
+ ├── src/
43
+ │ ├── index.ts # Entry point for PrismaService
44
+ │ ├── prisma.module.ts # Module definition (if needed)
45
+ │ └── prisma.service.ts # Service class extending PrismaClient
46
+ │ ├── prisma.service.spec.ts # Unit tests for PrismaService
47
+ ├── .gitignore # Specifies which files Git should ignore
48
+ ├── package.json # Manages dependencies and scripts for the library
49
+ ├── package-lock.json # Lock file for dependencies
50
+ ├── README.md # Documentation for the library
51
+ ├── tsconfig.lib.json # TypeScript configuration for library builds
52
+ ├── tsconfig.production.json # TypeScript configuration for production builds
53
+ ```
@@ -5,5 +5,10 @@ export declare class PrismaService extends PrismaClient implements OnModuleInit
5
5
  getProvider(): any;
6
6
  isPostgres(): boolean;
7
7
  isMysql(): boolean;
8
+ createInsensitiveSearch(fields: string[], paginationParams: {
9
+ search: string;
10
+ }, prismaService: {
11
+ getProvider: () => string;
12
+ }): any[];
8
13
  }
9
14
  //# sourceMappingURL=prisma.service.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"prisma.service.d.ts","sourceRoot":"","sources":["../src/prisma.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC1D,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C,qBACa,aAAc,SAAQ,YAAa,YAAW,YAAY;IAC/D,YAAY;IAIlB,WAAW;IAIX,UAAU;IAIV,OAAO;CAGR"}
1
+ {"version":3,"file":"prisma.service.d.ts","sourceRoot":"","sources":["../src/prisma.service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC1D,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C,qBACa,aAAc,SAAQ,YAAa,YAAW,YAAY;IAC/D,YAAY;IAIlB,WAAW;IAIX,UAAU;IAIV,OAAO;IAIP,uBAAuB,CACrB,MAAM,EAAE,MAAM,EAAE,EAChB,gBAAgB,EAAE;QAAE,MAAM,EAAE,MAAM,CAAA;KAAE,EACpC,aAAa,EAAE;QAAE,WAAW,EAAE,MAAM,MAAM,CAAA;KAAE,GAC3C,GAAG,EAAE;CAeT"}
@@ -22,6 +22,19 @@ let PrismaService = class PrismaService extends client_1.PrismaClient {
22
22
  isMysql() {
23
23
  return this.getProvider() === 'mysql';
24
24
  }
25
+ createInsensitiveSearch(fields, paginationParams, prismaService) {
26
+ const OR = fields.map((field) => ({
27
+ [field]: { contains: paginationParams.search },
28
+ }));
29
+ if (prismaService.getProvider() === 'postgres') {
30
+ OR.forEach((condition) => {
31
+ Object.keys(condition).forEach((key) => {
32
+ condition[key].mode = 'insensitive';
33
+ });
34
+ });
35
+ }
36
+ return OR;
37
+ }
25
38
  };
26
39
  exports.PrismaService = PrismaService;
27
40
  exports.PrismaService = PrismaService = __decorate([
@@ -1 +1 @@
1
- {"version":3,"file":"prisma.service.js","sourceRoot":"","sources":["../src/prisma.service.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAA0D;AAC1D,2CAA8C;AAGvC,IAAM,aAAa,GAAnB,MAAM,aAAc,SAAQ,qBAAY;IAC7C,KAAK,CAAC,YAAY;QAChB,MAAM,IAAI,CAAC,QAAQ,EAAE,CAAC;IACxB,CAAC;IAED,WAAW;QACT,OAAQ,IAAY,CAAC,aAAa,CAAC,cAAc,CAAC;IACpD,CAAC;IAED,UAAU;QACR,OAAO,IAAI,CAAC,WAAW,EAAE,KAAK,YAAY,CAAC;IAC7C,CAAC;IAED,OAAO;QACL,OAAO,IAAI,CAAC,WAAW,EAAE,KAAK,OAAO,CAAC;IACxC,CAAC;CACF,CAAA;AAhBY,sCAAa;wBAAb,aAAa;IADzB,IAAA,mBAAU,GAAE;GACA,aAAa,CAgBzB"}
1
+ {"version":3,"file":"prisma.service.js","sourceRoot":"","sources":["../src/prisma.service.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAA0D;AAC1D,2CAA8C;AAGvC,IAAM,aAAa,GAAnB,MAAM,aAAc,SAAQ,qBAAY;IAC7C,KAAK,CAAC,YAAY;QAChB,MAAM,IAAI,CAAC,QAAQ,EAAE,CAAC;IACxB,CAAC;IAED,WAAW;QACT,OAAQ,IAAY,CAAC,aAAa,CAAC,cAAc,CAAC;IACpD,CAAC;IAED,UAAU;QACR,OAAO,IAAI,CAAC,WAAW,EAAE,KAAK,YAAY,CAAC;IAC7C,CAAC;IAED,OAAO;QACL,OAAO,IAAI,CAAC,WAAW,EAAE,KAAK,OAAO,CAAC;IACxC,CAAC;IAED,uBAAuB,CACrB,MAAgB,EAChB,gBAAoC,EACpC,aAA4C;QAE5C,MAAM,EAAE,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;YAChC,CAAC,KAAK,CAAC,EAAE,EAAE,QAAQ,EAAE,gBAAgB,CAAC,MAAM,EAAE;SAC/C,CAAC,CAAC,CAAC;QAEJ,IAAI,aAAa,CAAC,WAAW,EAAE,KAAK,UAAU,EAAE,CAAC;YAC/C,EAAE,CAAC,OAAO,CAAC,CAAC,SAAS,EAAE,EAAE;gBACvB,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE;oBACpC,SAAS,CAAC,GAAG,CAAS,CAAC,IAAI,GAAG,aAAa,CAAC;gBAC/C,CAAC,CAAC,CAAC;YACL,CAAC,CAAC,CAAC;QACL,CAAC;QAED,OAAO,EAAE,CAAC;IACZ,CAAC;CACF,CAAA;AApCY,sCAAa;wBAAb,aAAa;IADzB,IAAA,mBAAU,GAAE;GACA,aAAa,CAoCzB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hedhog/prisma",
3
- "version": "0.0.5",
3
+ "version": "0.0.6",
4
4
  "private": false,
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -18,4 +18,24 @@ export class PrismaService extends PrismaClient implements OnModuleInit {
18
18
  isMysql() {
19
19
  return this.getProvider() === 'mysql';
20
20
  }
21
+
22
+ createInsensitiveSearch(
23
+ fields: string[],
24
+ paginationParams: { search: string },
25
+ prismaService: { getProvider: () => string },
26
+ ): any[] {
27
+ const OR = fields.map((field) => ({
28
+ [field]: { contains: paginationParams.search },
29
+ }));
30
+
31
+ if (prismaService.getProvider() === 'postgres') {
32
+ OR.forEach((condition) => {
33
+ Object.keys(condition).forEach((key) => {
34
+ (condition[key] as any).mode = 'insensitive';
35
+ });
36
+ });
37
+ }
38
+
39
+ return OR;
40
+ }
21
41
  }