From df5ee50d1b9a10c4b072c9811413667ae07d2df4 Mon Sep 17 00:00:00 2001 From: Zbynek Rybicka Date: Thu, 30 Aug 2018 13:15:11 +0200 Subject: [PATCH] call proc is functional --- lib/xapi.js | 18 ++++++++++-------- lib/xsql.js | 9 +++++---- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/lib/xapi.js b/lib/xapi.js index 910db1d2b9..d5aa39833f 100644 --- a/lib/xapi.js +++ b/lib/xapi.js @@ -98,9 +98,10 @@ class Xapi { } setupRoutes() { - let stat = {}; - stat.tables = 0; - stat.apis = 0; + let stat = {} + stat.tables = 0 + stat.apis = 0 + stat.routines = 0 // 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))) stat.apis += 1 const procResources = this.mysql.getProcList(true, this.config.apiPrefix) - for (let resource in procResources) { - this.app.post('/_proc/' + procResources[resource], this.asyncMiddleware(this.callProc.bind(this))) - } + this.app.post('/_proc/:proc', this.asyncMiddleware(this.callProc.bind(this))) + stat.routines += procResources.length + stat.apis += procResources.length /**************** END : call stored procedures ****************/ @@ -361,6 +362,7 @@ class Xapi { console.log(' '); console.log(' Database : %s', this.config.database); console.log(' Number of Tables : %s', stat.tables); + console.log(' Number of Routines : %s', stat.routines); console.log(' '); console.log(' REST APIs Generated : %s'.green.bold, stat.apis); console.log(' '); @@ -494,8 +496,8 @@ class Xapi { } async callProc(req, res) { - let query = 'CALL showPeople(??)' - let params = [] + let query = 'CALL ??(?)' + let params = [req.params.proc, Object.values(req.body)] let results = await this.mysql.exec(query, params) res.status(200).json(results) } diff --git a/lib/xsql.js b/lib/xsql.js index 170d5fc8f8..3d2046ff23 100644 --- a/lib/xsql.js +++ b/lib/xsql.js @@ -13,7 +13,7 @@ class Xsql { this.pool = {}; this.metaDb = {}; this.metaDb.tables = {}; - this.metaDb.routines = {} + this.metaDb.routines = []; this.sqlConfig = sqlConfig; this.pool = pool; @@ -89,10 +89,11 @@ class Xsql { } iterateToCacheRoutines(routineResults) { + console.log(JSON.stringify(routineResults)) for (let i = 0; i < routineResults.length; i++) { - const routine = routineResults[i] - const routineName = routine['routine_name'] - this.metaDb.routines[routineName] = {} + const routine = routineResults[i] + const routineName = routine.routine_name + this.metaDb.routines.push(routineName) } }