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;
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.
fixUpgrade 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.
fixOnly 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.
fixEnsure 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.
fixImport createCubeApp from 'drizzle-cube/adapters/express' instead of 'drizzle-cube'.
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