Is there a way to generate the schema for the tables directly from the code, instead of having to access Cube's playground to generate it

NALB 71 Reputation points
2025-01-19T12:42:56.74+00:00

How can I automatically generate the DataModel for the tables from code instead of having to open Cube.js Playground manually?

I am currently using the following code, which works fine for me. However, in order for this to run, I have to open the Cube.js Playground and generate the schema for the tables. Otherwise, the following error appears:

Code:

public async Task<string> GetRoomOccupancyDataAsync()
{
    var query = new
    {
        var query = new { query = new { measures = new[] { "table.count" }, dimensions = new[] { "table.x", "table.y" }, limit = 10 } };
        limit = 10
    };
    var jsonQuery = JsonSerializer.Serialize(query);
    var request = new HttpRequestMessage(HttpMethod.Post, "http://localhost:4000/cubejs-api/v1/load")
    {
        Content = new StringContent(jsonQuery, Encoding.UTF8, "application/json")
    };
    var response = await _httpClient.SendAsync(request);
    if (!response.IsSuccessStatusCode)
    {
        var errorContent = await response.Content.ReadAsStringAsync();
        throw new HttpRequestException($"Error: {response.StatusCode}, Details: {errorContent}");
    }
    return await response.Content.ReadAsStringAsync();
}

Service[0]
      Error  '{"type":"UserError","error":"Cube 'table' not found for path 'table.count'","stack":"Error: Cube 'table' not found for path 'table.count'\n    at CubeEvaluator.byPath (/cube/node_modules/@cubejs-backend/schema-compiler/src/compiler/CubeEvaluator.ts:618:13)\n


How can I automate the schema generation process directly from the code without relying on the Cube.js Playground?

ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,772 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Bruce (SqlWork.com) 70,776 Reputation points
    2025-01-19T17:12:40.58+00:00

    I believe the REST api only supports queries.

    You would create node/javascript app to generate the schema via a program. You can also use the cli which is a node application.

    as suggested this a cube.js issue and you should ask their support.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.