Data Manipulation

As mentioned at the beginning of this section, SlashDB creates for your data a REST-ful API, so not only does it allow reading of data but also modifying it in ways that suits you.

To create a new record, send a POST request to a given endpoint containing required data i.e.

curl https://demo.slashdb.com/db/Chinook/Invoice.json -XPOST -i \
-H 'Content-Type: application/json' \
-d '{"BillingPostalCode": "789789",
"InvoiceDate": "2007-01-01T00:00:00",
"BillingAddress": "Theodor-Heuss-Straße 34",
"BillingCountry": "Germany",
"Total": 1.98,
"CustomerId": 2,
"BillingCity": "Stuttgart"}'

HTTP/1.1 201 Created
Server: nginx/1.4.6 (Ubuntu)
Date: Wed, 31 May 2017 10:54:12 GMT
Content-Type: text/html; charset=utf-8
Content-Length: 33
Connection: keep-alive
Location: https://demo.slashdb.com/db/Chinook/Invoice/InvoiceId/456.json

or create multiple records in one go by sending an array of object:

curl https://demo.slashdb.com/db/Chinook/Invoice.json -XPOST -i \
-H 'Content-Type: application/json' \
-d '[{
"BillingPostalCode": "70174",
"InvoiceDate": "2007-01-01T00:00:00",
"BillingAddress": "Theodor-Heuss-Straße 34",
"BillingCountry": "FooLand",
"Total": 1.98,
"CustomerId": 2,
"BillingCity": "Stuttgart"
},{
"BillingPostalCode": "60316",
"InvoiceDate": "2007-01-19T00:00:00",
"BillingAddress": "Berger Straße 10",
"BillingCountry": "FooLand",
"Total": 0.99,
"CustomerId": 37,
"BillingCity": "Frankfurt"
},{
"BillingPostalCode": "10779",
"InvoiceDate": "2007-02-01T00:00:00",
"BillingAddress": "Barbarossastraße 19",
"BillingCountry": "FooLand",
"Total": 1.98,
"CustomerId": 38,
"BillingCity": "Berlin"
}]'

HTTP/1.1 201 Created
Server: nginx/1.4.6 (Ubuntu)
Date: Wed, 31 May 2017 10:59:55 GMT
Content-Type: text/html; charset=utf-8
Content-Length: 101
Connection: keep-alive

/db/Chinook/Invoice/InvoiceId/426
/db/Chinook/Invoice/InvoiceId/427
/db/Chinook/Invoice/InvoiceId/428

You can also send data in XML:

curl https://demo.slashdb.com/db/Chinook/Invoice.xml -XPOST -i \
-H 'Content-Type: text/xml' \
-d '<SlashDB xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns="http://www.vtenterprise.com/slashdb">
<Invoice>
<CustomerId>2</CustomerId>
<InvoiceDate>2007-01-01T00:00:00</InvoiceDate>
<BillingAddress>Theodor-Heuss-Straße 34</BillingAddress>
<BillingCity>Stuttgart</BillingCity>
<BillingCountry>FooLand</BillingCountry>
<BillingPostalCode>70174</BillingPostalCode>
<Total>1.98</Total>
</Invoice>
<Invoice>
<CustomerId>37</CustomerId>
<InvoiceDate>2007-01-19T00:00:00</InvoiceDate>
<BillingAddress>Berger Straße 10</BillingAddress>
<BillingCity>Frankfurt</BillingCity>
<BillingCountry>FooLand</BillingCountry>
<BillingPostalCode>60316</BillingPostalCode>
<Total>0.99</Total>
</Invoice>
<Invoice>
<CustomerId>38</CustomerId>
<InvoiceDate>2007-02-01T00:00:00</InvoiceDate>
<BillingAddress>Barbarossastraße 19</BillingAddress>
<BillingCity>Berlin</BillingCity>
<BillingCountry>FooLand</BillingCountry>
<BillingPostalCode>10779</BillingPostalCode>
<Total>1.98</Total>
</Invoice>
</SlashDB>'

HTTP/1.1 201 Created
Server: nginx/1.4.6 (Ubuntu)
Date: Wed, 31 May 2017 11:02:03 GMT
Content-Type: text/html; charset=utf-8
Content-Length: 101
Connection: keep-alive

/db/Chinook/Invoice/InvoiceId/429
/db/Chinook/Invoice/InvoiceId/430
/db/Chinook/Invoice/InvoiceId/431

or even CVS:

curl https://demo.slashdb.com/db/Chinook/Invoice.csv -XPOST -i \
-H 'Content-Type: text/csv' \
-d 'CustomerId,InvoiceDate,BillingAddress,BillingCity,BillingState,BillingCountry,BillingPostalCode,Total
2,2007-01-01 00:00:00,Theodor-Heuss-Straße 34,Stuttgart,,FooLand,70174,1.98
37,2007-01-19 00:00:00,Berger Straße 10,Frankfurt,,FooLand,60316,0.99
38,2007-02-01 00:00:00,Barbarossastraße 19,Berlin,,FooLand,10779,1.98'

HTTP/1.1 201 Created
Server: nginx/1.4.6 (Ubuntu)
Date: Wed, 31 May 2017 11:05:16 GMT
Content-Type: text/html; charset=utf-8
Content-Length: 101
Connection: keep-alive

/db/Chinook/Invoice/InvoiceId/432
/db/Chinook/Invoice/InvoiceId/433
/db/Chinook/Invoice/InvoiceId/434

Change the POST method to PUT and you'll be able to update existing records much like you created new entries i.e.

curl https://demo.slashdb.com/db/Chinook/Invoice/InvoiceId/1.json -XPUT -i \
-H 'Content-Type: application/json' -d '{"BillingPostalCode": "456"}'

HTTP/1.1 204 No Content
Server: nginx/1.4.6 (Ubuntu)
Date: Wed, 31 May 2017 11:20:48 GMT
Connection: keep-alive
Access-Control-Allow-Origin: *

Just as with POST you can use different formats i.e.

curl https://demo.slashdb.com/db/Chinook/Invoice/InvoiceId/2.csv -XPUT -i \
-H 'Content-Type: text/csv' \
-d 'BillingPostalCode
567'

HTTP/1.1 204 No Content
Server: nginx/1.4.6 (Ubuntu)
Date: Wed, 31 May 2017 11:20:06 GMT
Connection: keep-alive

Performing a DELETE request type will allow you to delete record on demand. If you only want to delete a specific record, it's best to use a URL containing its Primary Key i.e.

# firstly, create a new MediaType record
curl https://demo.slashdb.com/db/Chinook/MediaType.json -XPOST -i -d '{"Name": "cat"}'

HTTP/1.1 201 Created
Server: nginx/1.4.6 (Ubuntu)
Date: Wed, 31 May 2017 11:34:36 GMT
Content-Type: text/html; charset=utf-8
Content-Length: 35
Connection: keep-alive
Location: https://demo.slashdb.com/db/Chinook/MediaType/MediaTypeId/6.json

# and using the returned 'Location'
# let's issue an DELETE request on it using its primary key
curl https://demo.slashdb.com/db/Chinook/MediaType/MediaTypeId/6.json -XDELETE -i

HTTP/1.1 204 No Content
Server: nginx/1.4.6 (Ubuntu)
Date: Wed, 31 May 2017 11:24:34 GMT
Connection: keep-alive

This will delete an MediaType entry with its PK field MediaTypeId, set to 6.

When deleting by a non-PK field i.e.

# create two MediaType records with the 'Name': "Tape"
curl https://demo.slashdb.com/db/Chinook/MediaType.json -XPOST -i -d '{"Name": "Tape"}'

HTTP/1.1 201 Created
Server: nginx/1.4.6 (Ubuntu)
Date: Wed, 31 May 2017 11:34:36 GMT
Content-Type: text/html; charset=utf-8
Content-Length: 35
Connection: keep-alive
Location: https://demo.slashdb.com/db/Chinook/MediaType/MediaTypeId/7.json


curl https://demo.slashdb.com/db/Chinook/MediaType.json -XPOST -i -d '{"Name": "Tape"}'

HTTP/1.1 201 Created
Server: nginx/1.4.6 (Ubuntu)
Date: Wed, 31 May 2017 11:34:36 GMT
Content-Type: text/html; charset=utf-8
Content-Length: 35
Connection: keep-alive
Location: https://demo.slashdb.com/db/Chinook/MediaType/MediaTypeId/8.json


# issue a DELETE request
# deleting all MediaType records with "Name": "Tape"
curl https://demo.slashdb.com/db/Chinook/MediaType/Name/Tape.json -XDELETE -i

HTTP/1.1 204 No Content
Server: nginx/1.4.6 (Ubuntu)
Date: Wed, 31 May 2017 11:38:16 GMT
Connection: keep-alive


# now let's make sure that both records are properly erased
curl https://demo.slashdb.com/db/Chinook/MediaType/Name/Tape.json -i
HTTP/1.1 200 OK
Server: nginx/1.4.6 (Ubuntu)
Date: Fri, 09 Jun 2017 11:52:39 GMT
Content-Type: application/json
Content-Length: 2
Connection: keep-alive

[]

be careful, as this will delete all MediaType entries where Name is Tape.

Also remember that if a given table has other tables referencing it, and ON DELETE CASCADE has not been set, a 409 status code will be returned.

results matching ""

    No results matching ""