Replacing Data Sources
When embedding the Reveal SDK in your application, you can replace the connection details of data sources at runtime. This allows you to change various properties of the data source such as the table, port, database, schema, host, file location, and more depending on the data source being used.
The Reveal SDK utilizes the data source provider to give you, the developer, an opportunity to modify the details of a data source. It also provides the User Context so that you can use information about the current user, and properties of that user, to load the appropriate data.
A data source provider can be created with two steps:
*Step 1 - Create the data source provider.
- ASP.NET
- Java
- Node.js
public class DataSourceProvider : IRVDataSourceProvider
{
public Task<RVDataSourceItem> ChangeDataSourceItemAsync(IRVUserContext userContext, string dashboardId, RVDataSourceItem dataSourceItem)
{
throw new NotImplementedException();
}
public Task<RVDashboardDataSource> ChangeDataSourceAsync(IRVUserContext userContext, RVDashboardDataSource dataSource)
{
throw new NotImplementedException();
}
}
public class DataSourceProvider implements IRVDataSourceProvider {
public RVDashboardDataSource changeDataSource(IRVUserContext userContext, RVDashboardDataSource dataSource) {
return null;
}
public RVDataSourceItem changeDataSourceItem(IRVUserContext userContext, String dashboardsID, RVDataSourceItem dataSourceItem) {
return null;
}
}
const dataSourceProvider = async (userContext: IRVUserContext | null, dataSource: RVDashboardDataSource) => {
return null;
}
const dataSourceItemProvider = async (userContext: IRVUserContext | null, dataSourceItem: RVDataSourceItem) => {
return null;
}
Step 2 - Register the data source provider with the Reveal SDK.
- ASP.NET
- Java
- Node.js
builder.Services.AddControllers().AddReveal( builder =>
{
builder.AddDataSourceProvider<DataSourceProvider>();
});
RevealEngineInitializer.initialize(new InitializeParameterBuilder().
setDataSourceProvider(new DataSourceProvider()).
build());
const revealOptions: RevealOptions = {
dataSourceProvider: dataSourceProvider,
dataSourceItemProvider: dataSourceItemProvider,
}
app.use('/', reveal(revealOptions));