Registry / analytics / drizzle-cube

drizzle-cube

JSON →
library0.5.7jsnpmunverified

Drizzle ORM-first semantic layer for type-safe analytics. v0.5.7 – rapid development with weekly releases. Provides Cube.js-compatible API, SQL injection protection via parameterized queries, and multi-tenant security built-in. Differentiators: full TypeScript inference from Drizzle schema, MCP server for AI agent integration, includes React dashboard components. Supports Express, Fastify, Hono adapters. Requires Drizzle ORM 0.45+.

npm install drizzle-cube
INSTALL
IMPORT
SIG · DRIZZLE-CUBE
D
drizzle-cube
analyticsjavascriptv0.5.7
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

defineCube
import { defineCube } from 'drizzle-cube/server'
import { defineCube } from 'drizzle-cube'
Server-side functions are under 'drizzle-cube/server' subpath; client under 'drizzle-cube/client'.
createCubeApp
import { createCubeApp } from 'drizzle-cube/adapters/hono'
import { createCubeApp } from 'drizzle-cube'
Adapter-specific export; replace 'hono' with 'express' or 'fastify' for other adapters.
AnalysisBuilder
import { AnalysisBuilder } from 'drizzle-cube/client'
const AnalysisBuilder = require('drizzle-cube/client')
Client components are ESM-only and require React; CJS require will fail if module is not transpiled.

Defines an Employees cube with measures, dimensions, join to Departments, and a Hono API server with multi-tenant security.

import { defineCube } from 'drizzle-cube/server'; import { createCubeApp } from 'drizzle-cube/adapters/hono'; import { Hono } from 'hono'; import { eq } from 'drizzle-orm'; import { drizzle } from 'drizzle-orm/node-postgres'; import { employees, departments } from './schema'; export const employeesCube = defineCube('Employees', { sql: (ctx) => ({ from: employees, where: eq(employees.organisationId, ctx.securityContext.organisationId) }), joins: { Departments: { targetCube: () => departmentsCube, relationship: 'belongsTo', on: [{ source: employees.departmentId, target: departments.id }] } }, measures: { count: { type: 'count', sql: employees.id }, avgSalary: { type: 'avg', sql: employees.salary } }, dimensions: { name: { type: 'string', sql: employees.name }, email: { type: 'string', sql: employees.email }, hiredAt: { type: 'time', sql: employees.hiredAt } } }); const app = new Hono(); const cubeApp = createCubeApp({ cubes: [employeesCube], drizzle: drizzle(process.env.DATABASE_URL ?? ''), schema: { employees }, extractSecurityContext: async (req) => ({ organisationId: req.header('x-org-id') ?? '' }) }); app.route('/', cubeApp); export default app;
Debug
Known issues
breakingv0.5.0 changed import paths: server functions moved to 'drizzle-cube/server', adapters to 'drizzle-cube/adapters/*'.
fix
Update imports to use subpath exports (e.g., 'drizzle-cube/server').
affects: <0.5.0
deprecatedUsage of 'drizzle-cube/client' components requires React 18; React 16/17 are not supported.
fix
Upgrade React to ^18.0.0 or do not import client components.
affects: >=0.5.0
gotchaThe 'sql' option in defineCube must be a function receiving context, not a static object. Static objects can leak security context.
fix
Wrap sql config in a function: sql: (ctx) => ({ ... }).
affects: >=0.5.0
breakingPeer dependency 'drizzle-orm' bumped to ^0.45.0 in v0.5.0; older versions incompatible.
fix
Update drizzle-orm to 0.45+.
affects: >=0.5.0
gotchaCube names must be unique per app; duplicate names cause undefined behavior.
fix
Ensure each cube has a unique name string in defineCube.
affects: >=0.5.0
Errors
Common errors & fixes
Cannot find module 'drizzle-cube/server' or its corresponding type declarations.
Importing from subpath that does not exist in older version.
fix
Upgrade drizzle-cube to ^0.5.0 and ensure TypeScript 'moduleResolution' is 'node16' or 'bundler'.
Module '"drizzle-cube/client"' has no exported member 'AnalysisBuilder'.
Trying to import client component from server environment.
fix
Only import from 'drizzle-cube/client' in React client code; check tsconfig jsx setting.
TypeError: Cannot read properties of undefined (reading 'organisationId')
Security context not passed or extractSecurityContext returned undefined.
fix
Ensure extractSecurityContext returns an object with required fields; check middleware order.
Error: No adapter provided for 'express'. Did you import from 'drizzle-cube/adapters/express'?
Using wrong import path for adapter.
fix
Import createCubeApp from 'drizzle-cube/adapters/express' instead of 'drizzle-cube'.
Upgrade
Version history
0.5.7latest on npm
Audit
Dependencies
drizzle-ormrequiredCore dependency for schema and query building
reactoptionalClient components require React 18
@openai/sdkoptionalAI integration via MCP server may need OpenAI or Anthropic SDK
Agent activity
30 hits · last 30 days
node
28
OpenAI (training)
1
Resources
drizzle-cube — npm install drizzle-cube · libregistry