From d7b789a26a801aed53385ae9be75136a51a5707b Mon Sep 17 00:00:00 2001
From: Peter
Date: Tue, 2 Apr 2019 17:00:45 +0300
Subject: [PATCH] Generate all queries
---
lib/querier.js | 21 +++++----------------
templates/multi-method.mustache | 2 +-
2 files changed, 6 insertions(+), 17 deletions(-)
diff --git a/lib/querier.js b/lib/querier.js
index 76a70d7d..06003d73 100644
--- a/lib/querier.js
+++ b/lib/querier.js
@@ -11,15 +11,9 @@ function getProperties(params) {
const parameters = [];
const questions = [];
params.forEach((param) => {
- if (param.in && param.in === 'path' || param.in === 'query') {
+ if (param.name) {
parameters.push(param.name);
}
- if (param.in && param.in === 'body') {
- const { '$ref': ref } = param.schema || {};
- if (ref) {
- parameters.push(ref.split('/').slice(-1)[0]);
- }
- }
questions.push('?');
});
return {
@@ -31,7 +25,7 @@ function getProperties(params) {
/**
* Create SQL query for the method
* @param data {object} - object with definitions & methods
- * @returns {*}
+ * @returns {object} - same as data, but with updated methods
*/
function querier(data) {
try {
@@ -50,14 +44,9 @@ function querier(data) {
}
});
- if (!special) {
- const { parameters, questions } = getProperties(method.parameters);
- mutable.methods[m].query = {
- content: `const results = await dal.query("SELECT FN_${method.methodName}(${questions})", [${parameters}], { redis: true });`,
- };
- } else {
-
- }
+ const { parameters, questions } = getProperties(method.parameters, special);
+ mutable.methods[m].query = `const results = await dal.query("${special ? 'CALL SP_' : 'SELECT FN_'}${method.methodName}(${questions})", `
+ + `[${parameters}], { redis: ${!special} });`;
});
return mutable;
diff --git a/templates/multi-method.mustache b/templates/multi-method.mustache
index da4ea542..cec0f2ad 100644
--- a/templates/multi-method.mustache
+++ b/templates/multi-method.mustache
@@ -46,7 +46,7 @@
{{#query}}
/*
- {{&content}}
+ {{&query}}
*/
{{/query}}
{{^query}}