- Notifications
You must be signed in to change notification settings - Fork2
Official JavaScript client for SlicingDice, Data Warehouse and Analytics Database as a Service.
License
SlicingDice/slicingdice-javascript
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Official JavaScript client forSlicingDice - Data Warehouse and Analytics Database as a Service.
SlicingDice is a serverless, SQL & API-based, easy-to-use and really cost-effective alternative to Amazon Redshift and Google BigQuery.
If you are new to SlicingDice, check ourquickstart guide and learn to use it in 15 minutes.
Please refer to theSlicingDice official documentation for more information onhow to create a database,how to insert data,how to make queries,how to create columns,SlicingDice restrictions andAPI details.
Whether you want to test the client installation or simply check more examples on how the client works, take a look attests and examples directory.
In order to install the JavaScript client, you only need to usenpm
.
npm install slicerjs
The following code snippet is an example of how to add and query datausing the SlicingDice javascript client. We entry data informinguser1@slicingdice.com
has age 22 and then query the database forthe number of users with age between 20 and 40 years old.If this is the first register ever entered into the system,the answer should be 1.
varSlicingDice=require('slicerjs');// only required for Node.js// Configure the clientconstclient=newSlicingDice({masterKey:'MASTER_API_KEY',writeKey:'WRITE_API_KEY',readKey:'READ_API_KEY'});// Inserting dataconstinsertData={"user1@slicingdice.com":{"age":22},"auto-create":["dimension","column"]};client.insert(insertData);// Querying dataconstqueryData={"query-name":"users-between-20-and-40","query":[{"age":{"range":[20,40]}}]};client.countEntity(queryData).then((resp)=>{console.log(resp);},(err)=>{console.err(err);});
SlicingDice
encapsulates logic for sending requests to the API. Its methods are thin layers around theAPI endpoints, so their parameters and return values are JSON-likeObject
objects with the same syntax as theAPI endpoints
SlicingDice(apiKeys)
apiKeys (Object)
-API key to authenticate requests with the SlicingDice API.
Get information about current database. This method corresponds to aGET
request at/database
.
letSlicingDice=require('slicerjs');constclient=newSlicingDice({masterKey:'MASTER_API_KEY'});client.getDatabase().then((resp)=>{console.log(resp);},(err)=>{console.error(err);});
{"name":"Database 1","description":"My first database","dimensions": ["default","users" ],"updated-at":"2017-05-19T14:27:47.417415","created-at":"2017-05-12T02:23:34.231418"}
Get all created columns, both active and inactive ones. This method corresponds to aGET request at /column.
letSlicingDice=require('slicerjs');constclient=newSlicingDice({masterKey:'MASTER_API_KEY'});client.getColumns().then((resp)=>{console.log(resp);},(err)=>{console.error(err);});
{"active": [ {"name":"Model","api-name":"car-model","description":"Car models from dealerships","type":"string","category":"general","cardinality":"high","storage":"latest-value" } ],"inactive": [ {"name":"Year","api-name":"car-year","description":"Year of manufacture","type":"integer","category":"general","storage":"latest-value" } ]}
Create a new column. This method corresponds to aPOST request at /column.
letSlicingDice=require('slicerjs');constclient=newSlicingDice({masterKey:'MASTER_API_KEY'});column={"name":"Year","api-name":"year","type":"integer","description":"Year of manufacturing","storage":"latest-value"};client.createColumn(column).then((resp)=>{console.log(resp);},(err)=>{console.error(err);});
{"status":"success","api-name":"year"}
Insert data to existing entities or create new entities, if necessary. This method corresponds to aPOST request at /insert.
letSlicingDice=require('slicerjs');constclient=newSlicingDice({masterKey:'MASTER_API_KEY',writeKey:'WRITE_API_KEY'});constinsertData={"user1@slicingdice.com":{"car-model":"Ford Ka","year":2016},"user2@slicingdice.com":{"car-model":"Honda Fit","year":2016},"user3@slicingdice.com":{"car-model":"Toyota Corolla","year":2010,"test-drives":[{"value":"NY","date":"2016-08-17T13:23:47+00:00"},{"value":"NY","date":"2016-08-17T13:23:47+00:00"},{"value":"CA","date":"2016-04-05T10:20:30Z"}]},"user4@slicingdice.com":{"car-model":"Ford Ka","year":2005,"test-drives":{"value":"NY","date":"2016-08-17T13:23:47+00:00"}}};client.insert(insertData).then((resp)=>{console.log(resp);},(err)=>{console.error(err);});
{"status":"success","inserted-entities":4,"inserted-columns":10,"took":0.023}
Verify which entities exist in a tabdimensionle (usesdefault
dimension if not provided) given a list of entity IDs. This method corresponds to aPOST request at /query/exists/entity.
letSlicingDice=require('slicerjs');constclient=newSlicingDice({masterKey:'MASTER_KEY',readKey:'READ_KEY'});ids=["user1@slicingdice.com","user2@slicingdice.com","user3@slicingdice.com"];client.existsEntity(ids).then((resp)=>{console.log(resp);},(err)=>{console.error(err);});
{"status":"success","exists": ["user1@slicingdice.com","user2@slicingdice.com" ],"not-exists": ["user3@slicingdice.com" ],"took":0.103}
Count the number of inserted entities in the whole database. This method corresponds to aPOST request at /query/count/entity/total.
letSlicingDice=require('slicerjs');constclient=newSlicingDice({masterKey:'MASTER_KEY',readKey:'READ_KEY'});client.countEntityTotal().then((resp)=>{console.log(resp);},(err)=>{console.error(err);});
{"status":"success","result": {"total":42 },"took":0.103}
Count the total number of inserted entities in the given dimensions. This method corresponds to aPOST request at /query/count/entity/total.
letSlicingDice=require('slicerjs');constclient=newSlicingDice({masterKey:'MASTER_KEY',readKey:'READ_KEY'});constdimensions=["default"];client.countEntityTotal(dimensions).then((resp)=>{console.log(resp);},(err)=>{console.error(err);});
{"status":"success","result": {"total":42 },"took":0.103}
Count the number of entities matching the given query. This method corresponds to aPOST request at /query/count/entity.
letSlicingDice=require('slicerjs');constclient=newSlicingDice({masterKey:'MASTER_KEY',readKey:'READ_KEY'});constquery=[{"query-name":"corolla-or-fit","query":[{"car-model":{"equals":"toyota corolla"}},"or",{"car-model":{"equals":"honda fit"}}],"bypass-cache":false},{"query-name":"ford-ka","query":[{"car-model":{"equals":"ford ka"}}],"bypass-cache":false}];client.countEntity(query).then((resp)=>{console.log(resp);},(err)=>{console.error(err);});
{"result":{"ford-ka":2,"corolla-or-fit":2 },"took":0.083,"status":"success"}
Count the number of occurrences for time-series events matching the given query. This method corresponds to aPOST request at /query/count/event.
letSlicingDice=require('slicerjs');constclient=newSlicingDice({masterKey:'MASTER_KEY',readKey:'READ_KEY'});constquery=[{"query-name":"test-drives-in-ny","query":[{"test-drives":{"equals":"NY","between":["2016-08-16T00:00:00Z","2016-08-18T00:00:00Z"]}}],"bypass-cache":true},{"query-name":"test-drives-in-ca","query":[{"test-drives":{"equals":"CA","between":["2016-04-04T00:00:00Z","2016-04-06T00:00:00Z"]}}],"bypass-cache":true}];client.countEvent(query).then((resp)=>{console.log(resp);},(err)=>{console.error(err);});
{"result":{"test-drives-in-ny":3,"test-drives-in-ca":0 },"took":0.063,"status":"success"}
Return the top values for entities matching the given query. This method corresponds to aPOST request at /query/top_values.
letSlicingDice=require('slicerjs');constclient=newSlicingDice({masterKey:'MASTER_KEY',readKey:'READ_KEY'});query={"car-year":{"year":2},"car models":{"car-model":3}}client.topValues(query).then((resp)=>{console.log(resp);},(err)=>{console.error(err);});
{"result":{"car models":{"car-model":[ {"quantity":2,"value":"ford ka" }, {"quantity":1,"value":"honda fit" }, {"quantity":1,"value":"toyota corolla" } ] },"car-year":{"year":[ {"quantity":2,"value":"2016" }, {"quantity":1,"value":"2010" } ] } },"took":0.034,"status":"success"}
Return the aggregation of all columns in the given query. This method corresponds to aPOST request at /query/aggregation.
letSlicingDice=require('slicerjs');constclient=newSlicingDice({masterKey:'MASTER_KEY',readKey:'READ_KEY'});query={"query":[{"year":2},{"car-model":2,"equals":["honda fit","toyota corolla"]}]};client.aggregation(query).then((resp)=>{console.log(resp);},(err)=>{console.error(err);});
{"result":{"year":[ {"quantity":2,"value":"2016","car-model":[ {"quantity":1,"value":"honda fit" } ] }, {"quantity":1,"value":"2005" } ] },"took":0.079,"status":"success"}
Get all saved queries. This method corresponds to aGET request at /query/saved.
letSlicingDice=require('slicerjs');constclient=newSlicingDice({masterKey:'MASTER_KEY'});client.getSavedQueries().then((resp)=>{console.log(resp);},(err)=>{console.error(err);});
{"status":"success","saved-queries": [ {"name":"users-in-ny-or-from-ca","type":"count/entity","query": [ {"state": {"equals":"NY" } },"or", {"state-origin": {"equals":"CA" } } ],"cache-period":100 }, {"name":"users-from-ca","type":"count/entity","query": [ {"state": {"equals":"NY" } } ],"cache-period":60 } ],"took":0.103}
Create a saved query at SlicingDice. This method corresponds to aPOST request at /query/saved.
letSlicingDice=require('slicerjs');constclient=newSlicingDice({masterKey:'MASTER_KEY'});query={"name":"my-saved-query","type":"count/entity","query":[{"car-model":{"equals":"honda fit"}},"or",{"car-model":{"equals":"toyota corolla"}}],"cache-period":100}client.createSavedQuery(query).then((resp)=>{console.log(resp);},(err)=>{console.error(err);});
{"took":0.053,"query":[ {"car-model":{"equals":"honda fit" } },"or", {"car-model":{"equals":"toyota corolla" } } ],"name":"my-saved-query","type":"count/entity","cache-period":100,"status":"success"}
Update an existing saved query at SlicingDice. This method corresponds to aPUT request at /query/saved/QUERY_NAME.
letSlicingDice=require('slicerjs');constclient=newSlicingDice({masterKey:'MASTER_KEY'});newQuery={"type":"count/entity","query":[{"car-model":{"equals":"ford ka"}},"or",{"car-model":{"equals":"toyota corolla"}}],"cache-period":100};client.updateSavedQuery("my-saved-query",newQuery).then((resp)=>{console.log(resp);},(err)=>{console.error(err);});
{"took":0.037,"query":[ {"car-model":{"equals":"ford ka" } },"or", {"car-model":{"equals":"toyota corolla" } } ],"type":"count/entity","cache-period":100,"status":"success"}
Executed a saved query at SlicingDice. This method corresponds to aGET request at /query/saved/QUERY_NAME.
letSlicingDice=require('slicerjs');constclient=newSlicingDice({masterKey:'MASTER_KEY',readKey:'READ_KEY'});client.getSavedQuery("my-saved-query").then((resp)=>{console.log(resp);},(err)=>{console.error(err);});
{"result":{"query":2 },"took":0.035,"query":[ {"car-model":{"equals":"honda fit" } },"or", {"car-model":{"equals":"toyota corolla" } } ],"type":"count/entity","status":"success"}
Delete a saved query at SlicingDice. This method corresponds to aDELETE request at /query/saved/QUERY_NAME.
letSlicingDice=require('slicerjs');constclient=newSlicingDice({masterKey:'MASTER_KEY'});client.deleteSavedQuery("my-saved-query").then((resp)=>{console.log(resp);},(err)=>{console.error(err);});
{"took":0.029,"query":[ {"car-model":{"equals":"honda fit" } },"or", {"car-model":{"equals":"toyota corolla" } } ],"type":"count/entity","cache-period":100,"status":"success","deleted-query":"my-saved-query"}
Retrieve inserted values for entities matching the given query. This method corresponds to aPOST request at /data_extraction/result.
letSlicingDice=require('slicerjs');constclient=newSlicingDice({masterKey:'MASTER_KEY',readKey:'READ_KEY'});query={"query":[{"car-model":{"equals":"ford ka"}},"or",{"car-model":{"equals":"toyota corolla"}}],"columns":["car-model","year"],"limit":2};client.result(query).then((resp)=>{console.log(resp);},(err)=>{console.error(err);});
{"took":0.113,"next-page":null,"data":{"customer5@mycustomer.com":{"year":"2005","car-model":"ford ka" },"user1@slicingdice.com":{"year":"2016","car-model":"ford ka" } },"page":1,"status":"success"}
Retrieve inserted values as well as their relevance for entities matching the given query. This method corresponds to aPOST request at /data_extraction/score.
letSlicingDice=require('slicerjs');constclient=newSlicingDice({masterKey:'MASTER_KEY',readKey:'READ_KEY'});query={"query":[{"car-model":{"equals":"ford ka"}},"or",{"car-model":{"equals":"toyota corolla"}}],"columns":["car-model","year"],"limit":2};client.score(query).then((resp)=>{console.log(resp);},(err)=>{console.error(err);});
{"took":0.063,"next-page":null,"data":{"user3@slicingdice.com":{"score":1,"year":"2010","car-model":"toyota corolla" },"user2@slicingdice.com":{"score":1,"year":"2016","car-model":"honda fit" } },"page":1,"status":"success"}
Retrieve inserted values using a SQL syntax. This method corresponds to a POST request at /query/sql.
letSlicingDice=require('slicerjs');constclient=newSlicingDice({masterKey:'MASTER_KEY',readKey:'READ_KEY'});query="SELECT COUNT(*) FROM default WHERE age BETWEEN 0 AND 49";client.sql(query).then((resp)=>{console.log(resp);},(err)=>{console.error(err);});
letSlicingDice=require('slicerjs');constclient=newSlicingDice({masterKey:'MASTER_KEY',readKey:'READ_KEY'});query="INSERT INTO default([entity-id], name, age) VALUES(1, 'john', 10)";client.sql(query).then((resp)=>{console.log(resp);},(err)=>{console.error(err);});
{"took":0.063,"result":[ {"COUNT":3} ],"count":1,"status":"success"}
About
Official JavaScript client for SlicingDice, Data Warehouse and Analytics Database as a Service.
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Contributors12
Uh oh!
There was an error while loading.Please reload this page.