@payloadcms/db-sqlite 3.22.0 → 3.23.0-canary.597254e
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"countDistinct.d.ts","sourceRoot":"","sources":["../src/countDistinct.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,aAAa,EAAiB,MAAM,YAAY,CAAA;AAE9D,eAAO,MAAM,aAAa,EAAE,
|
|
1
|
+
{"version":3,"file":"countDistinct.d.ts","sourceRoot":"","sources":["../src/countDistinct.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,aAAa,EAAiB,MAAM,YAAY,CAAA;AAE9D,eAAO,MAAM,aAAa,EAAE,aAiC3B,CAAA"}
|
package/dist/countDistinct.js
CHANGED
|
@@ -1,8 +1,18 @@
|
|
|
1
1
|
import { chainMethods } from '@payloadcms/drizzle';
|
|
2
|
-
import { count } from 'drizzle-orm';
|
|
2
|
+
import { count, sql } from 'drizzle-orm';
|
|
3
3
|
export const countDistinct = async function countDistinct({ db, joins, tableName, where }) {
|
|
4
4
|
const chainedMethods = [];
|
|
5
|
-
|
|
5
|
+
// COUNT(DISTINCT id) is slow on large tables, so we only use DISTINCT if we have to
|
|
6
|
+
const visitedPaths = new Set([]);
|
|
7
|
+
let useDistinct = false;
|
|
8
|
+
joins.forEach(({ condition, queryPath, table })=>{
|
|
9
|
+
if (!useDistinct && queryPath) {
|
|
10
|
+
if (visitedPaths.has(queryPath)) {
|
|
11
|
+
useDistinct = true;
|
|
12
|
+
} else {
|
|
13
|
+
visitedPaths.add(queryPath);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
6
16
|
chainedMethods.push({
|
|
7
17
|
args: [
|
|
8
18
|
table,
|
|
@@ -14,7 +24,7 @@ export const countDistinct = async function countDistinct({ db, joins, tableName
|
|
|
14
24
|
const countResult = await chainMethods({
|
|
15
25
|
methods: chainedMethods,
|
|
16
26
|
query: db.select({
|
|
17
|
-
count: count()
|
|
27
|
+
count: useDistinct ? sql`COUNT(DISTINCT ${this.tables[tableName].id})` : count()
|
|
18
28
|
}).from(this.tables[tableName]).where(where)
|
|
19
29
|
});
|
|
20
30
|
return Number(countResult[0].count);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/countDistinct.ts"],"sourcesContent":["import type { ChainedMethods } from '@payloadcms/drizzle/types'\n\nimport { chainMethods } from '@payloadcms/drizzle'\nimport { count } from 'drizzle-orm'\n\nimport type { CountDistinct, SQLiteAdapter } from './types.js'\n\nexport const countDistinct: CountDistinct = async function countDistinct(\n this: SQLiteAdapter,\n { db, joins, tableName, where },\n) {\n const chainedMethods: ChainedMethods = []\n\n joins.forEach(({ condition, table }) => {\n chainedMethods.push({\n args: [table, condition],\n method: 'leftJoin',\n })\n })\n
|
|
1
|
+
{"version":3,"sources":["../src/countDistinct.ts"],"sourcesContent":["import type { ChainedMethods } from '@payloadcms/drizzle/types'\n\nimport { chainMethods } from '@payloadcms/drizzle'\nimport { count, sql } from 'drizzle-orm'\n\nimport type { CountDistinct, SQLiteAdapter } from './types.js'\n\nexport const countDistinct: CountDistinct = async function countDistinct(\n this: SQLiteAdapter,\n { db, joins, tableName, where },\n) {\n const chainedMethods: ChainedMethods = []\n\n // COUNT(DISTINCT id) is slow on large tables, so we only use DISTINCT if we have to\n const visitedPaths = new Set([])\n let useDistinct = false\n joins.forEach(({ condition, queryPath, table }) => {\n if (!useDistinct && queryPath) {\n if (visitedPaths.has(queryPath)) {\n useDistinct = true\n } else {\n visitedPaths.add(queryPath)\n }\n }\n chainedMethods.push({\n args: [table, condition],\n method: 'leftJoin',\n })\n })\n const countResult = await chainMethods({\n methods: chainedMethods,\n query: db\n .select({\n count: useDistinct ? sql`COUNT(DISTINCT ${this.tables[tableName].id})` : count(),\n })\n .from(this.tables[tableName])\n .where(where),\n })\n\n return Number(countResult[0].count)\n}\n"],"names":["chainMethods","count","sql","countDistinct","db","joins","tableName","where","chainedMethods","visitedPaths","Set","useDistinct","forEach","condition","queryPath","table","has","add","push","args","method","countResult","methods","query","select","tables","id","from","Number"],"mappings":"AAEA,SAASA,YAAY,QAAQ,sBAAqB;AAClD,SAASC,KAAK,EAAEC,GAAG,QAAQ,cAAa;AAIxC,OAAO,MAAMC,gBAA+B,eAAeA,cAEzD,EAAEC,EAAE,EAAEC,KAAK,EAAEC,SAAS,EAAEC,KAAK,EAAE;IAE/B,MAAMC,iBAAiC,EAAE;IAEzC,qFAAqF;IACrF,MAAMC,eAAe,IAAIC,IAAI,EAAE;IAC/B,IAAIC,cAAc;IAClBN,MAAMO,OAAO,CAAC,CAAC,EAAEC,SAAS,EAAEC,SAAS,EAAEC,KAAK,EAAE;QAC5C,IAAI,CAACJ,eAAeG,WAAW;YAC7B,IAAIL,aAAaO,GAAG,CAACF,YAAY;gBAC/BH,cAAc;YAChB,OAAO;gBACLF,aAAaQ,GAAG,CAACH;YACnB;QACF;QACAN,eAAeU,IAAI,CAAC;YAClBC,MAAM;gBAACJ;gBAAOF;aAAU;YACxBO,QAAQ;QACV;IACF;IACA,MAAMC,cAAc,MAAMrB,aAAa;QACrCsB,SAASd;QACTe,OAAOnB,GACJoB,MAAM,CAAC;YACNvB,OAAOU,cAAcT,GAAG,CAAC,eAAe,EAAE,IAAI,CAACuB,MAAM,CAACnB,UAAU,CAACoB,EAAE,CAAC,CAAC,CAAC,GAAGzB;QAC3E,GACC0B,IAAI,CAAC,IAAI,CAACF,MAAM,CAACnB,UAAU,EAC3BC,KAAK,CAACA;IACX;IAEA,OAAOqB,OAAOP,WAAW,CAAC,EAAE,CAACpB,KAAK;AACpC,EAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@payloadcms/db-sqlite",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.23.0-canary.597254e",
|
|
4
4
|
"description": "The officially supported SQLite database adapter for Payload",
|
|
5
5
|
"homepage": "https://payloadcms.com",
|
|
6
6
|
"repository": {
|
|
@@ -69,16 +69,16 @@
|
|
|
69
69
|
"prompts": "2.4.2",
|
|
70
70
|
"to-snake-case": "1.0.0",
|
|
71
71
|
"uuid": "9.0.0",
|
|
72
|
-
"@payloadcms/drizzle": "3.
|
|
72
|
+
"@payloadcms/drizzle": "3.23.0-canary.597254e"
|
|
73
73
|
},
|
|
74
74
|
"devDependencies": {
|
|
75
75
|
"@types/pg": "8.10.2",
|
|
76
76
|
"@types/to-snake-case": "1.0.0",
|
|
77
|
-
"payload": "3.
|
|
77
|
+
"payload": "3.23.0-canary.597254e",
|
|
78
78
|
"@payloadcms/eslint-config": "3.9.0"
|
|
79
79
|
},
|
|
80
80
|
"peerDependencies": {
|
|
81
|
-
"payload": "3.
|
|
81
|
+
"payload": "3.23.0-canary.597254e"
|
|
82
82
|
},
|
|
83
83
|
"scripts": {
|
|
84
84
|
"build": "pnpm build:swc && pnpm build:types",
|