Quickstart Guide for RestBI

Install, Configure the Models, and execute Queries

Deploy RestBI with Docker

To get started quickly with RestBI, you can deploy the RestBI server using Docker. The Docker image is available on DockerHub, making deployment simple and fast.

Pull the Docker image from DockerHub:

docker pull restbi/restbi-server:latest

Run the RestBI server with the following command:

docker run -d -p 3000:3000 restbi/restbi-server:latest

Install the SDK

Next, we need to install the SDK from npm. Open your terminal and run the following command in your project directory:

npm install restbi-sdk

Define Your Data Model

Create a data model file. This file will define the connection, tables, columns, joins, and formulas specific to your database. This keeps connection details secure and allows the RestBI server to generate accurate SQL queries based on your model.

Example: dataModel.ts

const connection: Connection = {
    id: '1',
    name: 'AdventureWorks',
    host: 'host.docker.internal',
    port: 5432,
    user: 'postgres',
    password: 'postgres',
    database: 'AdventureWorks',
    type: DatabaseType.POSTGRES,
};
const AdventureWorksModel: Model = {
    id: 'adventureworks',
    name: 'Adventure Works',
    connection: connection,
    tables: [ /* Define your tables here */ ],
    joins: [ /* Define your joins here */ ],
    formulas: [ /* Define your formulas here */ ],
};
  • Tables and Columns: Learn how to define tables and columns for your model.

  • Joins: Understand how to link your tables with joins.

  • Formulas: Create complex calculations and logic using formulas.

Model files are typically stored on the back-end of your application. Use environmental variables to set sensitive information.

Create a Query

Create a query to fetch data from your database. The query will specify the columns you want to retrieve, any filters, sorting options, and a limit on the number of rows.

Example: query.ts

import { Query } from 'bi-sdk';

export const sampleQuery: Query = {
    columns: ['Total Due', 'Order Date'],
    filters: [
        {
            column: 'Order Date',
            operator: '>=',
            value: new Date('2024-01-01'),
        },
    ],
    limit: 100,
};

This query selects the Total Due and Order Date columns from the database, applies a filter to only include records where the Order Date is on or after January 1, 2024, and limits the results to 100 rows. It's equivalent to a SQL SELECT statement with a WHERE clause and a LIMIT.

Get the Dataset

Use the SDK to send the query to the server. The SDK will handle communication with the server and return the results.

Example: index.ts

import { BIClient } from 'bi-sdk';
import { AdventureWorksModel } from './dataModel';
import { sampleQuery } from './query';

const client = new BIClient('http://localhost:3000');

client.executeQuery(sampleQuery, AdventureWorksModel)
    .then(result => {
        console.log('Query result:', result);
    })
    .catch(error => {
        console.error('Error executing query:', error);
    });

This will return a SQL Result object containing the dataset.

Whats Next - Demo App

The Demo App is a great way for you to see the art of the possible in RestBI.

Drill Anywhere - See how easy it is to add filtering, drilling and more to common charting libraries like AgGrid and ChartJS.

Report Builder - A dynamic interface for self service. See how to combine the Model and Query in a flexible interface.

Model Helper - Explore how models are built, the validate function, and even plugin GPT to generate models for you.

Last updated