Skip to content
This repository was archived by the owner on Nov 22, 2018. It is now read-only.
Open
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ yarn add nodecloud
| | DNS | Route53 | Google DNS |
| Databases | RDBMS | RDS | - |
| | NoSQL: key-value | DynamoDB | Cloud Datastore |
| | NoSQL: indexed | - | Cloud Datastore |
| | NoSQL: indexed | SimpleDB | Cloud Datastore |
| Security/ Authorization | IAM | AWS IAM | - |

## Usage
Expand Down
126 changes: 126 additions & 0 deletions docs/database/aws-simpledb.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
# NodeCloud database - AWS SimpleDB

## Configure AWS credentials

Create `config.json` as follows,

```js
{
"aws_access_key_id": "xxxxxxxxxxxx",
"aws_secret_access_key": "xxxxxxxxxxxx",
"region": "xxxxxxxxx" // eg : us-west-2
}
```

## Initialize library

```js
const nodeCloud = require("../../lib/");
const ncAWS = nodeCloud.getProvider(
"AWS",
process.env.ncconf // path to config.json
);
const options = {
apiVersion: '2016-11-15',
};
const simpleDB = ncAWS.indexedDB(options);
```

### Create a domain

```js
const params = {
DomainName: 'nodeCloudTestDomain' /* required */
};

simpleDB.createDomain(params)
.then((res) => {
console.log(res);
})
.catch((err) => {
console.error(err);
});
```

### Delete a domain

```js
simpleDB.deleteDomain(params)
.then((res) => {
console.log(res);
})
.catch((err) => {
console.error(err);
});
```

### Create an Item
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a line break


```js
const params = {
Attributes: [ /* required */
{
Name: 'STRING_VALUE', /* required */
Value: 'STRING_VALUE', /* required */
Replace: true || false
},
/* more items */
],
DomainName: 'STRING_VALUE', /* required */
ItemName: 'STRING_VALUE', /* required */
Expected: {
Exists: true || false,
Name: 'STRING_VALUE',
Value: 'STRING_VALUE'
}
};

simpleDB.createItem(params)
.then((res) => {
console.log(res);
})
.catch((err) => {
console.error(err);
});
```

### Delete an Item

```js
simpleDB.deleteItem(params)
.then((res) => {
console.log(res);
})
.catch((err) => {
console.error(err);
});
```

### Update an Item

```js
simpleDB.updateItem(params)
.then((res) => {
console.log(res);
})
.catch((err) => {
console.error(err);
});
```

### Query an Item

```js
const params = {
SelectExpression: 'STRING_VALUE', /* required */
ConsistentRead: true || false,
NextToken: 'STRING_VALUE'
};
simpleDB.query(params)
.then((res) => {
console.log(res);
})
.catch((err) => {
console.error(err);
});
```
20 changes: 20 additions & 0 deletions examples/database/aws-simpledb.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const nodeCloud = require('../../lib/');

const ncAWS = nodeCloud.getProvider('AWS', process.env.ncconf);
const options = {
apiVersion: '2016-11-15',
};

const simpleDB = ncAWS.indexedDB(options);

const params = {
DomainName: 'nodeCloudTestDomain' /* required */
};

simpleDB.createDomain(params)
.then((res) => {
console.log(res);
})
.catch((err) => {
console.error(err);
});
11 changes: 11 additions & 0 deletions lib/core/aws/provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const DirectConnect = require('../../network/aws-directconnect');
const RDS = require('../../database/aws-rds');
const DynamoDB = require('../../database/aws-dynamodb');
const IAM = require('../../security/aws-iam');
const SimpleDB = require('../../database/aws-simpledb');

class AWS {
/**
Expand Down Expand Up @@ -42,6 +43,8 @@ class AWS {
rdbms: this.RDS,
nosql: this.DynamoDB,
iam: this.IAM,
indexedDB: this.SimpleDB,

};
}
/**
Expand Down Expand Up @@ -158,6 +161,14 @@ class AWS {
}
return new IAM(this.getSDK());
}

SimpleDB(options) {
if (options.apiVersion) {
this._apiVersion = options.apiVersion;
return new SimpleDB(this.getSDK(), options);
}
return new SimpleDB(this.getSDK());
}
}

module.exports = AWS;
137 changes: 137 additions & 0 deletions lib/database/aws-simpledb.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
const helpers = require('../core/helpers');

const { checkParams } = helpers;
class SimpleDB {

/**
* SimpleDB constructor
* @constructor
* @param {object} aws - AWS SDK
* @param {object} options - { apiVersion }
*/
constructor(aws, options) {
this._AWS = aws;
if (options) {
this._apiVersion = options.apiVersion;
this._simpledb = new this._AWS.SimpleDB({ apiVersion: this._apiVersion });
} else {
this._simpledb = new this._AWS.SimpleDB();
}
}

/**
* Create Domain
* @createDomain
* @param {object} params
*/
createDomain(params) {
checkParams(params);

return new Promise((resolve, reject) => {
this._simpledb.createDomain(params, (err, data) => {
if (err) {
reject(err);
} else {
resolve(data);
}
});
});
}

/**
* Delete item
* @deleteDomain
* @param {object} params
*/
deleteDomain(params) {
checkParams(params);

return new Promise((resolve, reject) => {
this._simpledb.deleteDomain(params, (err, data) => {
if (err) {
reject(err);
} else {
resolve(data);
}
});
});
}

/**
* Create item
* @createItem
* @param {object} params
*/
createItem(params) {
checkParams(params);

return new Promise((resolve, reject) => {
this._simpledb.putAttributes(params, (err, data) => {
if (err) {
reject(err);
} else {
resolve(data);
}
});
});
}

/**
* Update item
* @updateItem
* @param {object} params
*/
updateItem(params) {
checkParams(params);

return new Promise((resolve, reject) => {
this._simpledb.putAttributes(params, (err, data) => {
if (err) {
reject(err);
} else {
resolve(data);
}
});
});
}

/**
* Delete item
* @deleteItem
* @param {object} params
*/
deleteItem(params) {
checkParams(params);

return new Promise((resolve, reject) => {
this._simpledb.deleteAttributes(params, (err, data) => {
if (err) {
reject(err);
} else {
resolve(data);
}
});
});
}

/**
* Query
* @query
* @param {object} params
*/
query(params) {
checkParams(params);

return new Promise((resolve, reject) => {
this._simpledb.getAttributes(params, (err, data) => {
if (err) {
reject(err);
} else {
resolve(data);
}
});
});
}
}

module.exports = SimpleDB;