Skip to content

Change table to dimension on code #20

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 63 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ const client = new SlicingDice({
masterKey: 'MASTER_API_KEY',
writeKey: 'WRITE_API_KEY',
readKey: 'READ_API_KEY'
}, usesTestEndpoint = true);
});

// Inserting data
const insertData = {
"user1@slicingdice.com": {
"age": 22
},
"auto-create": ["table", "column"]
"auto-create": ["dimension", "column"]
};
client.insert(insertData);

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

`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)

### Attributes

* `sdAddress (String)` - [Connection endpoint](https://docs.slicingdice.com/docs/api-keys) to use when generating requests to SlicingDice.

### Constructor

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

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

const client = new SlicingDice({
masterKey: 'MASTER_API_KEY'
}, usesTestEndpoint = false);
});

client.getDatabase().then((resp) => {
console.log(resp);
Expand All @@ -111,7 +106,7 @@ client.getDatabase().then((resp) => {
{
"name": "Database 1",
"description": "My first database",
"tables": [
"dimensions": [
"default",
"users"
],
Expand All @@ -130,7 +125,7 @@ let SlicingDice = require('slicerjs');

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

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

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

column = {
"name": "Year",
Expand Down Expand Up @@ -214,7 +209,7 @@ let SlicingDice = require('slicerjs');
const client = new SlicingDice({
masterKey: 'MASTER_API_KEY',
writeKey: 'WRITE_API_KEY'
}, usesTestEndpoint = true);
});

const insertData = {
"user1@slicingdice.com": {
Expand Down Expand Up @@ -269,8 +264,8 @@ client.insert(insertData).then((resp) => {
}
```

### `existsEntity(ids, table = null)`
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).
### `existsEntity(ids, dimension = null)`
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).

#### Request example

Expand All @@ -280,7 +275,7 @@ let SlicingDice = require('slicerjs');
const client = new SlicingDice({
masterKey: 'MASTER_KEY',
readKey: 'READ_KEY'
}, usesTestEndpoint = true);
});

ids = [
"user1@slicingdice.com",
Expand Down Expand Up @@ -322,7 +317,7 @@ let SlicingDice = require('slicerjs');
const client = new SlicingDice({
masterKey: 'MASTER_KEY',
readKey: 'READ_KEY'
}, usesTestEndpoint = true);
});

client.countEntityTotal().then((resp) => {
console.log(resp);
Expand All @@ -343,8 +338,8 @@ client.countEntityTotal().then((resp) => {
}
```

### `countEntityTotal(tables)`
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).
### `countEntityTotal(dimensions)`
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).

#### Request example

Expand All @@ -354,11 +349,11 @@ let SlicingDice = require('slicerjs');
const client = new SlicingDice({
masterKey: 'MASTER_KEY',
readKey: 'READ_KEY'
}, usesTestEndpoint = true);
});

const tables = ["default"];
const dimensions = ["default"];

client.countEntityTotal(tables).then((resp) => {
client.countEntityTotal(dimensions).then((resp) => {
console.log(resp);
}, (err) => {
console.error(err);
Expand Down Expand Up @@ -388,7 +383,7 @@ let SlicingDice = require('slicerjs');
const client = new SlicingDice({
masterKey: 'MASTER_KEY',
readKey: 'READ_KEY'
}, usesTestEndpoint = true);
});

const query = [
{
Expand Down Expand Up @@ -452,7 +447,7 @@ let SlicingDice = require('slicerjs');
const client = new SlicingDice({
masterKey: 'MASTER_KEY',
readKey: 'READ_KEY'
}, usesTestEndpoint = true);
});

const query = [
{
Expand Down Expand Up @@ -518,7 +513,7 @@ let SlicingDice = require('slicerjs');
const client = new SlicingDice({
masterKey: 'MASTER_KEY',
readKey: 'READ_KEY'
}, usesTestEndpoint = true);
});

query = {
"car-year": {
Expand Down Expand Up @@ -586,7 +581,7 @@ let SlicingDice = require('slicerjs');
const client = new SlicingDice({
masterKey: 'MASTER_KEY',
readKey: 'READ_KEY'
}, usesTestEndpoint = true);
});

query = {
"query": [
Expand Down Expand Up @@ -647,7 +642,7 @@ let SlicingDice = require('slicerjs');

const client = new SlicingDice({
masterKey: 'MASTER_KEY'
}, usesTestEndpoint = true);
});

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

const client = new SlicingDice({
masterKey: 'MASTER_KEY'
}, usesTestEndpoint = true);
});

query = {
"name": "my-saved-query",
Expand Down Expand Up @@ -769,7 +764,7 @@ let SlicingDice = require('slicerjs');

const client = new SlicingDice({
masterKey: 'MASTER_KEY'
}, usesTestEndpoint = true);
});

newQuery = {
"type": "count/entity",
Expand Down Expand Up @@ -831,7 +826,7 @@ let SlicingDice = require('slicerjs');
const client = new SlicingDice({
masterKey: 'MASTER_KEY',
readKey: 'READ_KEY'
}, usesTestEndpoint = true);
});

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

const client = new SlicingDice({
masterKey: 'MASTER_KEY'
}, usesTestEndpoint = true);
});

client.deleteSavedQuery("my-saved-query").then((resp) => {
console.log(resp);
Expand Down Expand Up @@ -921,7 +916,7 @@ let SlicingDice = require('slicerjs');
const client = new SlicingDice({
masterKey: 'MASTER_KEY',
readKey: 'READ_KEY'
}, usesTestEndpoint = true);
});

query = {
"query": [
Expand Down Expand Up @@ -980,7 +975,7 @@ let SlicingDice = require('slicerjs');
const client = new SlicingDice({
masterKey: 'MASTER_KEY',
readKey: 'READ_KEY'
}, usesTestEndpoint = true);
});

query = {
"query": [
Expand Down Expand Up @@ -1030,6 +1025,41 @@ client.score(query).then((resp) => {
}
```

### `sql(query)`
Retrieve inserted values using a SQL syntax. This method corresponds to a POST request at /query/sql.

#### Request example

```javascript
let SlicingDice = require('slicerjs');

const client = new SlicingDice({
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);
});
```

#### Output example

```json
{
"took":0.063,
"result":[
{"COUNT": 3}
],
"count":1,
"status":"success"
}
```

## License

[MIT](https://opensource.org/licenses/MIT)
14 changes: 7 additions & 7 deletions src/slicer.js
Original file line number Diff line number Diff line change
Expand Up @@ -569,11 +569,11 @@

/* Makes a total query on Slicing Dice API
*
* @param (array) tables - the tables in which the total query will be performed
* @param (array) dimensions - the dimensions in which the total query will be performed
*/
countEntityTotal(tables = []) {
countEntityTotal(dimensions = []) {
let query = {
"tables": tables
"dimensions": dimensions
};
let path = this._sdRoutes.countEntityTotal;
return this.makeRequest({
Expand All @@ -596,9 +596,9 @@
/* Makes a exists query on Slicing Dice API
*
* @param (array) ids - the array of IDs to check
* @param (string) table - the table to check for IDs
* @param (string) dimension - the dimension to check for IDs
*/
existsEntity(ids, table = null) {
existsEntity(ids, dimension = null) {
if (ids.constructor != Array) {
throw new errors.WrongTypeError("This method should receive an array as parameter");
}
Expand All @@ -609,8 +609,8 @@
let query = {
"ids": ids
}
if (table) {
query["table"] = table
if (dimension) {
query["dimension"] = dimension
}
return this.makeRequest({
path: path,
Expand Down
6 changes: 3 additions & 3 deletions tests_and_examples/examples/count_entity.json
Original file line number Diff line number Diff line change
Expand Up @@ -23283,7 +23283,7 @@
"name": "Test for a \"COUNT ENTITY\" query using automatically created columns, operator \"AND\" and parameter \"EQUALS\".",
"columns": [],
"insert": {
"auto-create": ["table", "column"],
"auto-create": ["dimension", "column"],
"24": {
"string-test-column": "value:matched_value",
"numeric-test-column": 1000001
Expand Down Expand Up @@ -23713,7 +23713,7 @@
"name": "Test for a \"COUNT ENTITY\" query using automatically created columns, operators \"AND\" and \"OR\" and parameter \"EQUALS\".",
"columns": [],
"insert": {
"auto-create": ["table", "column"],
"auto-create": ["dimension", "column"],
"24": {
"string-test-column": "value:matched_value",
"boolean-test-column": "true",
Expand Down Expand Up @@ -24251,7 +24251,7 @@
"name": "Test for a \"COUNT ENTITY\" query using automatically created columns, operators \"AND\" and \"OR\" and parameters \"EQUALS\", \"BETWEEN\" and \"MINFREQ\".",
"columns": [],
"insert": {
"auto-create": ["table", "column"],
"auto-create": ["dimension", "column"],
"24": {
"string-test-column": "value:matched_value",
"boolean-test-column": "true",
Expand Down
Loading