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
1 line
3.3 KiB
Plaintext
1 line
3.3 KiB
Plaintext
{"version":3,"sources":["../../src/queries/selectDistinct.ts"],"sourcesContent":["import type { QueryPromise, SQL } from 'drizzle-orm'\nimport type { SQLiteColumn, SQLiteSelect } from 'drizzle-orm/sqlite-core'\n\nimport type {\n DrizzleAdapter,\n DrizzleTransaction,\n GenericColumn,\n TransactionSQLite,\n} from '../types.js'\nimport type { BuildQueryJoinAliases } from './buildQuery.js'\n\ntype Args = {\n adapter: DrizzleAdapter\n db: DrizzleAdapter['drizzle'] | DrizzleTransaction\n forceRun?: boolean\n hasAggregates?: boolean\n joins: BuildQueryJoinAliases\n query?: (args: { query: SQLiteSelect }) => SQLiteSelect\n selectFields: Record<string, GenericColumn>\n tableName: string\n where: SQL\n}\n\n/**\n * Selects distinct records from a table only if there are joins that need to be used, otherwise return null\n */\nexport const selectDistinct = ({\n adapter,\n db,\n forceRun,\n hasAggregates,\n joins,\n query: queryModifier = ({ query }) => query,\n selectFields,\n tableName,\n where,\n}: Args): QueryPromise<{ id: number | string }[] & Record<string, GenericColumn>> => {\n if (forceRun || Object.keys(joins).length > 0) {\n let query: SQLiteSelect\n const table = adapter.tables[tableName]\n\n // With hasAggregate we use groupBy so we don't need to use selectDistinct in that case\n // @ts-expect-error - Drizzle types are not accurate here\n let selectFunc: TransactionSQLite['selectDistinct'] = hasAggregates\n ? db.select\n : db.selectDistinct\n\n // bind this otherwise we get TypeError: Cannot read properties of undefined (reading 'session')\n selectFunc = selectFunc.bind(db)\n\n query = selectFunc(selectFields as Record<string, SQLiteColumn>)\n .from(table)\n .$dynamic()\n\n if (where) {\n query = query.where(where)\n }\n\n joins.forEach(({ type, condition, table }) => {\n query = query[type ?? 'leftJoin'](table, condition)\n })\n\n if (hasAggregates && '_selected' in selectFields) {\n // @ts-expect-error - Drizzle types are not accurate here\n query = query.groupBy(selectFields['_selected'])\n }\n\n return queryModifier({\n query,\n }) as unknown as QueryPromise<{ id: number | string }[] & Record<string, GenericColumn>>\n }\n}\n"],"names":["selectDistinct","adapter","db","forceRun","hasAggregates","joins","query","queryModifier","selectFields","tableName","where","Object","keys","length","table","tables","selectFunc","select","bind","from","$dynamic","forEach","type","condition","groupBy"],"mappings":"AAuBA;;CAEC,GACD,OAAO,MAAMA,iBAAiB,CAAC,EAC7BC,OAAO,EACPC,EAAE,EACFC,QAAQ,EACRC,aAAa,EACbC,KAAK,EACLC,OAAOC,gBAAgB,CAAC,EAAED,KAAK,EAAE,GAAKA,KAAK,EAC3CE,YAAY,EACZC,SAAS,EACTC,KAAK,EACA;IACL,IAAIP,YAAYQ,OAAOC,IAAI,CAACP,OAAOQ,MAAM,GAAG,GAAG;QAC7C,IAAIP;QACJ,MAAMQ,QAAQb,QAAQc,MAAM,CAACN,UAAU;QAEvC,uFAAuF;QACvF,yDAAyD;QACzD,IAAIO,aAAkDZ,gBAClDF,GAAGe,MAAM,GACTf,GAAGF,cAAc;QAErB,gGAAgG;QAChGgB,aAAaA,WAAWE,IAAI,CAAChB;QAE7BI,QAAQU,WAAWR,cAChBW,IAAI,CAACL,OACLM,QAAQ;QAEX,IAAIV,OAAO;YACTJ,QAAQA,MAAMI,KAAK,CAACA;QACtB;QAEAL,MAAMgB,OAAO,CAAC,CAAC,EAAEC,IAAI,EAAEC,SAAS,EAAET,KAAK,EAAE;YACvCR,QAAQA,KAAK,CAACgB,QAAQ,WAAW,CAACR,OAAOS;QAC3C;QAEA,IAAInB,iBAAiB,eAAeI,cAAc;YAChD,yDAAyD;YACzDF,QAAQA,MAAMkB,OAAO,CAAChB,YAAY,CAAC,YAAY;QACjD;QAEA,OAAOD,cAAc;YACnBD;QACF;IACF;AACF,EAAC"} |