Browse Source

call proc is functional

pull/122/head
Zbynek Rybicka 6 years ago committed by Jeremy Nagel
parent
commit
df5ee50d1b
  1. 18
      lib/xapi.js
  2. 7
      lib/xsql.js

18
lib/xapi.js

@ -98,9 +98,10 @@ class Xapi {
} }
setupRoutes() { setupRoutes() {
let stat = {}; let stat = {}
stat.tables = 0; stat.tables = 0
stat.apis = 0; stat.apis = 0
stat.routines = 0
// console.log('this.config while setting up routes', this.config); // console.log('this.config while setting up routes', this.config);
@ -349,9 +350,9 @@ class Xapi {
this.app.get('/_proc', this.asyncMiddleware(this.proc.bind(this))) this.app.get('/_proc', this.asyncMiddleware(this.proc.bind(this)))
stat.apis += 1 stat.apis += 1
const procResources = this.mysql.getProcList(true, this.config.apiPrefix) const procResources = this.mysql.getProcList(true, this.config.apiPrefix)
for (let resource in procResources) { this.app.post('/_proc/:proc', this.asyncMiddleware(this.callProc.bind(this)))
this.app.post('/_proc/' + procResources[resource], this.asyncMiddleware(this.callProc.bind(this))) stat.routines += procResources.length
} stat.apis += procResources.length
/**************** END : call stored procedures ****************/ /**************** END : call stored procedures ****************/
@ -361,6 +362,7 @@ class Xapi {
console.log(' '); console.log(' ');
console.log(' Database : %s', this.config.database); console.log(' Database : %s', this.config.database);
console.log(' Number of Tables : %s', stat.tables); console.log(' Number of Tables : %s', stat.tables);
console.log(' Number of Routines : %s', stat.routines);
console.log(' '); console.log(' ');
console.log(' REST APIs Generated : %s'.green.bold, stat.apis); console.log(' REST APIs Generated : %s'.green.bold, stat.apis);
console.log(' '); console.log(' ');
@ -494,8 +496,8 @@ class Xapi {
} }
async callProc(req, res) { async callProc(req, res) {
let query = 'CALL showPeople(??)' let query = 'CALL ??(?)'
let params = [] let params = [req.params.proc, Object.values(req.body)]
let results = await this.mysql.exec(query, params) let results = await this.mysql.exec(query, params)
res.status(200).json(results) res.status(200).json(results)
} }

7
lib/xsql.js

@ -13,7 +13,7 @@ class Xsql {
this.pool = {}; this.pool = {};
this.metaDb = {}; this.metaDb = {};
this.metaDb.tables = {}; this.metaDb.tables = {};
this.metaDb.routines = {} this.metaDb.routines = [];
this.sqlConfig = sqlConfig; this.sqlConfig = sqlConfig;
this.pool = pool; this.pool = pool;
@ -89,10 +89,11 @@ class Xsql {
} }
iterateToCacheRoutines(routineResults) { iterateToCacheRoutines(routineResults) {
console.log(JSON.stringify(routineResults))
for (let i = 0; i < routineResults.length; i++) { for (let i = 0; i < routineResults.length; i++) {
const routine = routineResults[i] const routine = routineResults[i]
const routineName = routine['routine_name'] const routineName = routine.routine_name
this.metaDb.routines[routineName] = {} this.metaDb.routines.push(routineName)
} }
} }

Loading…
Cancel
Save