Updating & Deleting data on SlicingDice

You'll learn how to update and delete data from your SlicingDice's databases through API or using SQL.


Updating data from databases

Using our update feature you'll be able to update values from desired columns on specified records from your database or also delete values from desired columns, setting them to NULL. Below you'll learn how to do it through API or using SQL.

Using API

You can update records using our API endpoint through our SDK clients or using direct HTTP REST requests. Do it defining an API POST request, containing a JSON object, to the /update endpoint as you can see on the example below.

Notice that you can create any query that will be responsible for specifying what entities should be updated and then you should just define a set parameter defining what values should be updated for these selected entities.

$ curl -X POST https://api.slicingdice.com/v1/update \
    -H 'Authorization: MASTER_OR_WRITE_API_KEY' \
    -H 'Content-Type: application/json' \
    -d '{
   "dimension":"users",
   "query":[
      {
         "entity-id":{
            "equals":"UUID-01"
         }
      }
   ],
   "set":{
      "name":"Mary"
   }
}'
from pyslicer import SlicingDice
slicingdice = SlicingDice(master_key='MASTER_API_KEY')

update_data = {
    "query": [
        {
            "entity-id": {
                "equals": "UUID-01"
            }
        }
    ],
    "set": {
        "name": "Mary"
    },
    "dimension": "users"
}

print(slicingdice.update(update_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");

        JSONObject updateData = new JSONObject()
        .put("query", new JSONArray()
            .put(new JSONObject()
                .put("entity-id", new JSONObject()
                    .put("equals", "UUID-01"))))
        .put("set", new JSONObject()
            .put("name", "Mary"))
        .put("dimension", "users");

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

update_data = {
    "query" => [
        {
            "entity-id" => {
                "equals" => "UUID-01"
            }
        }
    ],
    "set" => {
        "name" => "Mary"
    },
    "dimension" => "users"
}

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

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

const updateData = {
    "query": [
        {
            "entity-id": {
                "equals": "UUID-01"
            }
        }
    ],
    "set": {
        "name": "Mary"
    },
    "dimension": "users"
};

slicingdice.update(updateData).then((resp) => {
    console.log(resp);
}, (err) => {
    console.error(err);
});
<?php
use Slicer\SlicingDice;

$slicingdice = new SlicingDice(array("masterKey" => "MASTER_API_KEY"));

$updateData = array(
    "query" => array(
        array(
            "entity-id" => array(
                "equals" => "UUID-01"
            )
        )
    ),
    "set" => array(
        "name" => "Mary"
    ),
    "dimension" => "users"
);

print_r($slicingdice->update($updateData));
?>
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 updateData = new Dictionary<string, dynamic>{
                {"query", new List<dynamic>{
                    new Dictionary<string, dynamic>{
                        {"entity-id", new Dictionary<string, dynamic>{
                            {"equals", "UUID-01"}
                        }}
                    }
                }},
                {"set", new Dictionary<string, dynamic>{
                    {"name", "Mary"}
                }},
                {"dimension", "users"}
            };

            var result = slicingdice.Update(updateData);
            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)

    updateData := map[string]interface{}{
        "query": []interface{}{
            map[string]interface{}{
                "entity-id": map[string]interface{}{
                    "equals": "UUID-01",
                },
            },
        },
        "set": map[string]interface{}{
            "name": "Mary",
        },
        "dimension": "users",
    }

    fmt.Println(slicingdice.Insert(updateData))
}

Using SQL

You can also update records on your SlicingDice's databases using SQL in two different ways: through a SQL workbench that you may connect using our ODBC/JDBC drivers or through a POST request using our SQL-based API endpoint (/sql). Below you can check how this update can be executed:

UPDATE
  users
SET
  age = NULL
WHERE
  name = 'John';
$ curl -X POST https://api.slicingdice.com/v1/sql \
    -H 'Authorization: MASTER_OR_WRITE_API_KEY' \
    -H 'Content-Type: application/sql' \
    -d 'UPDATE users SET age = NULL WHERE name = 'John';'

Deleting data from databases

Through our delete feature you'll be able to delete values from desired columns on specified records from your database. Below you'll learn how to do it through API or using SQL.

Using API

You can delete records using our API endpoint through our SDK clients or using direct HTTP REST requests. Do it defining an API POST request, containing a JSON object, to the /delete endpoint as you can see on the example below.

Notice that you can define any query that will be responsible for specifying what entities should be deleted from your database and dimension.

curl -X POST https://api.slicingdice.com/v1/delete \
    -H 'Authorization: MASTER_OR_WRITE_API_KEY' \
    -H 'Content-Type: application/json' \
    -d '{
   "dimension":"users",
   "query":[
      {
         "age":{
            "equals":25
         }
      }
   ]
}'
from pyslicer import SlicingDice
slicingdice = SlicingDice(master_key='MASTER_API_KEY')

delete_data = {
    "query": [
        {
            "age": {
                "equals": 25
            }
        }
    ],
    "dimension": "users"
}

print(slicingdice.delete(delete_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");

        JSONObject deleteData = new JSONObject()
        .put("query", new JSONArray()
            .put(new JSONObject()
                .put("age", new JSONObject()
                    .put("equals", 25))))
        .put("dimension", "users");

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

delete_data = {
    "query" => [
        {
            "age" => {
                "equals" => 25
            }
        }
    ],
    "dimension" => "users"
}

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

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

const deleteData = {
    "query": [
        {
            "age": {
                "equals": 25
            }
        }
    ],
    "dimension": "users"
};

slicingdice.delete(deleteData).then((resp) => {
    console.log(resp);
}, (err) => {
    console.error(err);
});
<?php
use Slicer\SlicingDice;

$slicingdice = new SlicingDice(array("masterKey" => "MASTER_API_KEY"));

$deleteData = array(
    "query" => array(
        array(
            "age" => array(
                "equals" => 25
            )
        )
    ),
    "dimension" => "users"
);

print_r($slicingdice->delete($deleteData));
?>
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 deleteData = new Dictionary<string, dynamic>{
                {"query", new List<dynamic>{
                    new Dictionary<string, dynamic>{
                        {"age", new Dictionary<string, dynamic>{
                            {"equals", 25}
                        }}
                    }
                }},
                {"dimension", "users"}
            };

            var result = slicingdice.Delete(deleteData);
            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)

    deleteData := map[string]interface{}{
        "query": []interface{}{
            map[string]interface{}{
                "age": map[string]interface{}{
                    "equals": 25,
                },
            },
        },
        "dimension": "users",
    }

    fmt.Println(slicingdice.Insert(deleteData))
}

Using SQL

You can also delete records on your SlicingDice's databases using SQL in two different ways: through a SQL workbench that you may connect using our ODBC/JDBC drivers or through a POST request using our SQL-based API endpoint (/sql). Below you can check how this deletion can be done:

DELETE FROM
  users
WHERE
  age = 25;
$ curl -X POST https://api.slicingdice.com/v1/sql \
    -H 'Authorization: MASTER_OR_WRITE_API_KEY' \
    -H 'Content-Type: application/sql' \
    -d 'DELETE FROM
            users
        WHERE
            age = 25;'