Hi Firzhan, I thought of string sql statements in a json file rather than xml because it would be much simpler.
On Sat, Sep 20, 2014 at 9:18 PM, Firzhan Naqash <[email protected]> wrote: > Hi Kalpa, > > +1 for this option. > > In addition, if it is a jaggery code why don't you consider about storing > the sql commands in an xml file and later can be used to load those sql > commands. > > This will give you a much cleaner approach and accommodating changes to > the sql commands are much easy. > > Regards, > Firzhan > > On Sat, Sep 20, 2014 at 1:57 PM, Kalpa Welivitigoda <[email protected]> > wrote: > >> Hi, >> >> I am working on AS HTTP Dashboard and there's 10+ different sql >> statements used to retrieve data from the db. The code doesn't look nice >> when there are a bit lengthy sql statements amidst the jaggery code so I >> thought of separating them may be to a different json file. Sql statements >> needs to be generated dynamically based on the request parameters, an >> example would be the where clause. It's not only the values on the where >> clause but also the fields there would vary based on the request. >> >> To generate the sql statement I though of using string placeholder and >> use a function similar to the following to retrieve the complete statement. >> >> function formatSql(sql, arguments) { >> var formatted = sql; >> for (var i = 0; i < arguments.length; i++) { >> formatted = formatted.replace( >> RegExp('\{' + i + '\}', 'g'), arguments[i]); >> } >> return formatted; >> }; >> >> A sample invocation would be, >> >> var sql = 'SELECT sum({1}), {2} FROM {3} {4} GROUP BY {2}'; >> var formattedSql = formatSql(sql, ['requests', 'browser', 'BROWSER_STAT', >> 'WHERE webapp=\'Community blog\'']); >> >> and the formattedSql would be >> >> SELECT sum(requests), browser FROM BROWSER_STAT WHERE webapp='Community >> blog' GROUP BY browser; >> >> What are your suggestions on the approach? >> >> Is there a better way to separate out the sql statements and to get them >> dynamically generated? >> >> -- >> Best Regards, >> >> Kalpa Welivitigoda >> Software Engineer, WSO2 Inc. http://wso2.com >> Email: [email protected] >> Mobile: +94776509215 >> >> _______________________________________________ >> Dev mailing list >> [email protected] >> http://wso2.org/cgi-bin/mailman/listinfo/dev >> >> > -- Best Regards, Kalpa Welivitigoda Software Engineer, WSO2 Inc. http://wso2.com Email: [email protected] Mobile: +94776509215
_______________________________________________ Dev mailing list [email protected] http://wso2.org/cgi-bin/mailman/listinfo/dev
