@payloadcms/drizzle 3.29.0-internal.2984e42 → 3.29.0-internal.9400be9
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/dist/updateMany.d.ts.map +1 -1
- package/dist/updateMany.js +36 -6
- package/dist/updateMany.js.map +1 -1
- package/package.json +3 -3
package/dist/updateMany.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"updateMany.d.ts","sourceRoot":"","sources":["../src/updateMany.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"updateMany.d.ts","sourceRoot":"","sources":["../src/updateMany.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAYzC,eAAO,MAAM,UAAU,EAAE,UAiHxB,CAAA"}
|
package/dist/updateMany.js
CHANGED
|
@@ -1,22 +1,33 @@
|
|
|
1
1
|
import toSnakeCase from 'to-snake-case';
|
|
2
|
+
import { chainMethods } from './find/chainMethods.js';
|
|
2
3
|
import buildQuery from './queries/buildQuery.js';
|
|
3
4
|
import { selectDistinct } from './queries/selectDistinct.js';
|
|
4
5
|
import { upsertRow } from './upsertRow/index.js';
|
|
5
6
|
import { getTransaction } from './utilities/getTransaction.js';
|
|
6
|
-
export const updateMany = async function updateMany({ collection: collectionSlug, data, joins: joinQuery, limit, locale, req, returning, select, where: whereToUse }) {
|
|
7
|
+
export const updateMany = async function updateMany({ collection: collectionSlug, data, joins: joinQuery, limit, locale, req, returning, select, sort: sortArg, where: whereToUse }) {
|
|
7
8
|
const db = await getTransaction(this, req);
|
|
8
9
|
const collection = this.payload.collections[collectionSlug].config;
|
|
9
10
|
const tableName = this.tableNameMap.get(toSnakeCase(collection.slug));
|
|
10
|
-
const
|
|
11
|
+
const sort = sortArg !== undefined && sortArg !== null ? sortArg : collection.defaultSort;
|
|
12
|
+
const { joins, orderBy, selectFields, where } = buildQuery({
|
|
11
13
|
adapter: this,
|
|
12
14
|
fields: collection.flattenedFields,
|
|
13
15
|
locale,
|
|
16
|
+
sort,
|
|
14
17
|
tableName,
|
|
15
18
|
where: whereToUse
|
|
16
19
|
});
|
|
17
20
|
let idsToUpdate = [];
|
|
18
21
|
const selectDistinctResult = await selectDistinct({
|
|
19
22
|
adapter: this,
|
|
23
|
+
chainedMethods: orderBy ? [
|
|
24
|
+
{
|
|
25
|
+
args: [
|
|
26
|
+
()=>orderBy.map(({ column, order })=>order(column))
|
|
27
|
+
],
|
|
28
|
+
method: 'orderBy'
|
|
29
|
+
}
|
|
30
|
+
] : [],
|
|
20
31
|
db,
|
|
21
32
|
joins,
|
|
22
33
|
selectFields,
|
|
@@ -25,15 +36,34 @@ export const updateMany = async function updateMany({ collection: collectionSlug
|
|
|
25
36
|
});
|
|
26
37
|
if (selectDistinctResult?.[0]?.id) {
|
|
27
38
|
idsToUpdate = selectDistinctResult?.map((doc)=>doc.id);
|
|
28
|
-
// If id wasn't passed but `where` without any joins, retrieve it with findFirst
|
|
29
39
|
} else if (whereToUse && !joins.length) {
|
|
40
|
+
// If id wasn't passed but `where` without any joins, retrieve it with findFirst
|
|
30
41
|
const _db = db;
|
|
31
42
|
const table = this.tables[tableName];
|
|
32
|
-
const
|
|
33
|
-
id: table.id
|
|
34
|
-
}).from(table).where(where).limit(limit) : await _db.select({
|
|
43
|
+
const query = _db.select({
|
|
35
44
|
id: table.id
|
|
36
45
|
}).from(table).where(where);
|
|
46
|
+
const chainedMethods = [];
|
|
47
|
+
if (typeof limit === 'number' && limit > 0) {
|
|
48
|
+
chainedMethods.push({
|
|
49
|
+
args: [
|
|
50
|
+
limit
|
|
51
|
+
],
|
|
52
|
+
method: 'limit'
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
if (orderBy) {
|
|
56
|
+
chainedMethods.push({
|
|
57
|
+
args: [
|
|
58
|
+
()=>orderBy.map(({ column, order })=>order(column))
|
|
59
|
+
],
|
|
60
|
+
method: 'orderBy'
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
const docsToUpdate = await chainMethods({
|
|
64
|
+
methods: chainedMethods,
|
|
65
|
+
query
|
|
66
|
+
});
|
|
37
67
|
idsToUpdate = docsToUpdate?.map((doc)=>doc.id);
|
|
38
68
|
}
|
|
39
69
|
if (!idsToUpdate.length) {
|
package/dist/updateMany.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/updateMany.ts"],"sourcesContent":["import type { LibSQLDatabase } from 'drizzle-orm/libsql'\nimport type { UpdateMany } from 'payload'\n\nimport toSnakeCase from 'to-snake-case'\n\nimport type { DrizzleAdapter } from './types.js'\n\nimport buildQuery from './queries/buildQuery.js'\nimport { selectDistinct } from './queries/selectDistinct.js'\nimport { upsertRow } from './upsertRow/index.js'\nimport { getTransaction } from './utilities/getTransaction.js'\n\nexport const updateMany: UpdateMany = async function updateMany(\n this: DrizzleAdapter,\n {\n collection: collectionSlug,\n data,\n joins: joinQuery,\n limit,\n locale,\n req,\n returning,\n select,\n where: whereToUse,\n },\n) {\n const db = await getTransaction(this, req)\n const collection = this.payload.collections[collectionSlug].config\n const tableName = this.tableNameMap.get(toSnakeCase(collection.slug))\n\n const { joins, selectFields, where } = buildQuery({\n adapter: this,\n fields: collection.flattenedFields,\n locale,\n tableName,\n where: whereToUse,\n })\n\n let idsToUpdate: (number | string)[] = []\n\n const selectDistinctResult = await selectDistinct({\n adapter: this,\n db,\n joins,\n selectFields,\n tableName,\n where,\n })\n\n if (selectDistinctResult?.[0]?.id) {\n idsToUpdate = selectDistinctResult?.map((doc) => doc.id)\n\n // If id wasn't passed but `where` without any joins, retrieve it with findFirst\n
|
|
1
|
+
{"version":3,"sources":["../src/updateMany.ts"],"sourcesContent":["import type { LibSQLDatabase } from 'drizzle-orm/libsql'\nimport type { UpdateMany } from 'payload'\n\nimport toSnakeCase from 'to-snake-case'\n\nimport type { ChainedMethods, DrizzleAdapter } from './types.js'\n\nimport { chainMethods } from './find/chainMethods.js'\nimport buildQuery from './queries/buildQuery.js'\nimport { selectDistinct } from './queries/selectDistinct.js'\nimport { upsertRow } from './upsertRow/index.js'\nimport { getTransaction } from './utilities/getTransaction.js'\n\nexport const updateMany: UpdateMany = async function updateMany(\n this: DrizzleAdapter,\n {\n collection: collectionSlug,\n data,\n joins: joinQuery,\n limit,\n locale,\n req,\n returning,\n select,\n sort: sortArg,\n where: whereToUse,\n },\n) {\n const db = await getTransaction(this, req)\n const collection = this.payload.collections[collectionSlug].config\n const tableName = this.tableNameMap.get(toSnakeCase(collection.slug))\n\n const sort = sortArg !== undefined && sortArg !== null ? sortArg : collection.defaultSort\n\n const { joins, orderBy, selectFields, where } = buildQuery({\n adapter: this,\n fields: collection.flattenedFields,\n locale,\n sort,\n tableName,\n where: whereToUse,\n })\n\n let idsToUpdate: (number | string)[] = []\n\n const selectDistinctResult = await selectDistinct({\n adapter: this,\n chainedMethods: orderBy\n ? [\n {\n args: [() => orderBy.map(({ column, order }) => order(column))],\n method: 'orderBy',\n },\n ]\n : [],\n db,\n joins,\n selectFields,\n tableName,\n where,\n })\n\n if (selectDistinctResult?.[0]?.id) {\n idsToUpdate = selectDistinctResult?.map((doc) => doc.id)\n } else if (whereToUse && !joins.length) {\n // If id wasn't passed but `where` without any joins, retrieve it with findFirst\n\n const _db = db as LibSQLDatabase\n\n const table = this.tables[tableName]\n\n const query = _db.select({ id: table.id }).from(table).where(where)\n\n const chainedMethods: ChainedMethods = []\n\n if (typeof limit === 'number' && limit > 0) {\n chainedMethods.push({\n args: [limit],\n method: 'limit',\n })\n }\n\n if (orderBy) {\n chainedMethods.push({\n args: [() => orderBy.map(({ column, order }) => order(column))],\n method: 'orderBy',\n })\n }\n\n const docsToUpdate = await chainMethods({\n methods: chainedMethods,\n query,\n })\n\n idsToUpdate = docsToUpdate?.map((doc) => doc.id)\n }\n\n if (!idsToUpdate.length) {\n return []\n }\n\n const results = []\n\n // TODO: We need to batch this to reduce the amount of db calls. This can get very slow if we are updating a lot of rows.\n for (const idToUpdate of idsToUpdate) {\n const result = await upsertRow({\n id: idToUpdate,\n adapter: this,\n data,\n db,\n fields: collection.flattenedFields,\n ignoreResult: returning === false,\n joinQuery,\n operation: 'update',\n req,\n select,\n tableName,\n })\n results.push(result)\n }\n\n if (returning === false) {\n return null\n }\n\n return results\n}\n"],"names":["toSnakeCase","chainMethods","buildQuery","selectDistinct","upsertRow","getTransaction","updateMany","collection","collectionSlug","data","joins","joinQuery","limit","locale","req","returning","select","sort","sortArg","where","whereToUse","db","payload","collections","config","tableName","tableNameMap","get","slug","undefined","defaultSort","orderBy","selectFields","adapter","fields","flattenedFields","idsToUpdate","selectDistinctResult","chainedMethods","args","map","column","order","method","id","doc","length","_db","table","tables","query","from","push","docsToUpdate","methods","results","idToUpdate","result","ignoreResult","operation"],"mappings":"AAGA,OAAOA,iBAAiB,gBAAe;AAIvC,SAASC,YAAY,QAAQ,yBAAwB;AACrD,OAAOC,gBAAgB,0BAAyB;AAChD,SAASC,cAAc,QAAQ,8BAA6B;AAC5D,SAASC,SAAS,QAAQ,uBAAsB;AAChD,SAASC,cAAc,QAAQ,gCAA+B;AAE9D,OAAO,MAAMC,aAAyB,eAAeA,WAEnD,EACEC,YAAYC,cAAc,EAC1BC,IAAI,EACJC,OAAOC,SAAS,EAChBC,KAAK,EACLC,MAAM,EACNC,GAAG,EACHC,SAAS,EACTC,MAAM,EACNC,MAAMC,OAAO,EACbC,OAAOC,UAAU,EAClB;IAED,MAAMC,KAAK,MAAMhB,eAAe,IAAI,EAAES;IACtC,MAAMP,aAAa,IAAI,CAACe,OAAO,CAACC,WAAW,CAACf,eAAe,CAACgB,MAAM;IAClE,MAAMC,YAAY,IAAI,CAACC,YAAY,CAACC,GAAG,CAAC3B,YAAYO,WAAWqB,IAAI;IAEnE,MAAMX,OAAOC,YAAYW,aAAaX,YAAY,OAAOA,UAAUX,WAAWuB,WAAW;IAE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;QACF;QAEAd,cAAciB,cAAcb,IAAI,CAACK,MAAQA,IAAID,EAAE;IACjD;IAEA,IAAI,CAACR,YAAYU,MAAM,EAAE;QACvB,OAAO,EAAE;IACX;IAEA,MAAMS,UAAU,EAAE;IAElB,yHAAyH;IACzH,KAAK,MAAMC,cAAcpB,YAAa;QACpC,MAAMqB,SAAS,MAAMrD,UAAU;YAC7BwC,IAAIY;YACJvB,SAAS,IAAI;YACbxB;YACAY;YACAa,QAAQ3B,WAAW4B,eAAe;YAClCuB,cAAc3C,cAAc;YAC5BJ;YACAgD,WAAW;YACX7C;YACAE;YACAS;QACF;QACA8B,QAAQH,IAAI,CAACK;IACf;IAEA,IAAI1C,cAAc,OAAO;QACvB,OAAO;IACT;IAEA,OAAOwC;AACT,EAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@payloadcms/drizzle",
|
|
3
|
-
"version": "3.29.0-internal.
|
|
3
|
+
"version": "3.29.0-internal.9400be9",
|
|
4
4
|
"description": "A library of shared functions used by different payload database adapters",
|
|
5
5
|
"homepage": "https://payloadcms.com",
|
|
6
6
|
"repository": {
|
|
@@ -53,10 +53,10 @@
|
|
|
53
53
|
"@types/pg": "8.10.2",
|
|
54
54
|
"@types/to-snake-case": "1.0.0",
|
|
55
55
|
"@payloadcms/eslint-config": "3.28.0",
|
|
56
|
-
"payload": "3.29.0-internal.
|
|
56
|
+
"payload": "3.29.0-internal.9400be9"
|
|
57
57
|
},
|
|
58
58
|
"peerDependencies": {
|
|
59
|
-
"payload": "3.29.0-internal.
|
|
59
|
+
"payload": "3.29.0-internal.9400be9"
|
|
60
60
|
},
|
|
61
61
|
"scripts": {
|
|
62
62
|
"build": "pnpm build:swc && pnpm build:types",
|