Web reporting by SQL database PivotData Microservice Documentation

Cube schema is specified in the appsettings.json file.

Cube config for SQL database should have "SourceDb" entry:

  "Id": "orders",
  "Name": "Orders from MySQL sample DB",
  "SourceType": "SqlDb",
  "SourceDb": {
    "Connector": "mysql",
    "ConnectionString": "Server=db4free.net;Database=nreco_sampledb;Uid=nreco;Pwd=HRt5UbVD;",
    "SelectSql": "SELECT o.* FROM orders o LEFT JOIN customers c ON (c.customerNumber=o.customerNumber)"
  "InferSchema": true,  /* dimensions and measures are determined automatically by SELECT query resultset */
  "Dimensions": [],
  "Measures": [],
  "Parameters": []

"SelectSql" determines tabular data that can be used in a pivot table report.
If you don't need to perform any row-level calculations in SQL it is recommended to use SELECT * FROM ... or SELECT mainTablePrefix.* FROM ... instead of explicit list of columns - in this case microservice replaces * with columns list needed for concrete report.

Also it is much more effective to resolve lookups after grouping stage; "Star-schema support" section explains how to configure conditional post-group JOINs.

List of supported connectors:

Connector Description
mssql MS SQL Server, Azure SQL. ConnectionString sample:
Data Source=hostName;Database=db;User=user;Password=password;
Complete list of connection string options: System.Data.SqlClient documentation.
mysql MySql, MariaDB, MemSQL. ConnectionString sample:
Complete list of connection string options: MySqlConnector Driver documentation.
postgresql PostgreSql, Amazon Redshift. ConnectionString sample:
Host=hostName;Port=port;Database=db;User ID=user;Password=password;
For Redshift in some cases you'll need to add: Server Compatibility Mode=Redshift;
Complete list of connection string options: NpgSql .NET Driver documentation.
clickhouse Yandex ClickHouse. ConnectionString sample:
sqlite Local SQLite database file. ConnectionString sample:
Data Source=@CurrentDirectory/App_Data/northwind.db;
(you can use @CurrentDirectory token to specify working directory of the microservice.)
oracle Oracle DB. ConnectionString sample:
Data Source=TORCL;User Id=user;Password=password;
NOTE: currently this connector is supported only in .NET Framework microservice build.
odbc Database that has ODBC Driver. ConnectionString sample:
Driver={any odbc driver's name};OdbcKey=someValue;
(Check concrete ODBC driver's documentation on available connection string options)
In most cases you'll not use "odbc" connector directly - as usually databases have own SQL dialect and they need additional connector setup.
NOTE: this connector is not supported in .NET Core 1.0 microservice build.
<custom connector> Custom connector defined in "PivotDataService.DbConnectors" configuration entry.

NOTE: "InferSchema" is useful for one-time or for development purposes; for production use it is better to specify list of dimensions and measures explicitely to avoid some overhead and get full control over cube member options.


In case of SQL data source dimension name should refer to the column of the specified SQL SELECT:

  "Dimensions": [
       "Name": "status",  /* or 'o.status' */
       "LabelText": "Status"

It is possible to specify SQL expression to calculate dimension values on database level:

       "Name": "orderDate_year",
       "LabelText": "Order Year",   
       "Params": [ "YEAR(orderDate)" ]


Measure parameter (if needed by the aggregator type) should refer to the column returned by "SelectSql" query:

  "Measures": [
       "Type": "Count",  /* other types: "Sum", "Average", "Min", "Max" */
       "Type": "Sum",
       "Params": [ "orderNumber" ]  /* refers to column from SQL query */

Like dimensions each measure should have an unique name; if property "Name" is not specified measure name is generated automatically by its type and list of parameters. For the sample config from above suggested names will be "Count and "SumOforderNumber".


In SQL data sources report parameters could be used in SELECT query as ADO.NET command parameters, for example:

  "Parameters": [
      "Name": "country",
      "DataType": "string",
      "Multivalue": true
    "SelectSql": "SELECT o.* FROM orders o LEFT JOIN customers c ON (c.customerNumber=o.customerNumber) WHERE 1=1 @country[ AND c.country IN ({0}) ]"

Token @country[ AND c.country IN ({0}) ] refers to the parameter with name "country". It works in the following way: if report parameter is empty, nothing is added to WHERE; otherwise "AND c.country IN ('Austria')" condition is added.

NOTE: Multivalue parameters should be used only with "IN" operator.

Star-schema support

If database has star schema with main facts table and dimension tables it is possible to resolve lookup values without JOINs in the main query ("SelectSql"). Instead of that JOINs could be applied after data grouping only if they are needed for the concrete pivot table report; this is possible with "JoinsAfterGroup" config entry.

Lets assume that 'facts' table has 'company_id' column that refers to 'companies' dimension table with 'id' and 'title' columns. The following config illustrates how to configure conditional JOIN to resolve 'Company Title' dimension:

  "SourceDb": {
    "Connector": "...",
    "ConnectionString": "...",
    "SelectSql": "SELECT * FROM facts",
    "JoinsAfterGroup": [
        "JoinSql": "LEFT JOIN companies c ON (c.id=t.company_id)",  /* "SelectSql" has an alias 't' */
        "ApplyOnFields": [ "c.title" ]  /* join is applied only for specfied dimension names */
  "Dimensions": [
      "Name": "c.title",  /* refers to join specified in "JoinsAfterGroup" */
      "LabelText": "Company Title",
      "Params": ["company_id"]  /* FK column in facts table for group-by */

You can use report parameter tokens (@ParamName) in "JoinSql" template in the same manner as in "SelectSql".

Notice for ClickHouse connector: CH has its own JOIN syntax + it doesn't support table aliases for column names; this means that joined table should have unique column names (it is possible to join sub-query to get an unique column name).

Define custom connector

It is possible to customize default database connector setup by defining custom connector in "PivotDataService"."DbConnectors" array:

"DbConnectors" : [
    "BaseConnector": "odbc",
    "Connector": "odbc-access",
    "IdentifierFormat": "[{0}]",
    "ConnectionStringTpl": "Driver={{Microsoft Access Driver (*.mdb)}}; DBQ={0}",
    "SelectWithLimitTpl": "SELECT TOP {1} * FROM ( {0} ) as t",
    "SqlFuncTpl": {
      "Year": "YEAR({0})",
      "Month": "MONTH({0})"
      "Day": "DAY({0})"

In this case custom connector is based on "odbc" and it defines database-specific options for Access ODBC driver.
"SelectWithLimitTpl" and "SqlFuncTpl" are needed only if you want to use "InferSchema" feature that automatically suggests dimensions and measures by SQL query.