1 | "ibm_db" :"~0.0.1", |
1 | "jade" :"*" to "ejs" :"*" |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | db2 = services['BLUAcceleration-10.5.3 Rev. A Build 0.1'][0].credentials; //It will get specific credentials to log in your BLU Acceleration var connString = "DRIVER={DB2};DATABASE=" + db2.db + "; UID=" + db2.username + " ![]() HOSTNAME=" + db2.hostname + ";port=" + db2.port; //String built, required by ibmdb module. /* app.post receives 2 parameters: * '/' -> path that will receive the post. * function(ibmdb, connString, db2.username) -> The callback * function.It will receive the ibmdb variable, the connString * created and the db2.username that changes according to Bluemix. * * It will connect on db2 once a post method is sent by the * client-side using $.post jQuery function. * * A JSON object can be received by the client-side the req.body * object. this function is written to receive objects named table, * columns and/or extras. */ app.post('/', function(ibmdb, connString, db2.username){ return function(req, res){ ibmdb.open(connString, function(err, conn) { if (err ) { res.send("error occurred " + err.message); } else { var extra; if(req.body.columns){ query = req.body.columns.join(", "); } else { query = '*';} if(req.body.extra){ extra = req.body.extra; } else { extra = ''; }; query = "SELECT " + query + " FROM " + db2.username + "."+ req.body.table + " " + extra; //Change this query according to your application. conn.query(query, function(err, tables){ if ( !err ) { res.json(tables); } else { res.send("error occurred " + err.message); } }); } }); }; }); |
1 | $.post('/', {JSON}, function(data){ //do something }); |
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |