From 203609e4f74150897e0fe98128c838ca994570e8 Mon Sep 17 00:00:00 2001 From: Rajendra Kadam Date: Fri, 23 Mar 2018 18:21:59 +0530 Subject: [PATCH 1/5] Add SimpleDB Support to core --- lib/core/aws/provider.js | 11 +++ lib/database/aws-simple-db.js | 137 ++++++++++++++++++++++++++++++++++ 2 files changed, 148 insertions(+) create mode 100644 lib/database/aws-simple-db.js diff --git a/lib/core/aws/provider.js b/lib/core/aws/provider.js index 66a8e56..ecd62b6 100644 --- a/lib/core/aws/provider.js +++ b/lib/core/aws/provider.js @@ -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('../../aws-simple-db'); class AWS { /** @@ -42,6 +43,8 @@ class AWS { rdbms: this.RDS, nosql: this.DynamoDB, iam: this.IAM, + indexedDB: this.SimpleDB, + }; } /** @@ -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; diff --git a/lib/database/aws-simple-db.js b/lib/database/aws-simple-db.js new file mode 100644 index 0000000..b8ca1fe --- /dev/null +++ b/lib/database/aws-simple-db.js @@ -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; \ No newline at end of file From 0883a2697454b9b449973e53ca6527203af95a68 Mon Sep 17 00:00:00 2001 From: Rajendra Kadam Date: Fri, 23 Mar 2018 18:28:09 +0530 Subject: [PATCH 2/5] Fix inconsistent tabs and spaces --- lib/database/aws-simple-db.js | 50 +++++++++++++++++------------------ 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/lib/database/aws-simple-db.js b/lib/database/aws-simple-db.js index b8ca1fe..f095e3e 100644 --- a/lib/database/aws-simple-db.js +++ b/lib/database/aws-simple-db.js @@ -7,7 +7,7 @@ class SimpleDB { * SimpleDB constructor * @constructor * @param {object} aws - AWS SDK - * @param {object} options - { apiVersion } + * @param {object} options - { apiVersion } */ constructor(aws, options) { this._AWS = aws; @@ -20,10 +20,10 @@ class SimpleDB { } /** - * Create Domain - * @createDomain - * @param {object} params - */ + * Create Domain + * @createDomain + * @param {object} params + */ createDomain(params) { checkParams(params); @@ -39,10 +39,10 @@ class SimpleDB { } /** - * Delete item - * @deleteDomain - * @param {object} params - */ + * Delete item + * @deleteDomain + * @param {object} params + */ deleteDomain(params) { checkParams(params); @@ -58,10 +58,10 @@ class SimpleDB { } /** - * Create item - * @createItem - * @param {object} params - */ + * Create item + * @createItem + * @param {object} params + */ createItem(params) { checkParams(params); @@ -77,10 +77,10 @@ class SimpleDB { } /** - * Update item - * @updateItem - * @param {object} params - */ + * Update item + * @updateItem + * @param {object} params + */ updateItem(params) { checkParams(params); @@ -96,10 +96,10 @@ class SimpleDB { } /** - * Delete item - * @deleteItem - * @param {object} params - */ + * Delete item + * @deleteItem + * @param {object} params + */ deleteItem(params) { checkParams(params); @@ -115,10 +115,10 @@ class SimpleDB { } /** - * Query - * @query - * @param {object} params - */ + * Query + * @query + * @param {object} params + */ query(params) { checkParams(params); From df91f74f45e6ba79f86a354455fd9391a3ff17a7 Mon Sep 17 00:00:00 2001 From: Rajendra Kadam Date: Sun, 25 Mar 2018 20:30:40 +0530 Subject: [PATCH 3/5] Fix #56 Add simpledb to core, docs and examples --- docs/database/aws-simpledb.md | 122 ++++++++++++++++++ examples/database/aws-simpledb.js | 20 +++ lib/core/aws/provider.js | 2 +- .../{aws-simple-db.js => aws-simpledb.js} | 0 4 files changed, 143 insertions(+), 1 deletion(-) create mode 100644 docs/database/aws-simpledb.md create mode 100644 examples/database/aws-simpledb.js rename lib/database/{aws-simple-db.js => aws-simpledb.js} (100%) diff --git a/docs/database/aws-simpledb.md b/docs/database/aws-simpledb.md new file mode 100644 index 0000000..04fe09c --- /dev/null +++ b/docs/database/aws-simpledb.md @@ -0,0 +1,122 @@ +# 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 +```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); + }); +``` diff --git a/examples/database/aws-simpledb.js b/examples/database/aws-simpledb.js new file mode 100644 index 0000000..38e5b91 --- /dev/null +++ b/examples/database/aws-simpledb.js @@ -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); + }); diff --git a/lib/core/aws/provider.js b/lib/core/aws/provider.js index ecd62b6..714a2dd 100644 --- a/lib/core/aws/provider.js +++ b/lib/core/aws/provider.js @@ -9,7 +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('../../aws-simple-db'); +const SimpleDB = require('../../database/aws-simpledb'); class AWS { /** diff --git a/lib/database/aws-simple-db.js b/lib/database/aws-simpledb.js similarity index 100% rename from lib/database/aws-simple-db.js rename to lib/database/aws-simpledb.js From 9085344930d76e9dde3890f946df40b53faf4be5 Mon Sep 17 00:00:00 2001 From: Rajendra Kadam Date: Sun, 25 Mar 2018 20:36:31 +0530 Subject: [PATCH 4/5] Update README for indexedDB support --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 111870d..3c1baa4 100644 --- a/README.md +++ b/README.md @@ -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 From 3ab4a2d8e6c90a713165e1c5b16b76ff152e5149 Mon Sep 17 00:00:00 2001 From: Rajendra Kadam Date: Mon, 26 Mar 2018 11:06:33 +0530 Subject: [PATCH 5/5] Add line breaks in docs md file for simpledb --- docs/database/aws-simpledb.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/database/aws-simpledb.md b/docs/database/aws-simpledb.md index 04fe09c..2f8768b 100644 --- a/docs/database/aws-simpledb.md +++ b/docs/database/aws-simpledb.md @@ -55,6 +55,7 @@ simpleDB.deleteDomain(params) ``` ### Create an Item + ```js const params = { Attributes: [ /* required */ @@ -84,6 +85,7 @@ simpleDB.createItem(params) ``` ### Delete an Item + ```js simpleDB.deleteItem(params) .then((res) => { @@ -95,6 +97,7 @@ simpleDB.deleteItem(params) ``` ### Update an Item + ```js simpleDB.updateItem(params) .then((res) => { @@ -106,6 +109,7 @@ simpleDB.updateItem(params) ``` ### Query an Item + ```js const params = { SelectExpression: 'STRING_VALUE', /* required */