This repository was archived by the owner on Nov 22, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 100
Add SimpleDB Support to core #57
Open
raju249
wants to merge
5
commits into
leopardslab:master
Choose a base branch
from
raju249:aws-simple-db
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
203609e
Add SimpleDB Support to core
0883a26
Fix inconsistent tabs and spaces
df91f74
Fix #56 Add simpledb to core, docs and examples
raju249 9085344
Update README for indexedDB support
raju249 3ab4a2d
Add line breaks in docs md file for simpledb
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
|
|
||
| ```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); | ||
| }); | ||
| ``` | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a line break