Skip to content

Commit 4eaaee6

Browse files
authored
Merge pull request #20 from SlicingDice/feature/change-table-to-dimension
Change table to dimension on code
2 parents 990ee28 + fcb48f9 commit 4eaaee6

File tree

4 files changed

+81
-51
lines changed

4 files changed

+81
-51
lines changed

README.md

+63-33
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,14 @@ const client = new SlicingDice({
4040
masterKey: 'MASTER_API_KEY',
4141
writeKey: 'WRITE_API_KEY',
4242
readKey: 'READ_API_KEY'
43-
}, usesTestEndpoint = true);
43+
});
4444

4545
// Inserting data
4646
const insertData = {
4747
4848
"age": 22
4949
},
50-
"auto-create": ["table", "column"]
50+
"auto-create": ["dimension", "column"]
5151
};
5252
client.insert(insertData);
5353

@@ -76,15 +76,10 @@ client.countEntity(queryData).then((resp) => {
7676

7777
`SlicingDice` encapsulates logic for sending requests to the API. Its methods are thin layers around the [API endpoints](https://docs.slicingdice.com/docs/api-details), so their parameters and return values are JSON-like `Object` objects with the same syntax as the [API endpoints](https://docs.slicingdice.com/docs/api-details)
7878

79-
### Attributes
80-
81-
* `sdAddress (String)` - [Connection endpoint](https://docs.slicingdice.com/docs/api-keys) to use when generating requests to SlicingDice.
82-
8379
### Constructor
8480

85-
`SlicingDice(apiKeys, usesTestEndpoint)`
81+
`SlicingDice(apiKeys)`
8682
* `apiKeys (Object)` - [API key](https://docs.slicingdice.com/docs/api-keys) to authenticate requests with the SlicingDice API.
87-
* `usesTestEndpoint (boolean)` - If false the client will send requests to production end-point, otherwise to tests end-point.
8883

8984
### `getDatabase()`
9085
Get information about current database. This method corresponds to a `GET` request at `/database`.
@@ -96,7 +91,7 @@ let SlicingDice = require('slicerjs');
9691

9792
const client = new SlicingDice({
9893
masterKey: 'MASTER_API_KEY'
99-
}, usesTestEndpoint = false);
94+
});
10095

10196
client.getDatabase().then((resp) => {
10297
console.log(resp);
@@ -111,7 +106,7 @@ client.getDatabase().then((resp) => {
111106
{
112107
"name": "Database 1",
113108
"description": "My first database",
114-
"tables": [
109+
"dimensions": [
115110
"default",
116111
"users"
117112
],
@@ -130,7 +125,7 @@ let SlicingDice = require('slicerjs');
130125

131126
const client = new SlicingDice({
132127
masterKey: 'MASTER_API_KEY'
133-
}, usesTestEndpoint = true);
128+
});
134129

135130
client.getColumns().then((resp) => {
136131
console.log(resp);
@@ -177,7 +172,7 @@ let SlicingDice = require('slicerjs');
177172

178173
const client = new SlicingDice({
179174
masterKey: 'MASTER_API_KEY'
180-
}, usesTestEndpoint = true);
175+
});
181176

182177
column = {
183178
"name": "Year",
@@ -214,7 +209,7 @@ let SlicingDice = require('slicerjs');
214209
const client = new SlicingDice({
215210
masterKey: 'MASTER_API_KEY',
216211
writeKey: 'WRITE_API_KEY'
217-
}, usesTestEndpoint = true);
212+
});
218213

219214
const insertData = {
220215
@@ -269,8 +264,8 @@ client.insert(insertData).then((resp) => {
269264
}
270265
```
271266

272-
### `existsEntity(ids, table = null)`
273-
Verify which entities exist in a table (uses `default` table if not provided) given a list of entity IDs. This method corresponds to a [POST request at /query/exists/entity](https://docs.slicingdice.com/docs/exists).
267+
### `existsEntity(ids, dimension = null)`
268+
Verify which entities exist in a tabdimensionle (uses `default` dimension if not provided) given a list of entity IDs. This method corresponds to a [POST request at /query/exists/entity](https://docs.slicingdice.com/docs/exists).
274269

275270
#### Request example
276271

@@ -280,7 +275,7 @@ let SlicingDice = require('slicerjs');
280275
const client = new SlicingDice({
281276
masterKey: 'MASTER_KEY',
282277
readKey: 'READ_KEY'
283-
}, usesTestEndpoint = true);
278+
});
284279

285280
ids = [
286281
@@ -322,7 +317,7 @@ let SlicingDice = require('slicerjs');
322317
const client = new SlicingDice({
323318
masterKey: 'MASTER_KEY',
324319
readKey: 'READ_KEY'
325-
}, usesTestEndpoint = true);
320+
});
326321

327322
client.countEntityTotal().then((resp) => {
328323
console.log(resp);
@@ -343,8 +338,8 @@ client.countEntityTotal().then((resp) => {
343338
}
344339
```
345340

346-
### `countEntityTotal(tables)`
347-
Count the total number of inserted entities in the given tables. This method corresponds to a [POST request at /query/count/entity/total](https://docs.slicingdice.com/docs/total#section-counting-specific-tables).
341+
### `countEntityTotal(dimensions)`
342+
Count the total number of inserted entities in the given dimensions. This method corresponds to a [POST request at /query/count/entity/total](https://docs.slicingdice.com/docs/total#section-counting-specific-tables).
348343

349344
#### Request example
350345

@@ -354,11 +349,11 @@ let SlicingDice = require('slicerjs');
354349
const client = new SlicingDice({
355350
masterKey: 'MASTER_KEY',
356351
readKey: 'READ_KEY'
357-
}, usesTestEndpoint = true);
352+
});
358353

359-
const tables = ["default"];
354+
const dimensions = ["default"];
360355

361-
client.countEntityTotal(tables).then((resp) => {
356+
client.countEntityTotal(dimensions).then((resp) => {
362357
console.log(resp);
363358
}, (err) => {
364359
console.error(err);
@@ -388,7 +383,7 @@ let SlicingDice = require('slicerjs');
388383
const client = new SlicingDice({
389384
masterKey: 'MASTER_KEY',
390385
readKey: 'READ_KEY'
391-
}, usesTestEndpoint = true);
386+
});
392387

393388
const query = [
394389
{
@@ -452,7 +447,7 @@ let SlicingDice = require('slicerjs');
452447
const client = new SlicingDice({
453448
masterKey: 'MASTER_KEY',
454449
readKey: 'READ_KEY'
455-
}, usesTestEndpoint = true);
450+
});
456451

457452
const query = [
458453
{
@@ -518,7 +513,7 @@ let SlicingDice = require('slicerjs');
518513
const client = new SlicingDice({
519514
masterKey: 'MASTER_KEY',
520515
readKey: 'READ_KEY'
521-
}, usesTestEndpoint = true);
516+
});
522517

523518
query = {
524519
"car-year": {
@@ -586,7 +581,7 @@ let SlicingDice = require('slicerjs');
586581
const client = new SlicingDice({
587582
masterKey: 'MASTER_KEY',
588583
readKey: 'READ_KEY'
589-
}, usesTestEndpoint = true);
584+
});
590585

591586
query = {
592587
"query": [
@@ -647,7 +642,7 @@ let SlicingDice = require('slicerjs');
647642

648643
const client = new SlicingDice({
649644
masterKey: 'MASTER_KEY'
650-
}, usesTestEndpoint = true);
645+
});
651646

652647
client.getSavedQueries().then((resp) => {
653648
console.log(resp);
@@ -706,7 +701,7 @@ let SlicingDice = require('slicerjs');
706701

707702
const client = new SlicingDice({
708703
masterKey: 'MASTER_KEY'
709-
}, usesTestEndpoint = true);
704+
});
710705

711706
query = {
712707
"name": "my-saved-query",
@@ -769,7 +764,7 @@ let SlicingDice = require('slicerjs');
769764

770765
const client = new SlicingDice({
771766
masterKey: 'MASTER_KEY'
772-
}, usesTestEndpoint = true);
767+
});
773768

774769
newQuery = {
775770
"type": "count/entity",
@@ -831,7 +826,7 @@ let SlicingDice = require('slicerjs');
831826
const client = new SlicingDice({
832827
masterKey: 'MASTER_KEY',
833828
readKey: 'READ_KEY'
834-
}, usesTestEndpoint = true);
829+
});
835830

836831
client.getSavedQuery("my-saved-query").then((resp) => {
837832
console.log(resp);
@@ -876,7 +871,7 @@ let SlicingDice = require('slicerjs');
876871

877872
const client = new SlicingDice({
878873
masterKey: 'MASTER_KEY'
879-
}, usesTestEndpoint = true);
874+
});
880875

881876
client.deleteSavedQuery("my-saved-query").then((resp) => {
882877
console.log(resp);
@@ -921,7 +916,7 @@ let SlicingDice = require('slicerjs');
921916
const client = new SlicingDice({
922917
masterKey: 'MASTER_KEY',
923918
readKey: 'READ_KEY'
924-
}, usesTestEndpoint = true);
919+
});
925920

926921
query = {
927922
"query": [
@@ -980,7 +975,7 @@ let SlicingDice = require('slicerjs');
980975
const client = new SlicingDice({
981976
masterKey: 'MASTER_KEY',
982977
readKey: 'READ_KEY'
983-
}, usesTestEndpoint = true);
978+
});
984979

985980
query = {
986981
"query": [
@@ -1030,6 +1025,41 @@ client.score(query).then((resp) => {
10301025
}
10311026
```
10321027

1028+
### `sql(query)`
1029+
Retrieve inserted values using a SQL syntax. This method corresponds to a POST request at /query/sql.
1030+
1031+
#### Request example
1032+
1033+
```javascript
1034+
let SlicingDice = require('slicerjs');
1035+
1036+
const client = new SlicingDice({
1037+
masterKey: 'MASTER_KEY',
1038+
readKey: 'READ_KEY'
1039+
});
1040+
1041+
query = "SELECT COUNT(*) FROM default WHERE age BETWEEN 0 AND 49";
1042+
1043+
client.sql(query).then((resp) => {
1044+
console.log(resp);
1045+
}, (err) => {
1046+
console.error(err);
1047+
});
1048+
```
1049+
1050+
#### Output example
1051+
1052+
```json
1053+
{
1054+
"took":0.063,
1055+
"result":[
1056+
{"COUNT": 3}
1057+
],
1058+
"count":1,
1059+
"status":"success"
1060+
}
1061+
```
1062+
10331063
## License
10341064

10351065
[MIT](https://opensource.org/licenses/MIT)

src/slicer.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -569,11 +569,11 @@
569569

570570
/* Makes a total query on Slicing Dice API
571571
*
572-
* @param (array) tables - the tables in which the total query will be performed
572+
* @param (array) dimensions - the dimensions in which the total query will be performed
573573
*/
574-
countEntityTotal(tables = []) {
574+
countEntityTotal(dimensions = []) {
575575
let query = {
576-
"tables": tables
576+
"dimensions": dimensions
577577
};
578578
let path = this._sdRoutes.countEntityTotal;
579579
return this.makeRequest({
@@ -596,9 +596,9 @@
596596
/* Makes a exists query on Slicing Dice API
597597
*
598598
* @param (array) ids - the array of IDs to check
599-
* @param (string) table - the table to check for IDs
599+
* @param (string) dimension - the dimension to check for IDs
600600
*/
601-
existsEntity(ids, table = null) {
601+
existsEntity(ids, dimension = null) {
602602
if (ids.constructor != Array) {
603603
throw new errors.WrongTypeError("This method should receive an array as parameter");
604604
}
@@ -609,8 +609,8 @@
609609
let query = {
610610
"ids": ids
611611
}
612-
if (table) {
613-
query["table"] = table
612+
if (dimension) {
613+
query["dimension"] = dimension
614614
}
615615
return this.makeRequest({
616616
path: path,

tests_and_examples/examples/count_entity.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -23283,7 +23283,7 @@
2328323283
"name": "Test for a \"COUNT ENTITY\" query using automatically created columns, operator \"AND\" and parameter \"EQUALS\".",
2328423284
"columns": [],
2328523285
"insert": {
23286-
"auto-create": ["table", "column"],
23286+
"auto-create": ["dimension", "column"],
2328723287
"24": {
2328823288
"string-test-column": "value:matched_value",
2328923289
"numeric-test-column": 1000001
@@ -23713,7 +23713,7 @@
2371323713
"name": "Test for a \"COUNT ENTITY\" query using automatically created columns, operators \"AND\" and \"OR\" and parameter \"EQUALS\".",
2371423714
"columns": [],
2371523715
"insert": {
23716-
"auto-create": ["table", "column"],
23716+
"auto-create": ["dimension", "column"],
2371723717
"24": {
2371823718
"string-test-column": "value:matched_value",
2371923719
"boolean-test-column": "true",
@@ -24251,7 +24251,7 @@
2425124251
"name": "Test for a \"COUNT ENTITY\" query using automatically created columns, operators \"AND\" and \"OR\" and parameters \"EQUALS\", \"BETWEEN\" and \"MINFREQ\".",
2425224252
"columns": [],
2425324253
"insert": {
24254-
"auto-create": ["table", "column"],
24254+
"auto-create": ["dimension", "column"],
2425524255
"24": {
2425624256
"string-test-column": "value:matched_value",
2425724257
"boolean-test-column": "true",

0 commit comments

Comments
 (0)