Modeling Databases Schemas

You'll be presented the API commands to model your database schemas, defining dimensions and columns.


Creating a dimension

You can create one or more dimensions for a given database through a POST request on the /dimension endpoint authenticated with a Database Key.

$ curl -X POST https://api.slicingdice.com/v1/dimension \
    -H 'Authorization: MASTER_API_KEY' \
    -H 'Content-Type: application/json' \
    -d '[
	{
		"name": "users",
		"api-name": "users"
	},
	{
		"name": "sales",
		"api-name": "sales"
	}
]'
Request Parameters
Parameter Mandatory Description
name Yes Column name as it'll show in Control Panel, up to 80 characters. All ASCII characters are allowed, except ', " and _.
api-name Yes Dimension name, up to 80 characters, as it'll be referenced in API requests. The api-name should be lowercase containing just letters, numbers and dashes.
Request Response
{
    "status": "success",
    "api-name": [
        "users",
        "sales"
    ]
}

Dimensions Relationship

You can create related dimensions based on the Star Schema for a given database through a POST request also on the /dimension endpoint authenticated with a Database Key defining Fact dimensions and Regular dimensions.

curl -X POST https://api.slicingdice.com/v1/dimension \
    -H 'Authorization: MASTER_API_KEY \
    -H 'Content-Type: application/json' \
    -d '[
   {
      "name":"Fact_Sales",
      "api-name":"fact_sales",
      "relational-model-type":"fact"
   },
   {
      "name":"Dim_Product",
      "api-name":"dim_product",
      "relational-model-type":"dimension"
   },
   {
      "name":"Dim_Store",
      "api-name":"dim_store",
      "relational-model-type":"dimension"
   },
   {
      "name":"Dim-Date",
      "api-name":"dim_date",
      "relational-model-type":"dimension"
   }
]'
Request Parameters
Parameter Mandatory Description
name Yes Column name as it'll show in Control Panel, up to 80 characters. All ASCII characters are allowed, except ', " and _.
api-name Yes Dimension name, up to 80 characters, as it'll be referenced in API requests. The api-name should be lowercase containing just letters, numbers and dashes.
relational-model-type Yes Defines if it is a "fact" dimension or a regular "dimension"

Deleting a dimension

You can delete one dimension for a given database through a DELETE request on the /dimension endpoint authenticated with a Database Key.

$ curl -X DEL https://api.slicingdice.com/v1/dimension \
    -H 'Authorization: MASTER_API_KEY' \
    -H 'Content-Type: application/json' \
    -d '{
	"api-name": "users-dimension"
}'
Request Response
{
    "status": "success",
    "api-name": [
        "users-dimension"
    ]
}

Creating a column

You can create one or more columns for a given database and dimension through a POST request on the /column endpoint authenticated with a Database Key.

$ curl -X POST https://api.slicingdice.com/v1/column \
    -H 'Authorization: MASTER_API_KEY' \
    -H 'Content-Type: application/json' \
    -d '[
        {
            "name": "User State",
            "api-name": "state",
            "type": "string",
            "description": "State where the user lives",
            "storage": "latest-value"
        }, {
            "name": "User Age",
            "api-name": "age",
            "type": "integer",
            "storage": "latest-value"
        }
    ]'
from pyslicer import SlicingDice
slicingdice = SlicingDice(master_key='MASTER_API_KEY', uses_test_endpoint=True)

insert_data = [
    {
        "type": "string",
        "storage": "latest-value",
        "api-name": "state",
        "name": "User State",
        "description": "State where the user lives"
    },
    {
        "type": "integer",
        "storage": "latest-value",
        "api-name": "age",
        "name": "User Age"
    }
]
print(slicingdice.create_column(insert_data))
import com.slicingdice.jslicer.SlicingDice;
import java.io.IOException;
import org.json.JSONObject;
import org.json.JSONArray;

public class Example {
    public static void main(String[] args) throws IOException {
        SlicingDice slicingdice = new SlicingDice("MASTER_API_KEY", true);

        JSONArray insertData = new JSONArray()
        .put(new JSONObject()
            .put("type", "string")
            .put("storage", "latest-value")
            .put("api-name", "state")
            .put("name", "User State")
            .put("description", "State where the user lives"))
        .put(new JSONObject()
            .put("type", "integer")
            .put("storage", "latest-value")
            .put("api-name", "age")
            .put("name", "User Age"));
        JSONObject result = slicingdice.createColumn(insertData);
        System.out.println(result.toString());
    }
}
require 'rbslicer'
slicingdice = SlicingDice.new(master_key: 'MASTER_API_KEY', uses_test_endpoint: true)

insert_data = [
    {
        "type" => "string",
        "storage" => "latest-value",
        "api-name" => "state",
        "name" => "User State",
        "description" => "State where the user lives"
    },
    {
        "type" => "integer",
        "storage" => "latest-value",
        "api-name" => "age",
        "name" => "User Age"
    }
]
puts slicingdice.create_column(insert_data)
const SlicingDice = require('slicerjs');

const usesTestEndpoint = true;
const slicingdice = new SlicingDice({masterKey: 'MASTER_API_KEY'}, usesTestEndpoint);

const insertData = [
    {
        "type": "string",
        "storage": "latest-value",
        "api-name": "state",
        "name": "User State",
        "description": "State where the user lives"
    },
    {
        "type": "integer",
        "storage": "latest-value",
        "api-name": "age",
        "name": "User Age"
    }
];

slicingdice.createColumn(insertData).then((resp) => {
    console.log(resp);
}, (err) => {
    console.error(err);
});
<?php
use Slicer\SlicingDice;
$usesTestEndpoint = true;
$slicingdice = new SlicingDice(array("masterKey" => "MASTER_API_KEY"), $usesTestEndpoint);

$insertData = array(
    array(
        "type" => "string",
        "storage" => "latest-value",
        "api-name" => "state",
        "name" => "User State",
        "description" => "State where the user lives"
    ),
    array(
        "type" => "integer",
        "storage" => "latest-value",
        "api-name" => "age",
        "name" => "User Age"
    )
);

print_r($slicingdice->createColumn($insertData));
?>
using System.Collections.Generic;
using Slicer;
using Newtonsoft.Json;

namespace SlicerTester.Console
{
    class Program
    {
        static void Main(string[] args)
        {
            var slicingdice = new SlicingDice(masterKey: "MASTER_API_KEY", usesTestEndpoint: true);

            var insertData = new List<dynamic>{
                new Dictionary<string, dynamic>{
                    {"type", "string"},
                    {"storage", "latest-value"},
                    {"api-name", "state"},
                    {"name", "User State"},
                    {"description", "State where the user lives"}
                },
                new Dictionary<string, dynamic>{
                    {"type", "integer"},
                    {"storage", "latest-value"},
                    {"api-name", "age"},
                    {"name", "User Age"}
                }
            };

            var result = slicingdice.createColumn(insertData);
            System.Console.WriteLine(JsonConvert.SerializeObject(result).ToString());
        }
    }
}
package main
import (
    "fmt"
    "github.com/SlicingDice/slicingdice-go/slicingdice"
)
func main() {
    keys := new(slicingdice.APIKey)
    keys.MasterKey = "MASTER_API_KEY"
    slicingdice := slicingdice.New(keys, 60)
    slicingdice.Test = true

    insertData := []interface{}{
        map[string]interface{}{
            "type": "string",
            "storage": "latest-value",
            "api-name": "state",
            "name": "User State",
            "description": "State where the user lives",
        },
        map[string]interface{}{
            "type": "integer",
            "storage": "latest-value",
            "api-name": "age",
            "name": "User Age",
        },
    }

    fmt.Println(slicingdice.createColumn(insertData))
}
Request Parameters
Parameter Mandatory Description
name Yes Column name as it'll show in Control Panel, up to 80 characters. All ASCII characters are allowed, except ', " and _.
type Yes The type of the column according to the supported data types.
api-name No Column name, up to 80 characters, as it'll be referenced in API requests. Usually, the api-name is a lowercase version of the name, replacing spaces and non-alphanumeric characters by dashes. If you don't inform an api-name, one will be automatically generated for you.
description No Column description
dimension No The dimension that will hold the column created. If you don't specify a dimension the column will be created on the default dimension.
storage No Defines whether the column stores only the latest value inserted ("latest-value") or all inserted values ("list-of-values").
Request Response
{
    "status": "success",
    "api-name": [
        "state",
        "age"
    ]
}

Deleting a column

You can delete one column for a given database through a DELETE request on the /column endpoint authenticated with a Database Key.

Notice that you can only delete one column per request and that you should specify just an existent column api-name.

$ curl -X DEL https://api.slicingdice.com/v1/column \
    -H 'Authorization: MASTER_API_KEY' \
    -H 'Content-Type: application/json' \
    -d '{
	"api-name": "age"
}'
Request Response
{
    "status": "success",
    "api-name": [
        "age"
    ]
}

Editing a column

You can edit one column for a given database through a PUT request on the /column endpoint authenticated with a Database Key.

$ curl -X PUT https://api.slicingdice.com/v1/column \
    -H 'Authorization: MASTER_API_KEY' \
    -H 'Content-Type: application/json' \
    -d '{
	"api-name": "age",
    "name": "new-age",
    "description": "New column name"
}'
Request Parameters
Parameter Mandatory Description
api-name Yes Valid and existent api-name so SlicingDice can identify and edit it.
name No Column name to be edited as it'll show in Control Panel, up to 80 characters. All ASCII characters are allowed, except ', " and _.
description No Column description.
Request Response
{
    "status": "success",
    "api-name": [
        "new-age"
    ]
}

Listing columns information

You can list all columns and their information for a given database through a GET request on the /column endpoint authenticated with a Database Key.

$ curl -X GET https://api.slicingdice.com/v1/column \
    -H 'Authorization: MASTER_API_KEY' \
    -H 'Content-Type: application/json'
from pyslicer import SlicingDice
slicingdice = SlicingDice(master_key='MASTER_API_KEY')

print(slicingdice.get_columns())
import com.slicingdice.jslicer.SlicingDice;
import java.io.IOException;
import org.json.JSONObject;
import org.json.JSONArray;

public class Example {
    public static void main(String[] args) throws IOException {
        SlicingDice slicingdice = new SlicingDice("MASTER_API_KEY");

        JSONObject result = slicingdice.getColumns();
        System.out.println(result.toString());
    }
}
require 'rbslicer'
slicingdice = SlicingDice.new(master_key: 'MASTER_API_KEY')

puts slicingdice.get_columns()
const SlicingDice = require('slicerjs');

const slicingdice = new SlicingDice({masterKey: 'MASTER_API_KEY'});

slicingdice.getColumns().then((resp) => {
    console.log(resp);
}, (err) => {
    console.error(err);
});
<?php
use Slicer\SlicingDice;
$slicingdice = new SlicingDice(array("masterKey" => "MASTER_API_KEY"));

print_r($slicingdice->getColumns());
?>
using System.Collections.Generic;
using Slicer;
using Newtonsoft.Json;

namespace SlicerTester.Console
{
    class Program
    {
        static void Main(string[] args)
        {
            var slicingdice = new SlicingDice(masterKey: "MASTER_API_KEY");

            var result = slicingdice.getColumns();
            System.Console.WriteLine(JsonConvert.SerializeObject(result).ToString());
        }
    }
}
package main
import (
    "fmt"
    "github.com/SlicingDice/slicingdice-go/slicingdice"
)
func main() {
    keys := new(slicingdice.APIKey)
    keys.MasterKey = "MASTER_API_KEY"
    slicingdice := slicingdice.New(keys, 60)

    fmt.Println(slicingdice.getColumns())
}
Request Response
{
    "status": "success",
    "count": 3,
    "users": {
        "active": [
            {
                "name": "entity-id",
                "api-name": "entity-id",
                "description": "",
                "type": "unique-id",
                "category": "general",
                "storage": "latest-value"
            },
            {
                "name": "User State",
                "api-name": "state",
                "description": "State where the user lives",
                "type": "string",
                "category": "general",
                "storage": "latest-value"
            }
        ],
        "inactive": [
            {
                "name": "User Age",
                "api-name": "age",
                "description": "Age of the user",
                "type": "integer",
                "category": "general",
                "storage": "latest-value"
            }
        ]
    },
    "took": 0.026
}

Creating columns relations

You can create a column relation for a given database and dimension through a POST request on the /column/relation endpoint authenticated with a Database Key.

Notice that if the relation name you provide on the request already exists for this database and dimension, the columns you define will be added to this existent relation.

curl -X POST https://api.slicingdice.com/v1/column/relation \
    -H 'Authorization: MASTER_API_KEY' \
    -H 'Content-Type: application/json' \
    -d '{
           "name": "relation-01",
           "columns": ["page-view", "referer"],
           "dimension": "page-views"
    	  }'
Request Parameters
Parameter Mandatory Description
name Yes Name you can define for this column relation.
columns Yes List of existent time-series columns that you want to be related.
dimension No If you don't define a dimension where the relation will be created, we consider that you are using the default.
Request Response
{
    "status": "success",
    "columns_on_relation": [
        "page-view",
        "referer"
    ]
}

Listing columns relations

You can list all existent columns relations and their information for a given database through a GET request on the /column/relation endpoint authenticated with a Database Key.

curl -X GET https://api.slicingdice.com/v1/column/relation \
    -H 'Authorization: MASTER_API_KEY' \
    -H 'Content-Type: application/json'
Request Response
{
  "status": "success",
  "took": 0.017,
  "count": 0,
  "relations": {}
}

Deleting columns relations

You can remove columns from an existent column relation for a given database and dimension through a DEL request on the /column/relation endpoint authenticated with a Database Key.

curl -X DELETE https://api.slicingdice.com/v1/column/relation \
    -H 'Authorization: MASTER_API_KEY' \
    -H 'Content-Type: application/json'
    -d '{
           "name": "relation-01",
           "columns": ["page-view"],
           "dimension": "page-views"
    }'
Request Parameters
Parameter Mandatory Description
name Yes Name of an existent column relation.
columns Yes List of existent time-series columns that you want to remove from a given column relation.
dimension No If you don't define a dimension where the given relation exists, we consider that you are using the default.
Request Response
{
  "status": "success",
  "columns_deleted": [
    "page-view"
  ]
}