Compare commits

...

2 Commits

4 changed files with 19 additions and 8 deletions

View File

@ -40,10 +40,13 @@ const SQLTemplate = (inSql, inJSON) => {
}
return inSql;
};
const build_where = (req, c, w, d, args) => {
const build_where = (req, c, w) => {
//loop through each top level item expected to be a simple key/value list reflecting the column and the target value
// "part":"XFRM500", "customer":"Sanford and Son" --> SQL --> part = 'XFRM500'
// AND customer = 'Sanford and Son'
var d = 1;
var args = [];
for (var i in req.body.app_scenario) {
//console.log(i);
///console.log(req.body[i]);
@ -71,7 +74,7 @@ const build_where = (req, c, w, d, args) => {
args.push(req.body.app_scenario[i]);
c = c + 1;
};
return { c, w, d };
return { c, w };
}
//------------route to test if the process is running-------------------------------
@ -110,11 +113,9 @@ server.get('/baseline', bodyParser.json(), function(req, res) {
server.get('/scale', bodyParser.json(), function(req, res) {
var sql = "";
var w = ""; //holds the where
var c = 1; //flag if body is empty
var d = 1;
var where = ""; //holds the where
var check = 1; //flag if body is empty
var path = './routes/scale/scale.sql';
var args = [];
fs.readFile(path, 'utf8', function(err, data) {
@ -124,7 +125,7 @@ server.get('/scale', bodyParser.json(), function(req, res) {
return
}
let { check, where } = build_where(req, c, w, d, args);
({ c: check, w: where } = build_where(req, check, where));
//if there was no body sent, return with nothing
//if (c == 1) {
// res.send("no body was sent");

View File

@ -1,4 +1,4 @@
# execure the sql for scale which builds the sql and inserts into a table
#$PG -f ./routes/scale/gen_scale.sql
psql -h hptrow.me -p 54329 -d ubm -U ptrowbridge -f ./setup_sql/05_gen_scale.sql
# pull the sql out of the table and write it to route directory
psql -h hptrow.me -p 54329 -d ubm -U ptrowbridge -c "SELECT t FROM fc.sql WHERE cmd = 'scale'" -t -A -o ./routes/scale/scale.sql

View File

@ -140,6 +140,7 @@ FROM
WHERE
pscale.factor <> 0 or pscale.mod_price <> 0
)
,ins AS (
INSERT INTO
fc.dcard
SELECT
@ -151,4 +152,8 @@ SELECT
*
FROM
pricing
RETURNING *
)
SELECT count(*) num_rows FROM ins

View File

@ -245,6 +245,7 @@ FROM
WHERE
pscale.factor <> 0 or pscale.mod_price <> 0
)
,ins AS (
INSERT INTO
$$||_target_table||$$
SELECT
@ -256,6 +257,10 @@ SELECT
*
FROM
pricing
RETURNING *
)
SELECT count(*) num_rows FROM ins
$$
INTO
_sql;