Skip to content

Commit

Permalink
auto-create table
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesward committed Aug 2, 2016
1 parent 3415954 commit 52ef269
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
7 changes: 0 additions & 7 deletions README.md
Expand Up @@ -5,18 +5,11 @@ This sample application shows a simple way to use a Node.js app along with Workf

### Run on Heroku
1. Deploy the app: [![Deploy](https://www.herokucdn.com/deploy/button.png)](https://heroku.com/deploy)
1. Setup the contact table:

create table contact (id VARCHAR(18) PRIMARY KEY, name VARCHAR(128), email VARCHAR(128));


### Run Locally

1. Create a local MySQL database named `demo`
1. Create a table:

create table contact (id VARCHAR(18) PRIMARY KEY, name VARCHAR(128), email VARCHAR(128));

1. Install the Node.js dependencies:

npm install
Expand Down
14 changes: 10 additions & 4 deletions server.js
Expand Up @@ -2,7 +2,6 @@ let app = require('express')();
let xmlparser = require('express-xml-bodyparser')({explicitArray: false});
let mysql = require('mysql');


let tableName = 'contact';

function transform(sobject) {
Expand All @@ -13,13 +12,18 @@ function transform(sobject) {
};
}


app.use(xmlparser);

let connection = mysql.createConnection(process.env.CLEARDB_DATABASE_URL || 'mysql://root@localhost/demo');

connection.connect();

// create the table if it doesn't exist
connection.query(`SELECT * FROM ${tableName}`, function(err) {
if ((err != null) && (err.code == 'ER_NO_SUCH_TABLE')) {
connection.query('create table contact (id VARCHAR(18) PRIMARY KEY, name VARCHAR(128), email VARCHAR(128))');
}
});


function ack() {
return `<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
Expand All @@ -43,6 +47,8 @@ function nack(errorMessage) {
</soapenv:Envelope>`;
}

app.use(xmlparser);

app.post('/', function(req, res) {

try {
Expand Down

0 comments on commit 52ef269

Please sign in to comment.