@prisma-idb/idb-client-generator 0.2.1 → 0.3.0

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/.release-it.json CHANGED
@@ -7,5 +7,12 @@
7
7
  "@release-it/conventional-changelog": {
8
8
  "preset": "angular"
9
9
  }
10
+ },
11
+ "npm": {
12
+ "ignoreVersion": true
13
+ },
14
+ "git": {
15
+ "commit": false,
16
+ "push": false
10
17
  }
11
18
  }
@@ -6,9 +6,13 @@ function addCountMethod(modelClass, model) {
6
6
  name: "count",
7
7
  isAsync: true,
8
8
  typeParameters: [{ name: "Q", constraint: `Prisma.Args<Prisma.${model.name}Delegate, 'count'>` }],
9
- parameters: [{ name: "query", hasQuestionToken: true, type: "Q" }],
9
+ parameters: [
10
+ { name: "query", hasQuestionToken: true, type: "Q" },
11
+ { name: "tx", hasQuestionToken: true, type: "IDBUtils.TransactionType" },
12
+ ],
10
13
  returnType: `Promise<Prisma.Result<Prisma.${model.name}Delegate, Q, 'count'>>`,
11
14
  statements: (writer) => {
15
+ writer.writeLine(`tx = tx ?? this.client._db.transaction(["${model.name}"], "readonly");`);
12
16
  handleWithoutSelect(writer, model);
13
17
  handleWithSelect(writer, model);
14
18
  },
@@ -17,8 +21,8 @@ function addCountMethod(modelClass, model) {
17
21
  function handleWithoutSelect(writer, model) {
18
22
  writer.writeLine(`if (!query?.select || query.select === true)`).block(() => {
19
23
  writer
20
- .writeLine(`const records = await this.findMany({ where: query?.where });`)
21
- .writeLine(`return records.length as Prisma.Result<Prisma.${model.name}Delegate, Q, "count">;`);
24
+ .writeLine(`const totalRecords = await tx.objectStore("${model.name}").count();`)
25
+ .writeLine(`return totalRecords as Prisma.Result<Prisma.${model.name}Delegate, Q, "count">;`);
22
26
  });
23
27
  }
24
28
  function handleWithSelect(writer, model) {
@@ -31,10 +35,10 @@ function handleWithSelect(writer, model) {
31
35
  .writeLine(`if (typedKey === "_all")`)
32
36
  .block(() => {
33
37
  writer
34
- .writeLine(`result[typedKey] = (await this.findMany({ where: query.where })).length;`)
38
+ .writeLine(`result[typedKey] = (await this.findMany({ where: query.where }, tx)).length;`)
35
39
  .writeLine(`continue;`);
36
40
  })
37
- .writeLine("result[typedKey] = (await this.findMany({ where: { [`${typedKey}`]: { not: null } } })).length;");
41
+ .writeLine("result[typedKey] = (await this.findMany({ where: { [`${typedKey}`]: { not: null } } }, tx)).length;");
38
42
  })
39
43
  .writeLine(`return result as Prisma.Result<Prisma.UserDelegate, Q, "count">;`);
40
44
  }
@@ -1 +1 @@
1
- {"version":3,"file":"count.js","sourceRoot":"","sources":["../../../../../../src/fileCreators/prisma-idb-client/classes/models/api/count.ts"],"names":[],"mappings":";;AAGA,wCAYC;AAZD,SAAgB,cAAc,CAAC,UAA4B,EAAE,KAAY;IACvE,UAAU,CAAC,SAAS,CAAC;QACnB,IAAI,EAAE,OAAO;QACb,OAAO,EAAE,IAAI;QACb,cAAc,EAAE,CAAC,EAAE,IAAI,EAAE,GAAG,EAAE,UAAU,EAAE,sBAAsB,KAAK,CAAC,IAAI,oBAAoB,EAAE,CAAC;QACjG,UAAU,EAAE,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,gBAAgB,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC;QAClE,UAAU,EAAE,gCAAgC,KAAK,CAAC,IAAI,wBAAwB;QAC9E,UAAU,EAAE,CAAC,MAAM,EAAE,EAAE;YACrB,mBAAmB,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;YACnC,gBAAgB,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;QAClC,CAAC;KACF,CAAC,CAAC;AACL,CAAC;AAED,SAAS,mBAAmB,CAAC,MAAuB,EAAE,KAAY;IAChE,MAAM,CAAC,SAAS,CAAC,8CAA8C,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE;QAC1E,MAAM;aACH,SAAS,CAAC,+DAA+D,CAAC;aAC1E,SAAS,CAAC,iDAAiD,KAAK,CAAC,IAAI,wBAAwB,CAAC,CAAC;IACpG,CAAC,CAAC,CAAC;AACL,CAAC;AAED,SAAS,gBAAgB,CAAC,MAAuB,EAAE,KAAY;IAC7D,MAAM;SACH,SAAS,CAAC,6CAA6C,KAAK,CAAC,IAAI,yCAAyC,CAAC;SAC3G,SAAS,CAAC,8CAA8C,CAAC;SACzD,KAAK,CAAC,GAAG,EAAE;QACV,MAAM;aACH,SAAS,CAAC,oDAAoD,CAAC;aAC/D,SAAS,CAAC,0BAA0B,CAAC;aACrC,KAAK,CAAC,GAAG,EAAE;YACV,MAAM;iBACH,SAAS,CAAC,0EAA0E,CAAC;iBACrF,SAAS,CAAC,WAAW,CAAC,CAAC;QAC5B,CAAC,CAAC;aACD,SAAS,CAAC,iGAAiG,CAAC,CAAC;IAClH,CAAC,CAAC;SACD,SAAS,CAAC,kEAAkE,CAAC,CAAC;AACnF,CAAC"}
1
+ {"version":3,"file":"count.js","sourceRoot":"","sources":["../../../../../../src/fileCreators/prisma-idb-client/classes/models/api/count.ts"],"names":[],"mappings":";;AAGA,wCAgBC;AAhBD,SAAgB,cAAc,CAAC,UAA4B,EAAE,KAAY;IACvE,UAAU,CAAC,SAAS,CAAC;QACnB,IAAI,EAAE,OAAO;QACb,OAAO,EAAE,IAAI;QACb,cAAc,EAAE,CAAC,EAAE,IAAI,EAAE,GAAG,EAAE,UAAU,EAAE,sBAAsB,KAAK,CAAC,IAAI,oBAAoB,EAAE,CAAC;QACjG,UAAU,EAAE;YACV,EAAE,IAAI,EAAE,OAAO,EAAE,gBAAgB,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE;YACpD,EAAE,IAAI,EAAE,IAAI,EAAE,gBAAgB,EAAE,IAAI,EAAE,IAAI,EAAE,0BAA0B,EAAE;SACzE;QACD,UAAU,EAAE,gCAAgC,KAAK,CAAC,IAAI,wBAAwB;QAC9E,UAAU,EAAE,CAAC,MAAM,EAAE,EAAE;YACrB,MAAM,CAAC,SAAS,CAAC,4CAA4C,KAAK,CAAC,IAAI,kBAAkB,CAAC,CAAC;YAC3F,mBAAmB,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;YACnC,gBAAgB,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;QAClC,CAAC;KACF,CAAC,CAAC;AACL,CAAC;AAED,SAAS,mBAAmB,CAAC,MAAuB,EAAE,KAAY;IAChE,MAAM,CAAC,SAAS,CAAC,8CAA8C,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE;QAC1E,MAAM;aACH,SAAS,CAAC,8CAA8C,KAAK,CAAC,IAAI,aAAa,CAAC;aAChF,SAAS,CAAC,+CAA+C,KAAK,CAAC,IAAI,wBAAwB,CAAC,CAAC;IAClG,CAAC,CAAC,CAAC;AACL,CAAC;AAED,SAAS,gBAAgB,CAAC,MAAuB,EAAE,KAAY;IAC7D,MAAM;SACH,SAAS,CAAC,6CAA6C,KAAK,CAAC,IAAI,yCAAyC,CAAC;SAC3G,SAAS,CAAC,8CAA8C,CAAC;SACzD,KAAK,CAAC,GAAG,EAAE;QACV,MAAM;aACH,SAAS,CAAC,oDAAoD,CAAC;aAC/D,SAAS,CAAC,0BAA0B,CAAC;aACrC,KAAK,CAAC,GAAG,EAAE;YACV,MAAM;iBACH,SAAS,CAAC,8EAA8E,CAAC;iBACzF,SAAS,CAAC,WAAW,CAAC,CAAC;QAC5B,CAAC,CAAC;aACD,SAAS,CACR,qGAAqG,CACtG,CAAC;IACN,CAAC,CAAC;SACD,SAAS,CAAC,kEAAkE,CAAC,CAAC;AACnF,CAAC"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@prisma-idb/idb-client-generator",
3
3
  "description": "Generate types for idb from prisma schema",
4
- "version": "0.2.1",
4
+ "version": "0.3.0",
5
5
  "main": "dist/generator.js",
6
6
  "license": "MIT",
7
7
  "bin": {