Skip to main content

Cube Client

This document provides an overview and usage examples for functions designed for interacting with the Cube.js backend:

  • getAnalyticsCubeApi
  • getAnalyticsCube
  • getLakehouseCubeApi
  • getLakehouseCube

Overview

The provided functions allow for seamless integration with the Cube.js analytics framework by abstracting the token authentication and query execution processes.

getAnalyticsCubeApi

The getAnalyticsCubeApi function automatically handles the retrieval of an authentication token using the getToken function. This token is then used to authenticate requests made to the Cube.js backend.

getLakehouseCubeApi

Similar to getAnalyticsCubeApi, the getLakehouseCubeApi function automatically handles the retrieval of an authentication token using the getToken function. This token is then used to authenticate requests made to the Cube.js backend.

Common Parameters:

getAnalyticsCube accepts query and options as params. Depending on which function or hook you use, your option param will change. Please refer to each respective function or hook documentation below for more details.

  • query: A Query object or an array of Query objects representing the query(ies) to execute.

getAnalyticsCube

getAnalyticsCube calls load directly and requires a query as a param and options are optional. Please refer to Cube API Documentation: LoadMethodOptions for what options exist.

Usage as a standard function

import { getAnalyticsCube } from '@shared/cube-client'

const query = {
measures: ['TotalSales'],
dimension: 'Sales.date',
filters: [
{
dimension: 'Sales.date',
operator: 'between',
values: ['2020-01-01', '2020-12-31'],
},
],
}

const options = {
subscribe: false,
}

getAnalyticsCube(query, options)
.then((result) => {
console.log('Query result:', result)
})
.catch((error) => {
console.error('Error executing query:', error)
})

getLakehouseCube

Similar to getAnalyticsCube, getLakehouseCube calls load directly and requires a query as a param and options are optional. Please refer to Cube API Documentation: LoadMethodOptions for what options exist.