cancel
Showing results for 
Search instead for 
Did you mean: 

How to create the data model without using sisense cli in my application using compose sdk

enmiwong
8 - Cloud Apps
8 - Cloud Apps

https://sisense.dev/guides/sdk/quickstart-angular.html#:~:text=%23-,Generating%20a%20Data%20Model%20...

from the compose sdk tutorial above, the datamodel can be get by running cli. How do I achieve this dynamically in my application without running the cli? is there any sisense rest api can do this?

I'm getting the DM for building the data visualization as the tutorial provided here: https://www.sisense.com/blog/take-control-of-your-data-visualizations/

2 REPLIES 2

steve
Sisense Team Member
Sisense Team Member

Hi @enmiwong 

You can use Compose SDK without generating a datamodel by dynamically creating 'attributes' using createAttribute in your code. (you'll need to import this from sdk-data)

The minimum needed is the name and expression properties, and depending on the column type you might want more control e.g. granularity and format for date columns.

Expression is a string that consists of the name of the table and column, separated by a period, and enclosed in square brackets as shown below.

 

value: [
    measureFactory.sum(
        createAttribute({
            name: 'Total Revenue',
            expression: '[Commerce.Revenue]',
        })),
]

 Example of creating a date dimension:

createAttribute({
    name: 'Years',
    expression: '[Commerce.Date]',
    granularity: "Years",
    format: 'yyyy'
})

 For more information, check this link to the docs.

Hope that helps!

bogdan-karlenko
Sisense Team Member
Sisense Team Member

To address your API request specifically, `sdk-cli` package uses `/api/datasources/<datasource_name>/fields/search` endpoint to grab initial datasource information which is then converted to attributes:
https://github.com/sisense/compose-sdk-monorepo/blob/main/packages/sdk-query-client/src/query-api-di...

Note: using this endpoint will not give the final result as `sdk-cli` will, some additional code transformations will be required. `createAttribute` mentioned earlier is one of the tools that would help