Skip to content

Cube Semantic Layer in VS Code

Cube is a semantic layer (headless BI platform) that defines metrics once and serves them consistently across tools. Key characteristics include:

  • Semantic data model: Data is modeled as cubes, each exposing dimensions, measures, and segments over an underlying data source
  • Postgres-compatible SQL API: Query cubes with SQL over the Postgres wire protocol
  • Consistent metrics: Measures (aggregations) and pre-defined joins are evaluated server-side, so results are consistent regardless of the client
  • Caching and pre-aggregations: Cube accelerates queries with a caching layer and pre-aggregated rollups

Cube is ideal for exploring governed metrics and data models from a SQL client without re-implementing business logic.

To connect to Cube in DBCode:

  1. Open the DBCode Extension: Launch Visual Studio Code and open the DBCode extension.
  2. Add a New Connection: Click on the “Add Connection” icon.
  3. Complete connection form: Select Cube as the database type and enter:
    • Host and port of Cube’s SQL API (default: 15432)
    • Username and password (the CUBEJS_SQL_USER / CUBEJS_SQL_PASSWORD credentials)
    • Optionally, a REST API URL and API token to enrich the schema from Cube’s /meta endpoint (descriptions, measure vs dimension roles, primary keys, views, and relationships)
  4. Connect: Click save to connect to your Cube deployment.
  5. Start Exploring: Browse cubes, inspect their columns, and run analytical queries.

For detailed instructions on connecting to databases, refer to the Connect article.

DBCode enhances your Cube experience with:

  • Schema browsing: All schemas are discovered, with cubes and views appearing as typed objects and their dimensions, measures, and segments listed as columns
  • SQL query editor: Write and execute Cube SQL (including MEASURE(...) aggregations and pre-defined cross-cube joins) with syntax highlighting
  • /meta enrichment (when a REST API URL is set): columns are annotated as measures or dimensions with descriptions, primary keys are marked, views are separated from cubes, and segments are hidden
  • Relationships: Cube’s predefined joins are surfaced as foreign keys between cubes
  • Execution plans: Run EXPLAIN to see Cube’s logical and physical query plan
  • Monitoring: A Sessions and Locks view of the SQL API
  • Schema inspection: View a cube’s column layout as a reference CREATE TABLE definition
  • Row counts: Enable “Update Statistics” in the connection’s introspection settings to include per-cube row counts
  • Data exploration: Preview and export query results
  • Query cancellation and row limits: Long-running queries can be cancelled, and the editor row limit is applied to results

Cubes are defined in your Cube data model rather than via DDL, so connections are read-only: there is no insert, update, delete, or schema modification.

Cube evaluates numeric dimensions as 64-bit floating point, so integer values beyond 2^53 are returned with reduced precision. This is a characteristic of Cube’s SQL engine.

By using Cube with DBCode, you can explore your semantic model and governed metrics directly within Visual Studio Code.

For more information about Cube, visit cube.dev.