Thanks shimonchayim,
EJS looks more flexible than mustache.
I have written a ejs script that produces a valid json as required by the api used in the create table.
EJS-
<%
function handleArray(arrayKey, array){
var key = arrayKey %>
"<%= arrayKey %>": [
<% for(var i=0; i<array.length -1; i++) {%>
"<%= array[i] %>",
<% } %>
"<%= array[array.length-1] %>"
]
<%}
%>
<%function handleJsonRecord(params){ %>
"report" : {
"report_type" : "<%= params.report.report_type %>",
"report_interval" : "<%= params.report.report_interval %>",
<% handleArray("columns", params.report.columns ) %> }
<%}
%>
<%
handleJsonRecord(data)
%>
This ejs works correctly when invoked through javascript.
But now I am facing issues while integrating it with
ql.ioI get the following error with same ejs:
ReferenceError: ejs:24
22| %>
23|
>> 24| <%
25| handleJsonRecord(data)
26| %>
data is not defined
at eval (eval at <anonymous> (/root/myapp/node_modules/ql.io-app/node_modules/ql.io-console/node_modules/ejs/lib/ejs.js:223:12))
at exports.compile (/root/myapp/node_modules/ql.io-app/node_modules/ql.io-console/node_modules/ejs/lib/ejs.js:225:15)
at Object.exports.render (/root/myapp/node_modules/ql.io-app/node_modules/ql.io-console/node_modules/ejs/lib/ejs.js:263:13)
at Object.exports.serialize (/root/myapp/node_modules/ql.io-app/node_modules/ql.io-console/node_modules/ql.io-engine/lib/serializers/ejs.js:30:16)
at Object.module.exports.tmpl (/root/myapp/node_modules/ql.io-app/node_modules/ql.io-console/node_modules/ql.io-engine/lib/engine/source/verb.js:209:42)
at send (/root/myapp/node_modules/ql.io-app/node_modules/ql.io-console/node_modules/ql.io-engine/lib/engine/source/verb.js:628:37)
at module.exports.exec.async.parallel.ret.headers.content-type (/root/myapp/node_modules/ql.io-app/node_modules/ql.io-console/node_modules/ql.io-engine/lib/engine/source/verb.js:362:25)
at async.parallel.results (/root/myapp/node_modules/ql.io-app/node_modules/ql.io-console/node_modules/ql.io-engine/node_modules/async/lib/async.js:454:21)
at _asyncMap (/root/myapp/node_modules/ql.io-app/node_modules/ql.io-console/node_modules/ql.io-engine/node_modules/async/lib/async.js:185:13)
at async.forEach (/root/myapp/node_modules/ql.io-app/node_modules/ql.io-console/node_modules/ql.io-engine/node_modules/async/lib/async.js:86:13)
With heuristics, I could get that
ql.io takes the input data in variable named "params"
but then I get the following error - It is unable to access the nested json objects.
TypeError: ejs:17
15| <%function handleJsonRecord(data){ %>
16| "report" : {
>> 17| "report_type" : <%= data.report.report_type %>,
18| "report_interval" : "<%= data.report.report_interval %>",
19| <% handleArray("columns", data.report.columns ) %> }
20|
Cannot read property 'report_type' of undefined
at handleJsonRecord (eval at <anonymous> (/root/myapp/node_modules/ql.io-app/node_modules/ql.io-console/node_modules/ejs/lib/ejs.js:223:12))
at eval (eval at <anonymous> (/root/myapp/node_modules/ql.io-app/node_modules/ql.io-console/node_modules/ejs/lib/ejs.js:223:12))
at exports.compile (/root/myapp/node_modules/ql.io-app/node_modules/ql.io-console/node_modules/ejs/lib/ejs.js:225:15)
at Object.exports.render (/root/myapp/node_modules/ql.io-app/node_modules/ql.io-console/node_modules/ejs/lib/ejs.js:263:13)
at Object.exports.serialize (/root/myapp/node_modules/ql.io-app/node_modules/ql.io-console/node_modules/ql.io-engine/lib/serializers/ejs.js:30:16)
at Object.module.exports.tmpl (/root/myapp/node_modules/ql.io-app/node_modules/ql.io-console/node_modules/ql.io-engine/lib/engine/source/verb.js:209:42)
at send (/root/myapp/node_modules/ql.io-app/node_modules/ql.io-console/node_modules/ql.io-engine/lib/engine/source/verb.js:628:37)
at module.exports.exec.async.parallel.ret.headers.content-type (/root/myapp/node_modules/ql.io-app/node_modules/ql.io-console/node_modules/ql.io-engine/lib/engine/source/verb.js:362:25)
at async.parallel.results (/root/myapp/node_modules/ql.io-app/node_modules/ql.io-console/node_modules/ql.io-engine/node_modules/async/lib/async.js:454:21)
at _asyncMap (/root/myapp/node_modules/ql.io-app/node_modules/ql.io-console/node_modules/ql.io-engine/node_modules/async/lib/async.js:185:13)
Can you please let me know what is wrong with my setup here.
ql.io scripts:
table:
create table AN_getPublisherAnalytics
on select post to "
http://sand.api.appnexus.com/report?publisher_id={^publisher_id}"
using headers 'Authorization'='{token}'
using bodyTemplate 'Publisher.ejs' type 'application/json'
route:
return select * from AN_getPublisherAnalytics
where publisher_id='{publisher_id}' and token='{token}'
via route '/AN_getPublisherAnalytics?publisher_id={publisher_id}&token={token}' using method post;
Thanks,
Nikhil