Registry / data / cubejs-schema-compiler

cubejs-schema-compiler

JSON →
library0.33.8jsnpmunverified

Core schema compiler for Cube.js (v0.33.8), the analytics API platform. This package transforms Cube.js data schema definitions (data model files) into executable SQL queries. It compiles SQL for various databases (Postgres, BigQuery, MySQL, etc.) and supports pre-aggregations, joins, dimensions, measures, and time granularities. Weekly releases under the Cube.js monorepo. Key differentiator: provides an ORM-like layer for analytics SQL generation, enabling complex analytical queries (funnels, retention) without writing raw SQL. Fully typed with TypeScript. Requires Cube.js backend server for execution.

npm install cubejs-schema-compiler
INSTALL
IMPORT
SIG · CUBEJS-SCHEMA-COMP
C
cubejs-schema-compiler
datajavascriptv0.33.8
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.

SchemaCompiler
import { SchemaCompiler } from '@cubejs-backend/schema-compiler'
import SchemaCompiler from '@cubejs-backend/schema-compiler'
Named export, not default. Available in both ESM and CJS.
CubeValidator
import { CubeValidator } from '@cubejs-backend/schema-compiler'
import { SchemaValidator } from '@cubejs-backend/schema-compiler'
Name is CubeValidator, not SchemaValidator.
QueryBuilder
import { QueryBuilder } from '@cubejs-backend/schema-compiler'
For building SQL queries from schema.
DataTypeMapper
import { DataTypeMapper } from '@cubejs-backend/schema-compiler'
Maps cube data types to database-specific types.
BaseMeasure
import { BaseMeasure } from '@cubejs-backend/schema-compiler'
Base class for measure definitions.

Shows how to instantiate SchemaCompiler, define a cube schema, and compile it to an SQL query.

import { SchemaCompiler } from '@cubejs-backend/schema-compiler'; const compiler = new SchemaCompiler({ dataSource: 'my_db', schemaVersion: '1.0.0', authInfo: {}, // optional auth }); const schema = { cubes: [{ name: 'orders', measures: [{ name: 'count', type: 'count' }], dimensions: [{ name: 'status', type: 'string', sql: 'status' }] }] }; const compiled = compiler.compile(schema); console.log(compiled.sql); // outputs generated SQL
Debug
Known issues
breakingCube.js v0.33 requires Node.js >=12 (dropped Node 10 support).
fix
Upgrade to Node.js 12+ (prefer 14 or 16).
affects: >=0.33.0
deprecatedThe 'rename' option in cube schema definitions is deprecated and will be removed in v0.34.
fix
Use 'sql' alias or custom SQL expressions instead.
affects: >=0.32.0
gotchaSchemaCompiler.compile() returns a promise, not synchronously. Forgetting to await leads to undefined SQL.
fix
Use `await compiler.compile(schema)` or handle promise.
affects: >=0.30.0
gotchaWhen using TypeScript, ensure 'esModuleInterop' is true in tsconfig, otherwise imports from ramda/moment may break.
fix
Set `"esModuleInterop": true` in tsconfig.json.
affects: >=0.33.0
deprecatedThe method `SchemaCompiler.registerAdapter()` is deprecated; use constructor's `dataSource` option instead.
fix
Pass `dataSource` in the constructor options.
affects: >=0.31.0
gotchaCube schema files must export a `schema` object, not a class. Common mistake: exporting a class instance.
fix
Export `module.exports = { cubes: [...] }`.
affects: >=0.29.0
breakingv0.30 changed pre-aggregation syntax: `refreshKey` now defaults to `every: '1 hour'` instead of `every: '1 minute'`.
fix
Explicitly set `refreshKey` in pre-aggregations if old behavior needed.
affects: >=0.30.0
Errors
Common errors & fixes
TypeError: Cannot read property 'map' of undefined
SchemaCompiler.compile() called without awaiting, resulting in undefined promise.
fix
Use `const result = await compiler.compile(schema);`
Error: Data source 'my_db' is not configured
Missing or misspelled data source name in constructor options.
fix
Ensure the `dataSource` option matches a configured data source in Cube.js config.
SyntaxError: Unexpected token 'export'
Using ES module export syntax in a CommonJS schema file.
fix
Use `module.exports = { cubes: [...] };` instead of `export default { cubes: [...] };`
Upgrade
Version history
0.33.8latest on npm
Audit
Dependencies
@cubejs-backend/sharedrequiredShared utilities and types used across Cube.js packages
@cubejs-backend/schema-compileroptionalInternal dependency for schema compilation (likely self-referencing)
ramdarequiredFunctional utilities used internally
momentrequiredDate manipulation for time dimension handling
Agent activity
7 hits · last 30 days
node
6
OpenAI (training)
1
Resources