{"version":3,"sources":["../src/deleteMany.ts"],"sourcesContent":["import type { DeleteMany } from 'payload'\n\nimport { inArray } from 'drizzle-orm'\nimport toSnakeCase from 'to-snake-case'\n\nimport type { DrizzleAdapter } from './types.js'\n\nimport { findMany } from './find/findMany.js'\nimport { buildQuery } from './queries/buildQuery.js'\nimport { getTransaction } from './utilities/getTransaction.js'\n\nexport const deleteMany: DeleteMany = async function deleteMany(\n this: DrizzleAdapter,\n { collection, req, where: whereArg },\n) {\n const collectionConfig = this.payload.collections[collection].config\n\n const tableName = this.tableNameMap.get(toSnakeCase(collectionConfig.slug))\n\n const table = this.tables[tableName]\n\n const { joins, where } = buildQuery({\n adapter: this,\n fields: collectionConfig.flattenedFields,\n locale: req?.locale,\n tableName,\n where: whereArg,\n })\n\n let whereToUse = where\n\n if (joins?.length) {\n // Difficult to support joins (through where referencing other tables) in deleteMany. => 2 separate queries.\n // We can look into supporting this using one single query (through a subquery) in the future, though that's difficult to do in a generic way.\n const result = await findMany({\n adapter: this,\n fields: collectionConfig.flattenedFields,\n joins: false,\n limit: 0,\n locale: req?.locale,\n page: 1,\n pagination: false,\n req,\n select: {\n id: true,\n },\n tableName,\n where: whereArg,\n })\n\n whereToUse = inArray(\n table.id,\n result.docs.map((doc) => doc.id),\n )\n }\n\n const db = await getTransaction(this, req)\n\n await this.deleteWhere({\n db,\n tableName,\n where: whereToUse,\n })\n}\n"],"names":["inArray","toSnakeCase","findMany","buildQuery","getTransaction","deleteMany","collection","req","where","whereArg","collectionConfig","payload","collections","config","tableName","tableNameMap","get","slug","table","tables","joins","adapter","fields","flattenedFields","locale","whereToUse","length","result","limit","page","pagination","select","id","docs","map","doc","db","deleteWhere"],"mappings":"AAEA,SAASA,OAAO,QAAQ,cAAa;AACrC,OAAOC,iBAAiB,gBAAe;AAIvC,SAASC,QAAQ,QAAQ,qBAAoB;AAC7C,SAASC,UAAU,QAAQ,0BAAyB;AACpD,SAASC,cAAc,QAAQ,gCAA+B;AAE9D,OAAO,MAAMC,aAAyB,eAAeA,WAEnD,EAAEC,UAAU,EAAEC,GAAG,EAAEC,OAAOC,QAAQ,EAAE;IAEpC,MAAMC,mBAAmB,IAAI,CAACC,OAAO,CAACC,WAAW,CAACN,WAAW,CAACO,MAAM;IAEpE,MAAMC,YAAY,IAAI,CAACC,YAAY,CAACC,GAAG,CAACf,YAAYS,iBAAiBO,IAAI;IAEzE,MAAMC,QAAQ,IAAI,CAACC,MAAM,CAACL,UAAU;IAEpC,MAAM,EAAEM,KAAK,EAAEZ,KAAK,EAAE,GAAGL,WAAW;QAClCkB,SAAS,IAAI;QACbC,QAAQZ,iBAAiBa,eAAe;QACxCC,QAAQjB,KAAKiB;QACbV;QACAN,OAAOC;IACT;IAEA,IAAIgB,aAAajB;IAEjB,IAAIY,OAAOM,QAAQ;QACjB,4GAA4G;QAC5G,8IAA8I;QAC9I,MAAMC,SAAS,MAAMzB,SAAS;YAC5BmB,SAAS,IAAI;YACbC,QAAQZ,iBAAiBa,eAAe;YACxCH,OAAO;YACPQ,OAAO;YACPJ,QAAQjB,KAAKiB;YACbK,MAAM;YACNC,YAAY;YACZvB;YACAwB,QAAQ;gBACNC,IAAI;YACN;YACAlB;YACAN,OAAOC;QACT;QAEAgB,aAAazB,QACXkB,MAAMc,EAAE,EACRL,OAAOM,IAAI,CAACC,GAAG,CAAC,CAACC,MAAQA,IAAIH,EAAE;IAEnC;IAEA,MAAMI,KAAK,MAAMhC,eAAe,IAAI,EAAEG;IAEtC,MAAM,IAAI,CAAC8B,WAAW,CAAC;QACrBD;QACAtB;QACAN,OAAOiB;IACT;AACF,EAAC"}