Skip to content
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

Initial commit with mssql changes #189

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
42 changes: 42 additions & 0 deletions electrode-ota-server-dao-azsql/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# electrode-ota-server-dao-azsql
An implementation of the Electrode OTA Server's data access layer using AzureSQL as a back-end.

## Usage
In your electrode ota server implementation, include this module as a dependency.

```
npm install --save electrode-ota-server-dao-azsql
```

Update your OTA server configuration to override the DAO plugin. *This is assuming your config is in JavaScript format (not JSON).*

```JavaScript
const conf = {
plugins : {
// ...

"electrode-ota-server-dao-plugin" : {
module : "electrode-ota-server-dao-azsql",
// connection options based on typeorm;
// 'type' and 'entities' are defaulted but may be overriden
options : {
clusterConfig : {
canRetry : true,
defaultSelector : "ORDER",
removeNodeErrorCount : 5,
restoreNodeTimeout : 0,
},
poolConfigs : [{
database: "ota_db",
host: "localhost",
password: "password",
port: 3306,
user: "user",
}],
}
},

// ...
}
}
```
73 changes: 73 additions & 0 deletions electrode-ota-server-dao-azsql/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
{
"name": "electrode-ota-server-dao-azsql",
"version": "4.8.4",
"description": "Electrode OTA - AzureSQL driver",
"author": "Charles Selvarajan <charles.selvarajan@walmart.com>",
"license": "Apache-2.0",
"repository": "https://github.com/electrode-io/electrode-ota-server",
"bugs": {
"url": "https://github.com/electrode-io/electrode-ota-server/issues"
},
"homepage": "https://github.com/electrode-io/electrode-ota-server",
"main": "lib/index",
"typings": "lib/index",
"scripts": {
"test": "nyc mocha --compilers ts-node/register --require source-map-support/register --full-trace --bail test/**/*-spec.ts --reporter spec --timeout 100000",
"lint": "tslint --project .; exit 0",
"build": "rimraf ./lib && tsc -v && tsc && echo 'build complete'",
"prepublishOnly": "npm run build"
},
"nyc": {
"check-coverage": true,
"all": true,
"lines": 0,
"include": [
"src/**/*.ts"
],
"extension": [
".ts"
],
"exclude": [
"src/dto"
],
"reporter": [
"text",
"html",
"lcov"
],
"report-dir": "coverage/js"
},
"keywords": [
"code-push",
"ota",
"electrode",
"react-native",
"cordova"
],
"devDependencies": {
"@types/chai": "^4.0.4",
"@types/lodash": "4.14.108",
"@types/mocha": "^2.2.42",
"@types/mssql": "7.1.2",
"@types/semver": "7.1.0",
"@types/sinon": "4.3.3",
"chai": "^4.1.1",
"mocha": "^3.5.0",
"nyc": "^11.1.0",
"rimraf": "^2.6.1",
"semver": "^5.6.0",
"sinon": "7.4.1",
"source-map-support": "^0.4.16",
"ts-node": "^3.3.0",
"tslint": "^5.6.0",
"typescript": "2.4.2"
},
"dependencies": {
"@types/node": "^8.0.24",
"bluebird": "^3.5.1",
"electrode-ota-server-diregister": "^4.8.4",
"electrode-ota-server-util": "^4.8.4",
"lodash": ">=4.17.11",
"mssql": "^7.1.3"
}
}
55 changes: 55 additions & 0 deletions electrode-ota-server-dao-azsql/src/AzClient.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// AzureSQL driver
import { config, ConnectionPool } from "mssql";

const AzClient = async (options: config) => {
let pool: any;

const closePool = async () => {
try {
// try to close the connection pool
await pool.close();

// set the pool to null to ensure
// a new one will be created by getConnection()
pool = null;
} catch () {
// error closing the connection (could already be closed)
// set the pool to null to ensure
// a new one will be created by getConnection()
pool = null;
// server.log( [ "error", "data" ], "closePool error" );
// server.log( [ "error", "data" ], err );
}
};

const getConnection = async () => {
try {
if (pool) {
// has the connection pool already been created?
// if so, return the existing pool
return pool;
}
// create a new connection pool
pool = new ConnectionPool(options);

// catch any connection errors and close the pool
pool.on("error", async(err: any) => {
// server.log( [ "error", "data" ], "connection pool error" );
// server.log( [ "error", "data" ], err );
await closePool();
} );
return pool;
} catch () {
// error connecting to SQL Server
// server.log( [ "error", "data" ], "error connecting to sql server" );
// server.log( [ "error", "data" ], err );
pool = null;
}
};

// this is the API the client exposes to the rest
// of the application
return { getConnection }
};

module.exports = AzClient;
Loading