Forum Discussion
2 Replies
- steveSisense Employee
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-karlenkoSisense Employee
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-dispatcher/query-api-dispatcher.ts#L26
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