add-query-mode
Adding a Query Mode
Drizzle-cube has four analysis modes: query, funnel, flow, and retention. Each mode requires coordinated changes across backend (types → query builder → executor → compiler → cache), frontend (types → adapter → store slice → hooks → UI), tests, and an icon. Follow this checklist in order.
Checklist
Backend
-
1. Create type definitions — Create
src/server/types/{mode}.tswith{Mode}QueryConfig,{Mode}ResultRow, and{Mode}ValidationResultinterfaces. Export fromsrc/server/types/index.ts. Add optional{mode}?: {Mode}QueryConfigfield toSemanticQueryinsrc/server/types/query.ts. -
2. Create query builder — Create
src/server/builders/{mode}-query-builder.tswith:has{Mode}(query)detection,validateConfig(config, cubes)validation,build{Mode}Query(config, cubes, context)SQL generation via Drizzle, andtransformResult(rawResult)post-processing. -
3. Integrate with executor — In
src/server/executor.ts, add a{mode}QueryBuilderfield to theQueryExecutorclass, initialize it in the constructor, add detection in theexecute()method, add routing to a newexecute{Mode}QueryWithCache()method, and implementexecute{Mode}Query()anddryRun{Mode}()methods. -
4. Integrate with compiler — In
src/server/compiler.ts, add adryRun{Mode}()public method, add a validation path invalidateQueryAgainstCubes(), and add routing inexplainQuery(). -
5. Update cache utils — In
src/server/cache-utils.ts, addnormalize{Mode}Config()and wire it intonormalizeQuery(). -
6. Database adapter updates (if mode needs DB-specific SQL) — Add abstract methods to
src/server/adapters/base-adapter.tsand implement in postgres, mysql, sqlite, duckdb, snowflake, singlestore, and databend adapters.