Conditional route script

26 views
Skip to first unread message

Shailesh Birari

unread,
Jul 27, 2012, 6:23:47 AM7/27/12
to ql...@googlegroups.com

Is there any way to do if else in route ?

Here is what I am looking for.

I want to write an route API such that it will take an keyword as input and depending on the keyword it will return the contents from a particular table.

 ---- Route script ----

wsapis = [

        {"wskey": "ws1", "wstable": "satish_ws1"},

        {"wskey": "ws3", "wstable": "satish_ws3"}

];

wstable1 = select wstable from wsapis where

        wskey = '{keyword}';

return select * from wstable1

        via route '/wsapi' using method get;

 

 

---- Create table scripts ----

create table satish_ws1

on select get from "http://10.77.36.49:8080/RESTFull/services/hello/hello1";

 

 

create table satish_ws3

on select get from "http://10.77.36.49:8080/RESTFull/services/hello/hello3";

 

=============================================================================================

 This is to create a common interface to get data from different sites. So the application logic will be same for different sites.

 Note: I saw a similar topic on this forum but without solution :(

shimonchayim

unread,
Jul 27, 2012, 7:28:01 PM7/27/12
to ql...@googlegroups.com
Actually can do that. 

Most "if" like things happen using custom user defined functions return in js.

Also are your URLs different or your tables just look totally different? The answer differs based on this question.

If the URLs are different then your udf can return the URL of your choice and that url can be used by the table and your table can be more like

create table satish_ws

on select get from "{user_url}";


your route will something like this:
user_url = select * from keyword where u.yourfunctionforURL()


If the tables are different then with the help of udf you will return say a structure like this:

{
"satish_ws1":  true
}

In your route you will have script similar to:


r1 = select * from wstable1 where somefakeParam = '{^satish_ws1}';
r2 =  select * from wstable1 where somefakeParam = '{^satish_ws2}';

...

resultSet = [r1, r2, ...]
return select * from resultSet[] where u.yourSelectResultFunction() 


Having said that I realize this is workaroundish (but works). Go ahead and create a issue for supporting variable name for tables but at this time if/else is only supported through udf (we may support that more as part of the syntax in the future)
Reply all
Reply to author
Forward
0 new messages