From c4058859aeafce89aec5053f65aa5cb542acaf1a Mon Sep 17 00:00:00 2001 From: Ryland Goldstein Date: Tue, 19 Mar 2019 09:09:53 -0700 Subject: [PATCH 1/4] add TypeScript function example --- README.md | 1 + typescript-function/README.md | 34 ++++++++++++++++++ typescript-function/binaris.yml | 6 ++++ typescript-function/package.json | 28 +++++++++++++++ typescript-function/src/binaris.d.ts | 31 ++++++++++++++++ typescript-function/src/function.ts | 13 +++++++ typescript-function/tsconfig.json | 26 ++++++++++++++ typescript-function/tslint.yml | 54 ++++++++++++++++++++++++++++ 8 files changed, 193 insertions(+) create mode 100644 typescript-function/README.md create mode 100644 typescript-function/binaris.yml create mode 100755 typescript-function/package.json create mode 100644 typescript-function/src/binaris.d.ts create mode 100644 typescript-function/src/function.ts create mode 100755 typescript-function/tsconfig.json create mode 100644 typescript-function/tslint.yml diff --git a/README.md b/README.md index 0d1a978..eb27f53 100644 --- a/README.md +++ b/README.md @@ -26,3 +26,4 @@ Each example contains a README.md with an explanation about the solution and it' | [`python-crud-google-spreadsheet`](python-crud-google-spreadsheet)
Google Spreadsheet CRUD with functions | python3 | | [`kmeans-sklearn`](kmeans-sklearn)
Simple kmeans examples using sklearn | python2 | | [`naive-serverless-map-reduce`](naive-serverless-map-reduce)
Naive serverless MapReduce | nodeJS | +| [`typescript-function`](typescript-function)
Boilerplate TypeScript Binaris function | nodeJS and TypeScript | diff --git a/typescript-function/README.md b/typescript-function/README.md new file mode 100644 index 0000000..57b8e96 --- /dev/null +++ b/typescript-function/README.md @@ -0,0 +1,34 @@ +# TypeScript function (NodeJS and TypeScript) + +Boilerplate setup for a Binaris function written in TypeScript + +It is assumed you already have a Binaris account. If you don't have an account yet, worry not, signing up is painless and takes just 2 minutes. Visit [Getting Started](https://dev.binaris.com/tutorials/nodejs/getting-started/) to find concise instructions for the process. + +## Using the function + +1. Install dev-dependencies needed to compile TypeScript. + + ```bash + $ npm install + ``` + +1. Compile the TypeScript function for Binaris deployment. + + ```bash + $ npm run build + ``` + +1. Deploy the function. + + ```bash + $ bn deploy typescript + ``` + +1. Invoke. + + ```bash + $ bn invoke typescript + "Hello World!" + ``` + +> Note: The "npm run deploy" script is a convenience target that compiles and deploys your TypeScript function \ No newline at end of file diff --git a/typescript-function/binaris.yml b/typescript-function/binaris.yml new file mode 100644 index 0000000..2880398 --- /dev/null +++ b/typescript-function/binaris.yml @@ -0,0 +1,6 @@ +functions: + typescript: + file: dist/function.js + entrypoint: handler + executionModel: concurrent + runtime: node8 diff --git a/typescript-function/package.json b/typescript-function/package.json new file mode 100755 index 0000000..2c27313 --- /dev/null +++ b/typescript-function/package.json @@ -0,0 +1,28 @@ +{ + "name": "typescript-function", + "version": "1.0.0", + "private": true, + "license": "MIT", + "description": "A demo showing a common TypeScript setup on Binaris", + "main": "dist/index.js", + "repository": { + "type": "git", + "url": "git+https://github.com/binaris/functions-examples.git" + }, + "scripts": { + "deploy": "npm run build && bn deploy typescript", + "build": "tsc --p tsconfig.json", + "lint": "tslint -p tsconfig.json -c tslint.yml" + }, + "bugs": { + "url": "https://github.com/binaris/functions-examples/issues" + }, + "homepage": "https://github.com/binaris/functions-examples/typescript-function/README.md", + "author": "Ryland Goldstein", + "dependencies": {}, + "devDependencies": { + "@types/node": "^11.11.3", + "tslint": "^5.14.0", + "typescript": "^3.3.3333" + } +} diff --git a/typescript-function/src/binaris.d.ts b/typescript-function/src/binaris.d.ts new file mode 100644 index 0000000..1297026 --- /dev/null +++ b/typescript-function/src/binaris.d.ts @@ -0,0 +1,31 @@ +/// +interface BinarisHTTPRequest { + env: Record; + query: Record; + body: Buffer; + path: string; + method: string; + requestId: string; + headers: Record; +} + +interface FunctionResponse { + statusCode: number; + headers: Record; + body: Buffer | string; +} + +declare class BinarisHTTPResponse implements FunctionResponse { + userResponse: Partial; + constructor(userResponse: Partial); + statusCode: number; + headers: Record; + body: Buffer | string; +} + +declare type FunctionContext = { + request: BinarisHTTPRequest; + HTTPResponse: typeof BinarisHTTPResponse; +}; + +export declare type BinarisFunction = (body: unknown, context: FunctionContext) => Promise diff --git a/typescript-function/src/function.ts b/typescript-function/src/function.ts new file mode 100644 index 0000000..91b209c --- /dev/null +++ b/typescript-function/src/function.ts @@ -0,0 +1,13 @@ +import { FunctionContext } from './binaris'; + +interface DataWithName { name: string; } + +export async function handler(body: unknown, ctx: FunctionContext): Promise { + let name: string = 'World'; + if (typeof(ctx.request.query.name) === 'string') { + name = ctx.request.query.name; + } else if ((body !== undefined) && Object.prototype.hasOwnProperty.call(body, 'name')) { + name = (body as DataWithName).name; + } + return `Hello ${name}!`; +} diff --git a/typescript-function/tsconfig.json b/typescript-function/tsconfig.json new file mode 100755 index 0000000..e8b4e50 --- /dev/null +++ b/typescript-function/tsconfig.json @@ -0,0 +1,26 @@ +{ + "version": "2.4.2", + "compilerOptions": { + "lib": [ + "es2017", + "esnext.asynciterable" + ], + "target": "es2017", + "module": "commonjs", + "moduleResolution": "node", + "emitDecoratorMetadata": true, + "experimentalDecorators": true, + "declaration": true, + "sourceMap": true, + "strict": true, + "noImplicitAny": false, + "noUnusedLocals": true, + "outDir": "./dist" + }, + "include": [ + "./src/**/*.ts" + ], + "exclude": [ + "node_modules" + ] +} diff --git a/typescript-function/tslint.yml b/typescript-function/tslint.yml new file mode 100644 index 0000000..829fe5a --- /dev/null +++ b/typescript-function/tslint.yml @@ -0,0 +1,54 @@ +defaultSeverity: error +extends: + - 'tslint:recommended' +jsRules: +rules: + quotemark: + - true + - single + - avoid-escape + - avoid-template + curly: + - true + - ignore-same-line + max-classes-per-file: false + no-implicit-dependencies: + - true + - dev + variable-name: + - true + - ban-keywords + - check-format + - allow-leading-underscore + interface-name: false + member-ordering: false + object-literal-sort-keys: false + ordered-imports: false + object-literal-key-quotes: [true, "as-needed"] + trailing-comma: + - true + - multiline: + objects: always + arrays: always + typeLiterals: always + singleline: + functions: never + esSpecCompliant: true + whitespace: + - true + - check-branch + - check-decl + - check-operator + - check-module + - check-separator + - check-rest-spread + - check-type + - check-typecast + - check-type-operator + - check-preblock + +rulesDirectory: [] +linterOptions: + exclude: + - '**/node_modules/**.ts' + - '**/*.js' From 7ce465673ca2c7baa9bfac17fcb7ba5a36495bd5 Mon Sep 17 00:00:00 2001 From: Ryland Goldstein Date: Tue, 19 Mar 2019 12:32:16 -0700 Subject: [PATCH 2/4] update based on feedback --- typescript-function/src/function.ts | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/typescript-function/src/function.ts b/typescript-function/src/function.ts index 91b209c..ce702b2 100644 --- a/typescript-function/src/function.ts +++ b/typescript-function/src/function.ts @@ -1,13 +1,18 @@ -import { FunctionContext } from './binaris'; +import { BinarisFunction } from './binaris'; interface DataWithName { name: string; } -export async function handler(body: unknown, ctx: FunctionContext): Promise { - let name: string = 'World'; +function bodyHasName(body: unknown): body is DataWithName { + return body && typeof (body as DataWithName).name === 'string'; +} + +export const handler: BinarisFunction = async (body, ctx): Promise => { + let name: string | undefined; if (typeof(ctx.request.query.name) === 'string') { name = ctx.request.query.name; - } else if ((body !== undefined) && Object.prototype.hasOwnProperty.call(body, 'name')) { - name = (body as DataWithName).name; + } else if (bodyHasName(body)) { + name = name || body.name; } + name = name || 'World'; return `Hello ${name}!`; -} +}; From f9b447a44193a03c501bf0562ee3df171e3ddd05 Mon Sep 17 00:00:00 2001 From: Ryland Goldstein Date: Thu, 21 Mar 2019 12:20:37 -0700 Subject: [PATCH 3/4] use default tsconfig.json (with few changes) --- typescript-function/tsconfig.json | 79 ++++++++++++++++++++++--------- 1 file changed, 57 insertions(+), 22 deletions(-) mode change 100755 => 100644 typescript-function/tsconfig.json diff --git a/typescript-function/tsconfig.json b/typescript-function/tsconfig.json old mode 100755 new mode 100644 index e8b4e50..5cd9659 --- a/typescript-function/tsconfig.json +++ b/typescript-function/tsconfig.json @@ -1,26 +1,61 @@ { - "version": "2.4.2", "compilerOptions": { - "lib": [ - "es2017", - "esnext.asynciterable" - ], - "target": "es2017", - "module": "commonjs", - "moduleResolution": "node", - "emitDecoratorMetadata": true, - "experimentalDecorators": true, - "declaration": true, - "sourceMap": true, - "strict": true, - "noImplicitAny": false, - "noUnusedLocals": true, - "outDir": "./dist" + /* Basic Options */ + "module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */ + "outDir": "./dist", + // "allowJs": true, /* Allow javascript files to be compiled. */ + // "checkJs": true, /* Report errors in .js files. */ + // "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */ + // "declaration": true, /* Generates corresponding '.d.ts' file. */ + // "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */ + // "sourceMap": true, /* Generates corresponding '.map' file. */ + // "outFile": "./", /* Concatenate and emit output to single file. */ + // "outDir": "./", /* Redirect output structure to the directory. */ + // "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */ + // "composite": true, /* Enable project compilation */ + // "removeComments": true, /* Do not emit comments to output. */ + // "noEmit": true, /* Do not emit outputs. */ + // "importHelpers": true, /* Import emit helpers from 'tslib'. */ + // "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */ + // "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */ + + /* Strict Type-Checking Options */ + "strict": true, /* Enable all strict type-checking options. */ + // "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */ + // "strictNullChecks": true, /* Enable strict null checks. */ + // "strictFunctionTypes": true, /* Enable strict checking of function types. */ + // "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */ + // "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */ + // "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */ + // "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */ + + /* Additional Checks */ + // "noUnusedLocals": true, /* Report errors on unused locals. */ + // "noUnusedParameters": true, /* Report errors on unused parameters. */ + // "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */ + // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */ + + /* Module Resolution Options */ + // "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */ + // "baseUrl": "./", /* Base directory to resolve non-absolute module names. */ + // "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */ + // "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */ + // "typeRoots": [], /* List of folders to include type definitions from. */ + // "types": [], /* Type declaration files to be included in compilation. */ + // "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */ + "esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */ + // "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */ + + /* Source Map Options */ + // "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */ + // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */ + // "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */ + // "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */ + + /* Experimental Options */ + // "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */ + // "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */ }, - "include": [ - "./src/**/*.ts" - ], - "exclude": [ - "node_modules" - ] + "exclude": [ "node_modules" ], + "include": [ "./src/**/*.ts" ] } From 863356589e97e17bf41a209ca1fc3140d3217e6b Mon Sep 17 00:00:00 2001 From: Ryland Goldstein Date: Thu, 28 Mar 2019 11:49:00 -0700 Subject: [PATCH 4/4] add nodejs dynamo crud --- README.md | 2 +- nodejs-crud-dynamo/README.md | 84 ++++++++++++++++ nodejs-crud-dynamo/binaris.yml | 46 +++++++++ nodejs-crud-dynamo/deploy.sh | 6 ++ nodejs-crud-dynamo/function.js | 100 +++++++++++++++++++ nodejs-crud-dynamo/package.json | 34 +++++++ nodejs-crud-dynamo/queries/createDriver.json | 8 ++ nodejs-crud-dynamo/queries/deleteDriver.json | 3 + nodejs-crud-dynamo/queries/readDriver.json | 3 + nodejs-crud-dynamo/queries/updateDriver.json | 8 ++ nodejs-crud-dynamo/remove.sh | 6 ++ 11 files changed, 299 insertions(+), 1 deletion(-) create mode 100644 nodejs-crud-dynamo/README.md create mode 100644 nodejs-crud-dynamo/binaris.yml create mode 100755 nodejs-crud-dynamo/deploy.sh create mode 100644 nodejs-crud-dynamo/function.js create mode 100644 nodejs-crud-dynamo/package.json create mode 100644 nodejs-crud-dynamo/queries/createDriver.json create mode 100644 nodejs-crud-dynamo/queries/deleteDriver.json create mode 100644 nodejs-crud-dynamo/queries/readDriver.json create mode 100644 nodejs-crud-dynamo/queries/updateDriver.json create mode 100755 nodejs-crud-dynamo/remove.sh diff --git a/README.md b/README.md index eb27f53..b00526e 100644 --- a/README.md +++ b/README.md @@ -26,4 +26,4 @@ Each example contains a README.md with an explanation about the solution and it' | [`python-crud-google-spreadsheet`](python-crud-google-spreadsheet)
Google Spreadsheet CRUD with functions | python3 | | [`kmeans-sklearn`](kmeans-sklearn)
Simple kmeans examples using sklearn | python2 | | [`naive-serverless-map-reduce`](naive-serverless-map-reduce)
Naive serverless MapReduce | nodeJS | -| [`typescript-function`](typescript-function)
Boilerplate TypeScript Binaris function | nodeJS and TypeScript | +| [`nodejs-crud-dynamo`](nodejs-crud-dynamo)
Basic CRUD example using DynamoDB | nodeJS | diff --git a/nodejs-crud-dynamo/README.md b/nodejs-crud-dynamo/README.md new file mode 100644 index 0000000..0db2b9f --- /dev/null +++ b/nodejs-crud-dynamo/README.md @@ -0,0 +1,84 @@ +# NodeJS DynamoDB CRUD + +Wraps basic CRUD operations for DynamoDB in Binaris functions. + +# Using the CRUD + +It is assumed you already have a Binaris account. If you don't have an account yet, worry not, signing up is painless and takes just 2 minutes. Visit [Getting Started](https://dev.binaris.com/tutorials/nodejs/getting-started/) to find concise instructions for the process. + +To use any of the functions in this example, you must export the following three variables into your environment (before deployment). + +* `AWS_ACCESS_KEY_ID` # AWS access key +* `AWS_SECRET_ACCESS_KEY` # secret AWS credential +* `AWS_REGION` # AWS region used for DynamoDB + +## Deploy + +A helper command "deploy" is defined in the package.json to simplify the deployment process + +```bash +$ npm run deploy +``` + +## Create the Table + +```bash +$ bn invoke createDriversTable +``` + +## Create a Driver + +```bash +$ npm run createDriver +``` + +or + +```bash +$ bn invoke createDriver --json ./queries/createDriver.json +``` + +## Read a Driver + +```bash +$ npm run readDriver +``` + +or + +```bash +$ bn invoke readDriver --json ./queries/readDriver.json +``` + +## Update a Driver + +```bash +$ npm run updateDriver +``` + +or + +```bash +$ bn invoke updateDriver --json ./queries/updateDriver.json +``` + +## Delete a Driver + +```bash +$ npm run deleteDriver +``` + +or + +```bash +$ bn invoke deleteDriver --json ./queries/deleteDriver.json +``` + + +## Remove + +A helper command "remove" is defined in the package.json to simplify the removal process + +```bash +$ npm run remove +``` \ No newline at end of file diff --git a/nodejs-crud-dynamo/binaris.yml b/nodejs-crud-dynamo/binaris.yml new file mode 100644 index 0000000..8591f74 --- /dev/null +++ b/nodejs-crud-dynamo/binaris.yml @@ -0,0 +1,46 @@ +functions: + createDriversTable: + file: function.js + entrypoint: createDriversTable + executionModel: concurrent + runtime: node8 + env: + AWS_ACCESS_KEY_ID: + AWS_SECRET_ACCESS_KEY: + AWS_REGION: + createDriver: + file: function.js + entrypoint: createDriver + executionModel: concurrent + runtime: node8 + env: + AWS_ACCESS_KEY_ID: + AWS_SECRET_ACCESS_KEY: + AWS_REGION: + readDriver: + file: function.js + entrypoint: readDriver + executionModel: concurrent + runtime: node8 + env: + AWS_ACCESS_KEY_ID: + AWS_SECRET_ACCESS_KEY: + AWS_REGION: + updateDriver: + file: function.js + entrypoint: updateDriver + executionModel: concurrent + runtime: node8 + env: + AWS_ACCESS_KEY_ID: + AWS_SECRET_ACCESS_KEY: + AWS_REGION: + deleteDriver: + file: function.js + entrypoint: deleteDriver + executionModel: concurrent + runtime: node8 + env: + AWS_ACCESS_KEY_ID: + AWS_SECRET_ACCESS_KEY: + AWS_REGION: diff --git a/nodejs-crud-dynamo/deploy.sh b/nodejs-crud-dynamo/deploy.sh new file mode 100755 index 0000000..6da9bd2 --- /dev/null +++ b/nodejs-crud-dynamo/deploy.sh @@ -0,0 +1,6 @@ +#!/bin/bash +functions=( createDriversTable createDriver readDriver updateDriver deleteDriver ) +for i in "${functions[@]}" +do + bn deploy $i +done diff --git a/nodejs-crud-dynamo/function.js b/nodejs-crud-dynamo/function.js new file mode 100644 index 0000000..015fdf4 --- /dev/null +++ b/nodejs-crud-dynamo/function.js @@ -0,0 +1,100 @@ +const AWS = require('aws-sdk'); + +const { + AWS_ACCESS_KEY_ID, + AWS_SECRET_ACCESS_KEY, + AWS_REGION +} = process.env; + +AWS.config.update({ + accessKeyId: AWS_ACCESS_KEY_ID, + secretAccessKey: AWS_SECRET_ACCESS_KEY, + region: AWS_REGION, + endpoint: `https://dynamodb.${AWS_REGION}.amazonaws.com`, +}); + +const dynamoDB = new AWS.DynamoDB(); +const docClient = new AWS.DynamoDB.DocumentClient(); + +function validatedBody(body, ...fields) { + for (const field of fields) { + if (!Object.prototype.hasOwnProperty.call(body, field)) { + throw new Error(`Missing request body parameter: ${field}.`); + } + } + return body; +} + +const TableName = 'Drivers'; +const PrimaryKey = 'driverID'; + +exports.createDriversTable = async () => { + return dynamoDB.createTable({ + TableName, + KeySchema: [{ + AttributeName: PrimaryKey, + KeyType: 'HASH', + }], + AttributeDefinitions: [{ + AttributeName: PrimaryKey, + AttributeType: 'S', + }], + ProvisionedThroughput: { + ReadCapacityUnits: 10, + WriteCapacityUnits: 10, + } + }).promise(); +}; + +exports.createDriver = async (body) => { + const { + driverID, + rideStatus, + lastLocation + } = validatedBody(body, 'driverID', 'rideStatus', 'lastLocation'); + + return docClient.put({ + TableName, + Item: { + driverID, + rideStatus, + lastLocation, + } + }).promise(); +}; + +exports.readDriver = async (body) => { + const { driverID } = validatedBody(body, 'driverID'); + return docClient.get({ TableName, Key: { driverID } }).promise(); +}; + +exports.updateDriver = async (body) => { + const { + driverID, + rideStatus, + lastLocation + } = validatedBody(body, 'driverID', 'rideStatus', 'lastLocation'); + + return docClient.update({ + TableName, + Key: { driverID }, + UpdateExpression: 'SET #loc.#lon = :lonVal, #loc.#lat = :latVal, #rideStatus= :r', + ExpressionAttributeNames: { + '#loc': 'lastLocation', + '#lon': 'longitude', + '#lat': 'latitude', + '#rideStatus': 'rideStatus', + }, + ExpressionAttributeValues: { + ':r': rideStatus, + ':lonVal': lastLocation.longitude, + ':latVal': lastLocation.latitude, + }, + ReturnValues: 'UPDATED_NEW' + }).promise(); +}; + +exports.deleteDriver = async (body) => { + const { driverID } = validatedBody(body, 'driverID'); + return docClient.delete({ TableName, Key: { driverID } }).promise(); +}; diff --git a/nodejs-crud-dynamo/package.json b/nodejs-crud-dynamo/package.json new file mode 100644 index 0000000..93301b4 --- /dev/null +++ b/nodejs-crud-dynamo/package.json @@ -0,0 +1,34 @@ +{ + "name": "nodejs-crud-dynamo", + "version": "1.0.0", + "private": true, + "license": "MIT", + "description": "An example CRUD around DynamoDB", + "main": "function.js", + "repository": { + "type": "git", + "url": "git+https://github.com/binaris/functions-examples.git" + }, + "scripts": { + "deploy": "./deploy", + "remove": "./remove", + "createDriver": "bn invoke createDriver --json ./queries/createDriver.json", + "readDriver": "bn invoke readDriver --json ./queries/readDriver.json", + "updateDriver": "bn invoke updateDriver --json ./queries/updateDriver.json", + "deleteDriver": "bn invoke deleteDriver --json ./queries/deleteDriver.json" + }, + "bugs": { + "url": "https://github.com/binaris/functions-examples/issues" + }, + "homepage": "https://github.com/binaris/functions-examples/nodejs-crud-dynamo/README.md", + "author": "Ryland Goldstein", + "dependencies": { + "aws-sdk": "^2.430.0" + }, + "keywords": [ + "Binaris", + "FaaS", + "CRUD", + "DynamoDB" + ] +} diff --git a/nodejs-crud-dynamo/queries/createDriver.json b/nodejs-crud-dynamo/queries/createDriver.json new file mode 100644 index 0000000..6118cd5 --- /dev/null +++ b/nodejs-crud-dynamo/queries/createDriver.json @@ -0,0 +1,8 @@ +{ + "driverID": "a21s312qew313hdg", + "rideStatus": "HAS_RIDER", + "lastLocation": { + "longitude": "-77.0364", + "latitude": "38.8951" + } +} diff --git a/nodejs-crud-dynamo/queries/deleteDriver.json b/nodejs-crud-dynamo/queries/deleteDriver.json new file mode 100644 index 0000000..79f2816 --- /dev/null +++ b/nodejs-crud-dynamo/queries/deleteDriver.json @@ -0,0 +1,3 @@ +{ + "driverID": "a21s312qew313hdg" +} diff --git a/nodejs-crud-dynamo/queries/readDriver.json b/nodejs-crud-dynamo/queries/readDriver.json new file mode 100644 index 0000000..79f2816 --- /dev/null +++ b/nodejs-crud-dynamo/queries/readDriver.json @@ -0,0 +1,3 @@ +{ + "driverID": "a21s312qew313hdg" +} diff --git a/nodejs-crud-dynamo/queries/updateDriver.json b/nodejs-crud-dynamo/queries/updateDriver.json new file mode 100644 index 0000000..2f2459d --- /dev/null +++ b/nodejs-crud-dynamo/queries/updateDriver.json @@ -0,0 +1,8 @@ +{ + "driverID": "a21s312qew313hdg", + "rideStatus": "NO_RIDER", + "lastLocation": { + "longitude": "-78.0364", + "latitude": "38.8851" + } +} diff --git a/nodejs-crud-dynamo/remove.sh b/nodejs-crud-dynamo/remove.sh new file mode 100755 index 0000000..cb5f89c --- /dev/null +++ b/nodejs-crud-dynamo/remove.sh @@ -0,0 +1,6 @@ +#!/bin/bash +functions=( createDriversTable createDriver readDriver updateDriver deleteDriver ) +for i in "${functions[@]}" +do + bn remove $i +done