Files
klz-cables.com/.pnpm-store/v10/files/32/804b32edfcb2d02c9972f92c3486711514154a7e1e6dff528b53f6c63d625db4e3f35d23cc511c6ec26d688ebff17bf5ac4af485e0af340c1dcfa5b733b1b0
Marc Mintel 5397309103
Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 20s
Build & Deploy / 🧪 QA (push) Failing after 34s
Build & Deploy / 🏗️ Build (push) Has started running
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Smoke Test (push) Has been cancelled
Build & Deploy / ⚡ Lighthouse (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
fix(products): fix breadcrumbs and product filtering (backport from main)
2026-02-24 16:04:21 +01:00

29 lines
1.3 KiB
Plaintext

/**
* Selects distinct records from a table only if there are joins that need to be used, otherwise return null
*/ export const selectDistinct = ({ adapter, db, forceRun, hasAggregates, joins, query: queryModifier = ({ query })=>query, selectFields, tableName, where })=>{
if (forceRun || Object.keys(joins).length > 0) {
let query;
const table = adapter.tables[tableName];
// With hasAggregate we use groupBy so we don't need to use selectDistinct in that case
// @ts-expect-error - Drizzle types are not accurate here
let selectFunc = hasAggregates ? db.select : db.selectDistinct;
// bind this otherwise we get TypeError: Cannot read properties of undefined (reading 'session')
selectFunc = selectFunc.bind(db);
query = selectFunc(selectFields).from(table).$dynamic();
if (where) {
query = query.where(where);
}
joins.forEach(({ type, condition, table })=>{
query = query[type ?? 'leftJoin'](table, condition);
});
if (hasAggregates && '_selected' in selectFields) {
// @ts-expect-error - Drizzle types are not accurate here
query = query.groupBy(selectFields['_selected']);
}
return queryModifier({
query
});
}
};
//# sourceMappingURL=selectDistinct.js.map